public void UpdateFile(RefFilename filename, string text) { VariableStore.Instance.RemoveAllVariablesFromFile(filename); Instance.DeferedPostInitializationListNext.Clear(); ModCK3Library.ClearFile(filename); LoadingCK3Library = ModCK3Library; var c = GetContextFromDirectory(filename); try { var results = FileTokenizer.Instance.LoadText(text, filename, c); ModCK3Library.Add(results, c); } catch (Exception e) { } try { for (var i = 0; i < Instance.DeferedPostInitializationListNext.Count; i++) { var scriptObject = Instance.DeferedPostInitializationListNext[i]; scriptObject.Initialize(); } } catch (Exception e) { } try { LoadingCK3Library.RecalculateGroups(); do { Instance.DeferedPostInitializationList = Instance.DeferedPostInitializationListNext; Instance.DeferedPostInitializationListNext = new List <ScriptObject>(); for (var i = 0; i < Instance.DeferedPostInitializationList.Count; i++) { var scriptObject = Instance.DeferedPostInitializationList[i]; scriptObject.PostInitialize(null, null); } Instance.DeferedPostInitializationList.Clear(); } while (Instance.DeferedPostInitializationListNext.Count > 0); } catch (Exception e) { } ScriptObject.ClearCachedScriptedEffects(); }
public void LoadCK3Scripts(ScriptLibrary lib, IProgressFeedback progressFeedback = null, bool save = true, bool load = true) { LoadingCK3Library = lib; // events... var startDir = lib.Path; //"D:/SteamLibrary/steamapps/common/Crusader Kings III/"; LoadingCK3Library.LoadLocalizations(startDir + "localization/english"); if (progressFeedback != null) { progressFeedback.StartNewJob("Loading " + lib.Name + " CK3 Scripts", (int)ScriptContext.Max); } for (var x = 0; x < (int)ScriptContext.Max; x++) { if (LoadingCK3Library.ContextData.ContainsKey((ScriptContext)x)) { if (!string.IsNullOrEmpty(LoadingCK3Library.ContextData[(ScriptContext)x].Directory)) { var info = LoadingCK3Library.ContextData[(ScriptContext)x]; if (info.Directory.EndsWith(".txt")) { var r = FileTokenizer.Instance.LoadFile( new RefFilename(info.Directory, lib == BaseCK3Library), (ScriptContext)x, save); LoadingCK3Library.Add(r, (ScriptContext)x); } else { var r = FileTokenizer.Instance.LoadDirectory( new RefFilename(info.Directory + "/", lib == BaseCK3Library), (ScriptContext)x, save, load); LoadingCK3Library.Add(r, (ScriptContext)x); } } } progressFeedback?.AddProgress(1); } progressFeedback?.StartNewJob("Initializing " + lib.Name + " CK3 Scripts", (int)Instance.DeferedInitializationList.Count); for (var i = 0; i < Instance.DeferedInitializationList.Count; i++) { var scriptObject = Instance.DeferedInitializationList[i]; scriptObject.Initialize(); progressFeedback?.AddProgress(1); } Instance.DeferedInitializationList.Clear(); LoadingCK3Library.RecalculateGroups(); }