Exemplo n.º 1
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.º 2
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.º 3
0
 private void Wipe()
 {
     SchemaManager.Instance           = new SchemaManager();
     CoreIntellisenseHandler.Instance = new CoreIntellisenseHandler();
     EnumExtractorUtility.Instance    = new EnumExtractorUtility();
     EnumManager.Instance             = new EnumManager();
     FileTokenizer.Instance           = new FileTokenizer();
     JomaniScriptDocLogsToSchemaConverter.Instance = new JomaniScriptDocLogsToSchemaConverter();
     ReferenceManager.Instance = new ReferenceManager();
     BaseCK3Library            = null;
     ModCK3Library             = null;
     LoadingCK3Library         = null;
 }
Exemplo n.º 4
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.º 5
0
        public void LoadMod(string mod, IProgressFeedback progressFeedback)
        {
            ModCK3Library        = new ScriptLibrary();
            ModCK3Library.Parent = BaseCK3Library;
            ModCK3Library.Name   = mod;

            LoadingCK3Library = ModCK3Library;
            LoadCK3Scripts(ModCK3Library, progressFeedback, false, false);

            PostInitialize(progressFeedback);

            RePostProcessUntilComplete();

            ScriptObject.ClearCachedScriptedEffects();
        }
Exemplo n.º 6
0
        public void CreateOrLoadMod(string mod, IProgressFeedback progressFeedback)
        {
            if (Directory.Exists(Globals.CK3ModPath + mod + "/"))
            {
                LoadMod(mod, progressFeedback);
                return;
            }

            Directory.CreateDirectory(Globals.CK3ModPath + mod + "/");
            ModCK3Library        = new ScriptLibrary();
            ModCK3Library.Parent = BaseCK3Library;
            ModCK3Library.Name   = mod;

            PostInitialize(progressFeedback);
            ScriptObject.ClearCachedScriptedEffects();
        }
Exemplo n.º 7
0
        public void Init(IProgressFeedback progressFeedback)
        {
            Wipe();

            SchemaManager.Instance.Init();
            BaseCK3Library       = new ScriptLibrary();
            BaseCK3Library.Name  = "Base";
            ModCK3Library        = new ScriptLibrary();
            ModCK3Library.Parent = BaseCK3Library;
            LoadingCK3Library    = BaseCK3Library;

            EnumManager.Instance.Load();
            LoadCK3Scripts(BaseCK3Library, progressFeedback);
            ScriptObject.ClearCachedScriptedEffects();

            ProcessBaseFileBehaviour(progressFeedback);

            SchemaManager.Instance.SaveBinary();
        }
Exemplo n.º 8
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);
        }
Exemplo n.º 9
0
        public List <string> GetNameSet(string type, ScriptLibrary lib, bool allowPrepend = false,
                                        bool addPrepend = false)
        {
            var l = new List <string>();

            var where = lib.ContextData.Where(a => a.Value.Type == type);


            foreach (var keyValuePair in where)
            {
                if (keyValuePair.Value.Prepend != null && !allowPrepend)
                {
                }
                else
                {
                    if (keyValuePair.Value.Prepend != null && addPrepend)
                    {
                        l.AddRange(keyValuePair.Value.Keys()
                                   .Select(a => string.Concat(keyValuePair.Value.Prepend, ":", a)));
                    }
                    else
                    {
                        l.AddRange(keyValuePair.Value.Keys());
                    }
                }
            }

            var where2 = lib.GroupContextData.Where(a => a.Value.Type == type);

            foreach (var keyValuePair in where2)
            {
                l.AddRange(keyValuePair.Value.Keys());
            }

            return(l);
        }