public static void onEnthralledUnitMove(Map m, Unit u)
        {
            World.Log("narrEvents to check " + events.Count);
            foreach (var kv in events)
            {
                var e = kv.Value;

                EventContext?       nctx     = null;
                List <EventContext> contices = new List <EventContext>();
                contices.Add(EventContext.withUnit(m, u));
                switch (e.type)
                {
                case EventData.Type.MOVE:
                    nctx = chooseContext(e, contices);
                    break;

                default:
                    //Another type we're not involved in here
                    break;
                }

                if (nctx is EventContext ctx)
                {
                    World.log("Found a narr event to trigger");
                    m.world.prefabStore.popEvent(e.data, ctx);
                    break;
                }
            }
        }
Esempio n. 2
0
        public void bLoad()
        {
            audioStore.playClick();

            World.Log("load clicked");
            prefabStore.popScrollSetSaves();
        }
Esempio n. 3
0
        public void bQuickload()
        {
            audioStore.playClick();

            World.Log("load clicked");
            load("quicksave.sv");
        }
Esempio n. 4
0
        public static List <Token> tokenize(string expr)
        {
            List <Token> res = new List <Token>();

            while (!String.IsNullOrWhiteSpace(expr))
            {
                Token t = null;
                foreach (var te in expressions)
                {
                    t = te.match(ref expr);
                    if (t != null)
                    {
                        break;
                    }
                }

                if (t == null)
                {
                    World.Log("unexpected token: " + expr.Remove(1));
                    throw new Exception("could not parse event expression.");
                }

                res.Add(t);
                expr = expr.TrimStart();
            }

            return(res);
        }
Esempio n. 5
0
        public void save(string filename)
        {
            try
            {
                World world = this;
                // world.ui.setToMainMenu();
                GraphicalMap.purge();
                GraphicalSociety.purge();
                world.map.world = null;


                //foreach (SocialGroup sg in map.socialGroups)
                //{
                //    if (sg is Society)
                //    {
                //        Society soc = (Society)sg;
                //        soc.voteSession = null;
                //    }
                //}

                fsSerializer _serializer = new fsSerializer();
                fsData       data;
                _serializer.TrySerialize(typeof(Map), map, out data).AssertSuccessWithoutWarnings();

                // emit the data via JSON
                string saveString = fsJsonPrinter.CompressedJson(data);
                World.Log("Save exit point");

                if (File.Exists(filename))
                {
                    World.Log("Overwriting old save: " + filename);
                    File.Delete(filename);
                }
                File.WriteAllLines(filename, new string[] { saveString });

                world.map.world = world;
                staticMap       = map;

                world.prefabStore.popMsg("Game saved as: " + filename);

                //// step 1: parse the JSON data
                //fsData data = fsJsonParser.Parse(serializedState);

                //// step 2: deserialize the data
                //object deserialized = null;
                //_serializer.TryDeserialize(data, type, ref deserialized).AssertSuccessWithoutWarnings();
            }catch (Exception e)
            {
                World.log(e.Message);
                World.log(e.StackTrace);
                prefabStore.popMsg("Failure to save");
                prefabStore.popMsg("Exception: " + e.StackTrace);
            }
        }
        static void loadMod(string mod)
        {
            foreach (var path in Directory.EnumerateFiles(mod, "*.json"))
            {
                try
                {
                    string    data = File.ReadAllText(path);
                    EventData ev   = JsonUtility.FromJson <EventData>(data);

                    // The above pattern will also load mod.json, stop this.
                    if (String.IsNullOrEmpty(ev.id))
                    {
                        continue;
                    }

                    if (!events.ContainsKey(ev.id))
                    {
                        events.Add(ev.id, new ActiveEvent(ev));
                    }
                    else
                    {
                        World.Log("Ignoring duplicate event " + ev.id);
                        World.self.ui.uiMainMenu.errorMessage.text = "Duplicate event ID detected: " + ev.id;
                    }
                }
                catch (Exception e)
                {
                    string msg = "[" + path + "] could not load event: " + e.Message;
                    World.Log(msg);
                    World.self.ui.uiMainMenu.errorMessage.text = msg;
                    //World.self.prefabStore.popMsg("[" + path + "] could not load event: " + e.Message);
                }
            }
            foreach (var imgpath in Directory.EnumerateFiles(mod, "*.jpg"))
            {
                try
                {
                    World.log("Narr Event img found " + imgpath);
                    string[] split   = imgpath.Split(World.separator[0]);
                    string   imgName = split[split.Length - 2] + "." + split[split.Length - 1];
                    //Sprite loaded = TextureStore.LoadPNG(imgpath);
                    LoadImage(imgpath, imgName);
                    World.log("Narr Event Saving loaded image " + imgName);
                }
                catch (Exception e)
                {
                    string msg = "[" + imgpath + "] could not load img: " + e.Message;
                    World.Log(msg);
                    World.self.ui.uiMainMenu.errorMessage.text = msg;
                    //World.self.prefabStore.popMsg("[" + path + "] could not load event: " + e.Message);
                }
            }
        }
