private int ProcessAllSaveGameScripts(IEntity entity)
        {
            if (entity.Type == EntityType.Proxy || PauseScripts)
            {
                return(0);
            }

            try
            {
                var entityScriptData = new ScriptSaveGameRootData(CurrentEntities, ModApi.Playfield, entity, PersistendData)
                {
                    MainScriptPath = SaveGamesScripts.MainScriptPath,
                    ModApi         = ModApi
                };

                return(ExecFoundSaveGameScripts(entityScriptData,
                                                Path.Combine(SaveGamesScripts.MainScriptPath, Enum.GetName(typeof(EntityType), entity.Type)),
                                                Path.Combine(SaveGamesScripts.MainScriptPath, entity.Name),
                                                Path.Combine(SaveGamesScripts.MainScriptPath, ModApi.Playfield.Name),
                                                Path.Combine(SaveGamesScripts.MainScriptPath, ModApi.Playfield.Name, Enum.GetName(typeof(EntityType), entity.Type)),
                                                Path.Combine(SaveGamesScripts.MainScriptPath, ModApi.Playfield.Name, entity.Name),
                                                Path.Combine(SaveGamesScripts.MainScriptPath, entity.Id.ToString())
                                                ));
            }
            catch (Exception error)
            {
                File.WriteAllText(GetTrackingFileName(entity, "SaveGameScript") + ".error", error.ToString());

                return(0);
            }
        }
Ejemplo n.º 2
0
        public void TestMethodSortedEachEntities()
        {
            var lcdMod = new EmpyrionScripting();
            var pf     = new PlayfieldScriptData(lcdMod);

            var e1 = Substitute.For <IEntity>();

            e1.Name.ReturnsForAnyArgs("a");
            e1.Position.ReturnsForAnyArgs(new UnityEngine.Vector3(0, 0, 0));
            e1.Type.ReturnsForAnyArgs(EntityType.BA);

            var e2 = Substitute.For <IEntity>();

            e2.Name.ReturnsForAnyArgs("b");
            e2.Position.ReturnsForAnyArgs(new UnityEngine.Vector3(10, 10, 10));
            e2.Type.ReturnsForAnyArgs(EntityType.BA);

            pf.AllEntities = new[] { e1, e2 };

            var data = new ScriptSaveGameRootData(pf, pf.AllEntities, pf.AllEntities, null, e1, null, null);

            Assert.AreEqual(
                "a:0 # b:17,32051 # ",
                lcdMod.ExecuteHandlebarScript(pf, data, "{{#entitiesbyname '*'}}{{#sortedeach . 'Distance'}}{{./Name}}:{{./Distance}} # {{/sortedeach}}{{/entitiesbyname}}")
                );
            Assert.AreEqual(
                "b:17,32051 # a:0 # ",
                lcdMod.ExecuteHandlebarScript(pf, data, "{{#entitiesbyname '*'}}{{#sortedeach . 'Distance' true}}{{./Name}}:{{./Distance}} # {{/sortedeach}}{{/entitiesbyname}}")
                );
        }
        public int ExecFoundSaveGameScripts(ScriptSaveGameRootData entityScriptData, params string[] scriptLocations)
        {
            int count = 0;

            scriptLocations
            .ForEach(S =>
            {
                if (PauseScripts)
                {
                    return;
                }

                var path = S.NormalizePath();

                if (SaveGamesScripts.SaveGameScripts.TryGetValue(path + SaveGamesScripts.ScriptExtension, out var C))
                {
                    ProcessScript(new ScriptSaveGameRootData(entityScriptData)
                    {
                        Script     = C,
                        ScriptPath = Path.GetDirectoryName(path)
                    });

                    Interlocked.Increment(ref count);
                }
                else
                {
                    SaveGamesScripts.SaveGameScripts
                    .Where(F => Path.GetDirectoryName(F.Key) == path)
                    .ForEach(F => {
                        ProcessScript(new ScriptSaveGameRootData(entityScriptData)
                        {
                            Script     = F.Value,
                            ScriptPath = Path.GetDirectoryName(F.Key)
                        });

                        Interlocked.Increment(ref count);
                    });
                }
            });

            return(count);
        }