Exemplo n.º 1
0
        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();
        }
Exemplo n.º 2
0
        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();
        }
Exemplo n.º 3
0
        public void LoadCK3BaseFile(RefFilename filename)
        {
            if (BaseCK3Library.HasFile(filename))
            {
                return;
            }

            LoadingCK3Library = BaseCK3Library;

            var context = GetContextFromDirectory(filename);

            var results = FileTokenizer.Instance.LoadFile(filename, context, true);

            BaseCK3Library.Add(results, context);
        }
Exemplo n.º 4
0
        public bool LoadCK3File(RefFilename filename, bool forceBase = false, bool forceReload = false)
        {
            var fromBase = filename.IsBase;

            LoadingCK3Library = fromBase ? BaseCK3Library : ModCK3Library;
            if (!forceReload)
            {
                if (fromBase)
                {
                    if (BaseCK3Library.HasFile(filename))
                    {
                        return(fromBase);
                    }
                }
                else
                {
                    if (ModCK3Library.HasFile(filename))
                    {
                        return(fromBase);
                    }
                }
            }
            else
            {
                LoadingCK3Library.ClearFile(filename);
            }


            // string directory = filename.Substring(0, Math.Max(filename.LastIndexOf("/"), 0));

            var context = GetContextFromDirectory(filename);

            var results = FileTokenizer.Instance.LoadFile(filename, context, true);

            LoadingCK3Library.Add(results, context);

            PostInitialize(null);

            return(fromBase);
        }