Esempio n. 7
0
 public void load(string filename)
 {
     try
     {
         if (map != null)
         {
             GraphicalMap.purge();
             GraphicalSociety.purge();
             map.world = null;
             map       = null;
         }
         filename = saveFolder + filename;
         string fullFile = File.ReadAllText(filename);
         //string serializedState = fullFile.Substring(fullFile.IndexOf("\n"), fullFile.Length);
         int          startIndex      = fullFile.IndexOf(saveHeader) + saveHeader.Length;
         int          endIndex        = fullFile.Length - startIndex;
         string       serializedState = fullFile.Substring(startIndex, endIndex);
         fsSerializer _serializer     = new fsSerializer();
         fsData       data            = fsJsonParser.Parse(serializedState);
         World.Log("Data parsed");
         object deserialized = null;
         _serializer.TryDeserialize(data, typeof(Map), ref deserialized).AssertSuccessWithoutWarnings();
         World.saveLog.takeLine("Finished deserial");
         map       = (Map)deserialized;
         map.world = this;
         staticMap = map;
         World.self.displayMessages = true;
         GraphicalMap.map           = map;
         //ui.setToMainMenu();
         //GraphicalMap.checkLoaded();
         //GraphicalMap.checkData();
         //graphicalMap.loadArea(0, 0);
         map.decompressFromSave();
         prefabStore.popMsg("Loaded file: " + filename, true);
         World.Log("reached end of loading code");
         // prefabStore.popMsg("Load may well have succeeded.");
     }
     catch (FileLoadException e)
     {
         Debug.Log(e);
         World.log(e.StackTrace);
         prefabStore.popMsg("Exception: " + e.StackTrace, true);
     }
     catch (Exception e2)
     {
         Debug.Log(e2);
         World.log(e2.StackTrace);
         prefabStore.popMsg("Exception: " + e2.StackTrace, true);
     }
 }
