예제 #1
0
        public static SpriteUpdateMessage.NetMessage Deserialize(this NetworkReader reader)
        {
            var message = new SpriteUpdateMessage.NetMessage();

            SpriteUpdateMessage.SpriteUpdateEntry UnprocessedData = null;
            while (true)
            {
                UnprocessedData = null;
                bool ProcessSection = true;
                uint NetID          = reader.ReadUInt32();
                if (NetID == 0)
                {
                    break;
                }

                if (NetworkIdentity.spawned.ContainsKey(NetID) == false || NetworkIdentity.spawned[NetID] == null)
                {
                    ProcessSection = false;
                }

                string Name = reader.ReadString();
                if (ProcessSection == false ||
                    NetworkIdentity.spawned.ContainsKey(NetID) == false ||
                    SpriteHandlerManager.PresentSprites.ContainsKey(NetworkIdentity.spawned[NetID]) == false ||
                    SpriteHandlerManager.PresentSprites[NetworkIdentity.spawned[NetID]].ContainsKey(Name) == false)
                {
                    ProcessSection = false;
                }

                if (ProcessSection == false)
                {
                    UnprocessedData      = new SpriteUpdateMessage.SpriteUpdateEntry();
                    UnprocessedData.name = Name;
                    UnprocessedData.id   = NetID;
                }

                SpriteHandler SP = null;
                if (ProcessSection)
                {
                    SP = SpriteHandlerManager.PresentSprites[NetworkIdentity.spawned[NetID]][Name];
                }

                while (true)
                {
                    byte Operation = reader.ReadByte();

                    if (Operation == 255)
                    {
                        if (ProcessSection == false)
                        {
                            SpriteUpdateMessage.UnprocessedData.Add(UnprocessedData);
                        }

                        break;
                    }

                    if (Operation == 1)
                    {
                        int SpriteID = reader.ReadInt32();
                        if (ProcessSection)
                        {
                            SP.SetSpriteSO(SpriteCatalogue.Instance.Catalogue[SpriteID], Network: false);
                        }
                        else
                        {
                            UnprocessedData.call.Add(SpriteUpdateMessage.SpriteOperation.PresentSpriteSet);
                            UnprocessedData.arg.Add(SpriteID);
                        }
                    }


                    if (Operation == 2)
                    {
                        int Variant = reader.ReadInt32();
                        if (ProcessSection)
                        {
                            SP.ChangeSpriteVariant(Variant, NetWork: false);
                        }
                        else
                        {
                            UnprocessedData.call.Add(SpriteUpdateMessage.SpriteOperation.VariantIndex);
                            UnprocessedData.arg.Add(Variant);
                        }
                    }

                    if (Operation == 3)
                    {
                        int Sprite = reader.ReadInt32();
                        if (ProcessSection)
                        {
                            SP.ChangeSprite(Sprite, false);
                        }
                        else
                        {
                            UnprocessedData.call.Add(SpriteUpdateMessage.SpriteOperation.CataloguePage);
                            UnprocessedData.arg.Add(Sprite);
                        }
                    }

                    if (Operation == 4)
                    {
                        int SpriteAnimate = reader.ReadInt32();
                        if (ProcessSection)
                        {
                            SP.AnimateOnce(SpriteAnimate, false);
                        }
                        else
                        {
                            UnprocessedData.call.Add(SpriteUpdateMessage.SpriteOperation.AnimateOnce);
                            UnprocessedData.arg.Add(SpriteAnimate);
                        }
                    }

                    if (Operation == 5)
                    {
                        if (ProcessSection)
                        {
                            SP.PushTexture(false);
                        }
                        else
                        {
                            UnprocessedData.call.Add(SpriteUpdateMessage.SpriteOperation.PushTexture);
                        }
                    }

                    if (Operation == 6)
                    {
                        if (ProcessSection)
                        {
                            SP.Empty(false);
                        }
                        else
                        {
                            UnprocessedData.call.Add(SpriteUpdateMessage.SpriteOperation.Empty);
                        }
                    }


                    if (Operation == 7)
                    {
                        if (ProcessSection)
                        {
                            SP.PushClear(false);
                        }
                        else
                        {
                            UnprocessedData.call.Add(SpriteUpdateMessage.SpriteOperation.PushClear);
                        }
                    }

                    if (Operation == 8)
                    {
                        if (ProcessSection)
                        {
                            SP.ClearPallet(false);
                        }
                        else
                        {
                            UnprocessedData.call.Add(SpriteUpdateMessage.SpriteOperation.ClearPallet);
                        }
                    }


                    if (Operation == 9)
                    {
                        Color TheColour = reader.ReadColor();
                        if (ProcessSection)
                        {
                            SP.SetColor(TheColour, false);
                        }
                        else
                        {
                            UnprocessedData.call.Add(SpriteUpdateMessage.SpriteOperation.SetColour);
                            UnprocessedData.arg.Add(Convert.ToChar(Mathf.RoundToInt(TheColour.r * 255)));
                            UnprocessedData.arg.Add(Convert.ToChar(Mathf.RoundToInt(TheColour.g * 255)));
                            UnprocessedData.arg.Add(Convert.ToChar(Mathf.RoundToInt(TheColour.b * 255)));
                            UnprocessedData.arg.Add(Convert.ToChar(Mathf.RoundToInt(TheColour.a * 255)));
                        }
                    }

                    if (Operation == 10)
                    {
                        int          paletteCount = reader.ReadByte();
                        List <Color> Colours      = new List <Color>();
                        for (int i = 0; i < paletteCount; i++)
                        {
                            Colours.Add(reader.ReadColor());
                        }

                        if (ProcessSection)
                        {
                            SP.SetPaletteOfCurrentSprite(Colours, false);
                        }
                        else
                        {
                            UnprocessedData.call.Add(SpriteUpdateMessage.SpriteOperation.Pallet);
                            UnprocessedData.arg.Add(Convert.ToChar(paletteCount));
                            foreach (var color in Colours)
                            {
                                UnprocessedData.arg.Add(Convert.ToChar(Mathf.RoundToInt(color.r * 255)));
                                UnprocessedData.arg.Add(Convert.ToChar(Mathf.RoundToInt(color.g * 255)));
                                UnprocessedData.arg.Add(Convert.ToChar(Mathf.RoundToInt(color.b * 255)));
                                UnprocessedData.arg.Add(Convert.ToChar(Mathf.RoundToInt(color.a * 255)));
                            }
                        }
                    }
                }
            }

            return(message);
        }
