Example #1
0
        public B Spawn <B>() where B : BankableEntity
        {
            B bankable;

            if (sleepingBankables.Count > 0)
            {
                try {
                    bankable = (B)sleepingBankables[0];
                } catch (System.InvalidCastException e) {
                    throw Dj.Crashf("Bank '''{0}''' cannot be cast to type '''{1}'''\n{2}", original.name, typeof(B).ToString(), e.Message);
                }
                sleepingBankables.Remove(bankable);
            }
            else
            {
                if (original.gameObject.GetComponent <B>() == null)
                {
                    throw new System.Exception("Bankable " + original.gameObject.name + " is not of type " + typeof(B));
                }
                bankable = GameObject.Instantiate(original.gameObject).GetComponent <B>();
                bankable.RegisterBank(this);
            }
            spawnedBankables.Add(bankable);
            bankable.transform.SetParent(spawn);
            return(bankable);
        }
Example #2
0
 public Story Read(Story story)
 {
     if (isAuthor)
     {
         Dj.Crashf("Authors can't Read. Failed to Read Story '{0}'.", story.address);
     }
     story.SetStoryteller(this);
     this.stories[story.address] = story;
     StoryChanged(story);
     return(story);
 }
Example #3
0
        public static void untiltrue(System.Func <bool> func, int maxTries = 100)
        {
            for (int i = 0; i < maxTries; i++)
            {
                if (func())
                {
                    return;
                }
            }

            throw Dj.Crashf("Util.untiltrue failed after a maximum of {0} attempts", maxTries);
        }
Example #4
0
 public void Reject(ResponseStatus status)
 {
     if (Done)
     {
         throw Dj.Crash("Can only REPLY or REJECT one time on a PostAssistant");
     }
     if (status == ResponseStatus.Success)
     {
         throw Dj.Crashf("{0} is not a valid REJECTION status", status);
     }
     message.Respond(status);
     Done = true;
 }
Example #5
0
        public Story Decode(ServeStory serveAction)
        {
            Pages pages = Capn.Decrunchatize <Pages>(serveAction.storyBytes);

            foreach (var decoder in decoders)
            {
                var story = decoder.Decode(pages);
                if (story != null)
                {
                    return(story);
                }
            }

            throw Dj.Crashf("Decode failed on Story with unknown OPCODE '{0}' at address '{1}'. (OPCODE was not caught by any pushed IStorydecoder)", pages.op, pages.address);
        }
Example #6
0
        ////IMPORT-EXPORT FUNCTIONS
        public void ImportString(string encodedGrid, char separator)
        {
            RebuildGrid();             // not sure if necessary
            string[] valueStrings = encodedGrid.Split(separator);
            if (valueStrings.Length != options.count_cellsInGrid)
            {
                throw Dj.Crashf("ImportString misalignment. Got {0} values, expected {1} values ({2}x{3} grid)",
                                valueStrings.Length, options.count_cellsInGrid,
                                options.size_cellsInGrid.x, options.size_cellsInGrid.y);
            }
            int i = 0;

            DoEach((x, y) => {
                cells[x, y].SetValue(ushort.Parse(valueStrings[i++]));
            });
        }
Example #7
0
        public void SetupTileset(SpriteLot tilesetSprites, HashSet <int> solidTileSet, HashSet <int> spawnTileSet)
        {
            if (tilesetSprites.Length == 0)
            {
                Dj.Crashf("TiledLoader.SetupTileset was passed empty SpriteLot {0}.", tilesetSprites.gameObject.name);
            }

            //HashSet<int> solidTileSet = new HashSet<int>(solidTileIds);
            this.spawnTileSet = spawnTileSet;

            tileset = new Tile[tilesetSprites.Length];
            for (int i = 0; i < tileset.Length; i++)
            {
                tileset[i]              = ScriptableObject.CreateInstance <Tile>();
                tileset[i].sprite       = tilesetSprites[i];
                tileset[i].colliderType = solidTileSet.Contains(i) ? Tile.ColliderType.Grid : Tile.ColliderType.None;
            }
        }
Example #8
0
 public void SetPostHandler <ACTION, REPLY>(short opCode, System.Action <PostAssistant <ACTION, REPLY> > PrepareAssistant) where ACTION : struct where REPLY : struct
 {
     master.SetHandler(opCode, (message) => {
         var assistant = new PostAssistant <ACTION, REPLY>(message);
         PrepareAssistant(assistant);
         if (assistant.Done)
         {
         }
         else if (assistant.Delayed)
         {
             // if (assistant.responseStatus == ResponseStatus.Success) message.Respond(Capn.Crunchatize(assistant.reply), ResponseStatus.Success);
             // else message.Respond(assistant.responseStatus);
         }
         else
         {
             throw Dj.Crashf("generic action PrepareAssistant terminated illegally on opcode '{0}'!\nYou must call REPLY, REJECT, or PENDING before the action is done.", opCode);
         }
     });
 }