Esempio n. 8
0
        public void load(string filename)
        {
            try
            {
                if (map != null)
                {
                    GraphicalMap.purge();
                    GraphicalSociety.purge();
                    map.world = null;
                    map       = null;
                }

                string       serializedState = File.ReadAllText(filename);
                fsSerializer _serializer     = new fsSerializer();
                fsData       data            = fsJsonParser.Parse(serializedState);
                World.Log("Data parsed");
                object deserialized = null;
                _serializer.TryDeserialize(data, typeof(Map), ref deserialized).AssertSuccessWithoutWarnings();
                World.saveLog.takeLine("Finished deserial");
                map              = (Map)deserialized;
                map.world        = this;
                staticMap        = map;
                GraphicalMap.map = map;
                //ui.setToMainMenu();
                //GraphicalMap.checkLoaded();
                //GraphicalMap.checkData();
                //graphicalMap.loadArea(0, 0);
                prefabStore.popMsg("Loaded file: " + filename);
                World.Log("reached end of loading code");
                // prefabStore.popMsg("Load may well have succeeded.");
            }
            catch (FileLoadException e)
            {
                Debug.Log(e);
                World.log(e.StackTrace);
                prefabStore.popMsg("Exception: " + e.StackTrace);
            }
            catch (Exception e2)
            {
                Debug.Log(e2);
                World.log(e2.StackTrace);
                prefabStore.popMsg("Exception: " + e2.StackTrace);
            }
        }
        public static void turnTick(Map m)
        {
            World.Log("narrEvents to check " + events.Count);
            foreach (var kv in events)
            {
                var e = kv.Value;

                EventContext?nctx = null;
                switch (e.type)
                {
                case EventData.Type.LOCATION:
                    nctx = chooseContext(e, nextLocation(m));
                    break;

                case EventData.Type.PERSON:
                    nctx = chooseContext(e, nextPerson(m));
                    break;

                case EventData.Type.UNIT:
                    nctx = chooseContext(e, nextUnit(m));
                    break;

                case EventData.Type.WORLD:
                    nctx = chooseContext(e, nextWorld(m));
                    break;

                default:
                    //Nothing to handle, it's just not a type we care about
                    break;
                }

                if (nctx is EventContext ctx)
                {
                    World.log("Found a narr event to trigger");
                    m.world.prefabStore.popEvent(e.data, ctx);
                    break;
                }
            }
        }
Esempio n. 10
0
        public void save(string filename, bool popMsg = true)
        {
            Map rescueMap = World.staticMap;

            if (checkSaveFolder() == false)
            {
                prefabStore.popMsg("Unable to locate directory " + saveFolder + ". Saving cannot proceed without folder access. Aborting save.", true);
                return;
            }
            if (!hasWritePermission(saveFolder))
            {
                prefabStore.popMsg("Unable to write to directory " + saveFolder + ". Saving cannot proceed without folder access. Aborting save.", true);
                World.autosavePeriod = -1;
                return;
            }

            try
            {
                World world = this;
                // world.ui.setToMainMenu();
                GraphicalMap.purge();
                GraphicalSociety.purge();
                map.compressForSave();
                world.map.world = null;


                //foreach (SocialGroup sg in map.socialGroups)
                //{
                //    if (sg is Society)
                //    {
                //        Society soc = (Society)sg;
                //        soc.voteSession = null;
                //    }
                //}

                fsSerializer _serializer = new fsSerializer();
                fsData       data;
                _serializer.TrySerialize(typeof(Map), map, out data).AssertSuccessWithoutWarnings();

                // emit the data via JSON
                string saveString = fsJsonPrinter.CompressedJson(data);
                World.Log("Save data exit point");

                string catSaveString = "Version;" + World.versionNumber + ";" + World.subversionNumber;
                catSaveString += saveHeader;
                catSaveString += saveString;

                if (File.Exists(filename))
                {
                    World.Log("Overwriting old save: " + filename);
                    File.Delete(filename);
                }
                File.WriteAllLines(filename, new string[] { catSaveString });//Do it all on one line, to avoid faff wrt line endings

                world.map.world = world;
                staticMap       = map;
                map.decompressFromSave();

                if (popMsg)
                {
                    world.prefabStore.popMsg("Game saved as: " + filename, true);
                }

                //// step 1: parse the JSON data
                //fsData data = fsJsonParser.Parse(serializedState);

                //// step 2: deserialize the data
                //object deserialized = null;
                //_serializer.TryDeserialize(data, type, ref deserialized).AssertSuccessWithoutWarnings();
            }
            catch (Exception e)
            {
                World.log(e.Message);
                World.log(e.StackTrace);
                prefabStore.popMsg("Failure to save", true);
                prefabStore.popMsg("Exception: " + e.StackTrace, true);

                map       = rescueMap;
                map.world = this;
                staticMap = map;
            }
        }