예제 #2
0
        public StartScanning ProcessSection(int Start, int Scanning, string SerialiseData)
        {
            bool ProcessSection = true;
            int  InitialStart   = Start;

            Scanning = GoToIndexOfCharacter(SerialiseData, '@', Start);
            uint NetID = uint.Parse(SerialiseData.Substring(Start, Scanning - Start));

            if (NetworkIdentity.spawned.ContainsKey(NetID) == false || NetworkIdentity.spawned[NetID] == null)
            {
                ProcessSection = false;
            }


            Start    = Scanning + 1;
            Scanning = GoToIndexOfCharacter(SerialiseData, '{', Scanning);
            string Name = SerialiseData.Substring(Start, Scanning - Start);

            if (ProcessSection == false ||
                NetworkIdentity.spawned.ContainsKey(NetID) == false ||
                SpriteHandlerManager.Instance.PresentSprites.ContainsKey(NetworkIdentity.spawned[NetID]) == false ||
                SpriteHandlerManager.Instance.PresentSprites[NetworkIdentity.spawned[NetID]].ContainsKey(Name) == false)
            {
                ProcessSection = false;
            }

            SpriteHandler SP = null;

            if (ProcessSection)
            {
                SP = SpriteHandlerManager.Instance.PresentSprites[NetworkIdentity.spawned[NetID]][Name];
            }


            Scanning++;

            if (SerialiseData.Length > Scanning && SerialiseData[Scanning] == '>')
            {
                Scanning += 1;
                Start     = Scanning;
                Scanning  = GotoIndexOfNextControlCharacter(SerialiseData, Scanning);
                if (ProcessSection)
                {
                    int SpriteID = int.Parse(SerialiseData.Substring(Start, Scanning - Start));
                    SP.SetSpriteSO(SpriteCatalogue.Instance.Catalogue[SpriteID], Network: false);
                }
            }

            if (SerialiseData.Length > Scanning && SerialiseData[Scanning] == '<')
            {
                Scanning += 1;
                Start     = Scanning;
                Scanning  = GotoIndexOfNextControlCharacter(SerialiseData, Scanning);
                if (ProcessSection)
                {
                    SP.ChangeSpriteVariant(int.Parse(SerialiseData.Substring(Start, Scanning - Start)), NetWork: false);
                }
            }

            if (SerialiseData.Length > Scanning && SerialiseData[Scanning] == '&')
            {
                Scanning += 1;
                Start     = Scanning;
                Scanning  = GotoIndexOfNextControlCharacter(SerialiseData, Scanning);
                if (ProcessSection)
                {
                    SP.ChangeSprite(int.Parse(SerialiseData.Substring(Start, Scanning - Start)), false);
                }
            }

            if (SerialiseData.Length > Scanning && SerialiseData[Scanning] == '#')
            {
                Scanning += 1;
                Start     = Scanning;
                Scanning  = GotoIndexOfNextControlCharacter(SerialiseData, Scanning);
                if (ProcessSection)
                {
                    SP.AnimateOnce(int.Parse(SerialiseData.Substring(Start, Scanning - Start)), false);
                }
            }

            if (SerialiseData.Length > Scanning && SerialiseData[Scanning] == ',')
            {
                Scanning++;
                if (ProcessSection)
                {
                    SP.PushTexture(false);
                }
            }

            if (SerialiseData.Length > Scanning && SerialiseData[Scanning] == '?')
            {
                Scanning++;
                if (ProcessSection)
                {
                    SP.Empty(false);
                }
            }


            if (SerialiseData.Length > Scanning && SerialiseData[Scanning] == '~')
            {
                Scanning++;
                if (ProcessSection)
                {
                    SP.PushClear(false);
                }
            }

            if (SerialiseData.Length > Scanning && SerialiseData[Scanning] == '^')
            {
                Scanning++;
                if (ProcessSection)
                {
                    SP.ClearPallet(false);
                }
            }


            if (SerialiseData.Length > Scanning && SerialiseData[Scanning] == '`')
            {
                Color TheColour = Color.white;
                TheColour.r = ((int)SerialiseData[Scanning + 1] / 255f);
                TheColour.g = ((int)SerialiseData[Scanning + 2] / 255f);
                TheColour.b = ((int)SerialiseData[Scanning + 3] / 255f);
                TheColour.a = ((int)SerialiseData[Scanning + 4] / 255f);
                Scanning    = Scanning + 4;
                if (ProcessSection)
                {
                    SP.SetColor(TheColour, false);
                }

                Scanning++;
            }

            if (SerialiseData.Length > Scanning && SerialiseData[Scanning] == '%')
            {
                Scanning = Scanning + 1;
                int paletteCount = SerialiseData[Scanning];

                List <Color> Colours = new List <Color>();
                for (int i = 0; i < paletteCount; i++)
                {
                    Colours.Add(GetColourFromStringIndex(SerialiseData, Scanning + (i * 4)));
                }

                Scanning = Scanning + 1;
                Scanning = Scanning + 4 * paletteCount;
                if (ProcessSection)
                {
                    SP.SetPaletteOfCurrentSprite(Colours, false);
                }
            }

            Scanning++;
            Start = Scanning;
            if (ProcessSection == false)
            {
                UnprocessedData.Add(SerialiseData.Substring(InitialStart, Start - InitialStart));
            }

            StartScanning StartScanning = new StartScanning()
            {
                INStart    = Start,
                INScanning = Scanning,
            };

            return(StartScanning);
        }