Example #9
0
 public Story Read(Pages delta)
 {
     if (isAuthor)
     {
         Dj.Crashf("Authors can't Read. Failed to Read delta Pages '{0}'.", delta.address);
     }
     if (this.stories.TryGetValue(delta.address, out var story))
     {
         story.SetStoryteller(this);
         story.ReadChanges(delta);
         StoryChanged(story);
         return(story);
     }
     else
     {
         Dj.Warnf("Couldn't find matching story for delta Pages '{0}'.", delta.address);
         return(null);
     }
 }
Example #10
0
 public void StoryApplyDelta(IDelta delta)
 {
     if (delta is D)
     {
         this.pagenumber = delta.pagenumber;
         if (this.ApplyDelta((D)delta))
         {
             // ok, handled
         }
         else
         {
             Dj.Errorf("Page {0}.ApplyDelta failed on delta {1}\n-- return false", this, delta);
         }
     }
     else
     {
         Dj.Crashf("BasePage expected delta of type {0}\n-- but got bad delta {1}", typeof(D), delta);
     }
 }
Example #11
0
        public void InitializeManualTT()
        {
            var grid = tilemap.gameObject.GetComponentInParent <Grid>();

            this.mazeMaster = grid.gameObject.GetComponent <maze.MazeMaster>();
            if (this.mazeMaster == null)
            {
                this.mazeMaster = grid.gameObject.AddComponent <maze.MazeMaster>();
            }
            this.mazeMaster.IsTileSolid = cell => { return(SolidTileIds.Contains(Gett(cell))); };

            if (sprites.Length == 0)
            {
                Dj.Crashf("BaseTilemapXXI '{0}' has no sprites in its SpriteLot '{1}'. TiledLoader.SetupTileset will crash.", this.gameObject.name, sprites.gameObject.name);
            }

            loader.SetupTileset(sprites, SolidTileIds, SpawnTileIds);
            tts = new Dictionary <twin, int>();
        }
Example #12
0
 public void Write(Story story)
 {
     if (!isAuthor)
     {
         Dj.Crashf("Non-Authors can't Write. Failed to Write Story '{0}'.", story.address);
     }
     if (story.SetStoryteller(this))
     {
         this.stories.Add(story.address, story);
         StoryChanged(story);
     }
     else if (this.stories[story.address] == story)
     {
         StoryChanged(story);
     }
     else
     {
         Dj.Warnf("WARNING: Write story@{0} failed, please implement", story.address);
     }
 }
Example #13
0
 public void ReadChanges(Pages delta)
 {
     if (delta.address != this.address)
     {
         throw Dj.Crashf("Story '{0}' can't read from mismatched delta '{1}'.", this.address, delta.address);
     }
     if (storyteller == null)
     {
         throw Dj.Crashf("Story '{0}' has no storyteller.", this.address);
     }
     if (storyteller.isAuthor)
     {
         Dj.Warnf("Story '{0}' can't ReadChanges, it's an author.", this.address);
     }
     else
     {
         foreach (var kvp in delta.data)
         {
             this.pages.data[kvp.Key] = kvp.Value;
         }
     }
 }
Example #14
0
        public Pages WriteChanges()
        {
            if (storyteller == null)
            {
                throw Dj.Crashf("Story '{0}' has no storyteller.", this.address);
            }
            if (storyteller.isAuthor)
            {
                lastWrittenDelta = new Pages();

                lastWrittenDelta.address = this.address;
                lastWrittenDelta.data    = new Dictionary <string, byte[]>();
                foreach (var kvp in this.pages.data)
                {
                    if (lastWrittenData.TryGetValue(kvp.Key, out var lastWrittenBytes))
                    {
                        if (lastWrittenBytes.Equals(kvp.Value))
                        {
                            // skip
                        }
                        else
                        {
                            lastWrittenDelta.data.Add(kvp.Key, kvp.Value);
                        }
                    }
                }

                storyteller.Write(this);

                MemorizeLastWrittenPagesData();
            }
            else
            {
                Dj.Warnf("Story '{0}' can't WriteChanges, it's attached a non-author storyteller.", this.address);
            }

            return(lastWrittenDelta);
        }