public static T deserialize <T>(ContentResponse response)
        {
            if (response.type == (int)ContentType.DictInt)
            {
                SerializableDictionary <int, string> newAsset = new SerializableDictionary <int, string>();
                StringReader reader = new StringReader(PyNet.DecompressString(response.content));
                newAsset.ReadXml(XmlReader.Create(reader));
                return((T)(object)newAsset);
            }

            if (response.type == (int)ContentType.DictString)
            {
                SerializableDictionary <string, string> newAsset = new SerializableDictionary <string, string>();
                StringReader reader = new StringReader(PyNet.DecompressString(response.content));
                newAsset.ReadXml(XmlReader.Create(reader));
                return((T)(object)newAsset);
            }

            if (response.type == (int)ContentType.Texture)
            {
                SerializationTexture2D sTexture = JsonConvert.DeserializeObject <SerializationTexture2D>(PyNet.DecompressString(response.content));
                return((T)(object)sTexture.getTexture());
            }

            if (response.type == (int)ContentType.Map)
            {
                NewTiledTmxFormat format = new NewTiledTmxFormat();
                StringReader      reader = new StringReader(PyNet.DecompressString(response.content));
                Map map = format.Load(XmlReader.Create(reader));
                return((T)(object)map);
            }

            return((T)(object)null);
        }
 private static void incjectToGameContent(ContentResponse instruction, string[] assetNames)
 {
     foreach (string asset in assetNames)
     {
         incjectToGameContent(instruction);
     }
 }
Пример #3
0
        private static void incjectToGameContent(ContentResponse instruction)
        {
            if (instruction.type == (int)ContentType.DictInt)
            {
                SerializableDictionary <int, string> asset = deserialize <SerializableDictionary <int, string> >(instruction);
                asset.inject(instruction.assetName);
            }

            if (instruction.type == (int)ContentType.DictString)
            {
                SerializableDictionary <string, string> asset = deserialize <SerializableDictionary <string, string> >(instruction);
                asset.inject(instruction.assetName);
            }

            if (instruction.type == (int)ContentType.Texture)
            {
                Texture2D asset = deserialize <Texture2D>(instruction);
                asset.inject(instruction.assetName);
            }

            if (instruction.type == (int)ContentType.Map)
            {
                Map asset = deserialize <Map>(instruction);
                asset.inject(instruction.assetName);
            }
        }
        private static bool receiveInstruction(ContentResponse instruction)
        {
            if (contentPipe.ContainsKey(Game1.player) && contentPipe[Game1.player].Contains(instruction.assetName))
            {
                return(true);
            }

            if (contentPipe.ContainsKey(Game1.player))
            {
                contentPipe[Game1.player].AddOrReplace(instruction.assetName);
            }
            else
            {
                contentPipe.Add(Game1.player, new List <string>()
                {
                    instruction.assetName
                });
            }

            PyTKMod._monitor.Log("Receiving Content: " + instruction.assetName + " (" + (instruction.toGameContent ? "Game Content" : "Content") + ")");
            try
            {
                if (instruction.toGameContent)
                {
                    incjectToGameContent(instruction);
                }
                else
                {
                    content.AddOrReplace(instruction.assetName, deserialize <object>(instruction));
                }
            }
            catch (Exception e)
            {
                PyTKMod._monitor.Log(e.Message + ":" + e.StackTrace);
                return(false);
            }

            return(true);
        }
Пример #5
0
        private static bool receiveInstruction(ContentResponse instruction)
        {
            PyTKMod._monitor.Log("Receiving Content: " + instruction.assetName);
            try
            {
                if (instruction.toGameContent)
                {
                    if (!instruction.assetName.Contains("|"))
                    {
                        incjectToGameContent(instruction);
                    }
                    else
                    {
                        incjectToGameContent(instruction, instruction.assetName.Split('|'));
                    }
                }
                else
                {
                    if (!content.ContainsKey(instruction.assetName))
                    {
                        content.Add(instruction.assetName, deserialize <object>(instruction));
                    }
                    else
                    {
                        content[instruction.assetName] = deserialize <object>(instruction);
                    }
                }
            }
            catch (Exception e)
            {
                PyTKMod._monitor.Log(e.Message + ":" + e.StackTrace);
                return(false);
            }

            return(true);
        }
        private static void incjectToGameContent(ContentResponse instruction)
        {
            if (instruction.type == (int)ContentType.DictInt)
            {
                SerializableDictionary <int, string> asset   = deserialize <SerializableDictionary <int, string> >(instruction);
                SerializableDictionary <int, string> content = null;
                try
                {
                    content = Helper.Content.Load <SerializableDictionary <int, string> >(instruction.assetName, ContentSource.GameContent);
                }
                catch
                {
                }

                if (content == null)
                {
                    asset.inject(instruction.assetName);
                }
                else
                {
                    asset.injectInto(instruction.assetName);
                }
            }

            if (instruction.type == (int)ContentType.DictString)
            {
                SerializableDictionary <string, string> asset = deserialize <SerializableDictionary <string, string> >(instruction);

                SerializableDictionary <string, string> content = null;
                try
                {
                    content = Helper.Content.Load <SerializableDictionary <string, string> >(instruction.assetName, ContentSource.GameContent);
                }
                catch
                {
                }

                if (content == null)
                {
                    asset.inject(instruction.assetName);
                }
                else
                {
                    asset.injectInto(instruction.assetName);
                }
            }

            if (instruction.type == (int)ContentType.Texture)
            {
                Texture2D asset   = deserialize <Texture2D>(instruction);
                Texture2D content = null;
                try
                {
                    content = Helper.Content.Load <Texture2D>(instruction.assetName, ContentSource.GameContent);
                }
                catch
                {
                }

                if (content == null)
                {
                    asset.inject(instruction.assetName);
                }
                else
                {
                    asset.injectAs(instruction.assetName);
                }
            }

            if (instruction.type == (int)ContentType.Map)
            {
                Map asset   = deserialize <Map>(instruction);
                Map content = null;
                try
                {
                    content = Helper.Content.Load <Map>(instruction.assetName, ContentSource.GameContent);
                }
                catch
                {
                }

                if (content == null)
                {
                    asset.inject(instruction.assetName);
                }
                else
                {
                    asset.injectAs(instruction.assetName);
                }
            }
        }