added item.deconstructed hook, misc registers and luacs is now initialized before campaign/sub editor is loaded

This commit is contained in:
Evil Factory
2022-05-10 13:55:10 -03:00
parent 45efbd8e08
commit 2630c8354c
5 changed files with 12 additions and 6 deletions
@@ -1115,6 +1115,8 @@ namespace Barotrauma
return;
}
GameMain.LuaCs.Initialize();
selectedSub = new SubmarineInfo(Path.Combine(SaveUtil.TempPath, selectedSub.Name + ".sub"));
GameMain.GameSession = new GameSession(selectedSub, savePath, GameModePreset.SinglePlayerCampaign, settings, mapSeed);
@@ -1124,14 +1126,14 @@ namespace Barotrauma
GameMain.GameSession.CrewManager.AddCharacterInfo(characterInfo);
}
((SinglePlayerCampaign)GameMain.GameSession.GameMode).LoadNewLevel();
GameMain.LuaCs.Initialize();
}
private void LoadGame(string saveFile)
{
if (string.IsNullOrWhiteSpace(saveFile)) return;
GameMain.LuaCs.Initialize();
try
{
SaveUtil.LoadGame(saveFile);
@@ -1144,8 +1146,6 @@ namespace Barotrauma
//TODO
//GameMain.LobbyScreen.Select();
GameMain.LuaCs.Initialize();
}
#region UI Methods
@@ -1034,6 +1034,8 @@ namespace Barotrauma
return true;
}
GameMain.LuaCs.Initialize();
CloseItem();
backedUpSubInfo = new SubmarineInfo(MainSub);
@@ -1049,8 +1051,6 @@ namespace Barotrauma
GameMain.SubEditorScreen.Select();
};
GameMain.LuaCs.Initialize();
return true;
}
@@ -38,6 +38,7 @@ defaultLib["ContentPackageManager"] = CreateStatic("Barotrauma.ContentPackageMan
defaultLib["GameSettings"] = CreateStatic("Barotrauma.GameSettings")
defaultLib["RichString"] = CreateStatic("Barotrauma.RichString", true)
defaultLib["Identifier"] = CreateStatic("Barotrauma.Identifier", true)
defaultLib["LanguageIdentifier"] = CreateStatic("Barotrauma.LanguageIdentifier", true)
defaultLib["ContentPackage"] = CreateStatic("Barotrauma.ContentPackage", true)
defaultLib["WayPoint"] = CreateStatic("Barotrauma.WayPoint", true)
defaultLib["Submarine"] = CreateStatic("Barotrauma.Submarine", true)
@@ -11,6 +11,7 @@ RegisterBarotrauma("Level+InterestingPosition")
RegisterBarotrauma("RichString")
RegisterBarotrauma("Identifier")
RegisterBarotrauma("LanguageIdentifier")
RegisterBarotrauma("Job")
RegisterBarotrauma("JobPrefab")
@@ -34,6 +35,7 @@ RegisterBarotrauma("CharacterParams+SoundParams")
RegisterBarotrauma("Item")
RegisterBarotrauma("DeconstructItem")
RegisterBarotrauma("Submarine")
RegisterBarotrauma("INetSerializableStruct")
RegisterBarotrauma("Networking.Client")
@@ -301,6 +301,9 @@ namespace Barotrauma.Items.Components
GameAnalyticsManager.AddDesignEvent("ItemDeconstructed:" + (GameMain.GameSession?.GameMode?.Preset.Identifier.Value ?? "none") + ":" + targetItem.Prefab.Identifier);
bool? result = GameMain.LuaCs.Hook.Call<bool?>("item.deconstructed", targetItem, this, user, allowRemove);
if (result == true) { return; }
if (targetItem.AllowDeconstruct && allowRemove)
{
//drop all items that are inside the deconstructed item