コード例 #1
0
        public void build(string modFolder, string filename)
        {
            SaveHandler.register(this);
            if (allMachines == null)
            {
                allMachines = new List <simpleMachine>();
            }

            if (!allMachines.Contains(this))
            {
                allMachines.Add(this);
            }
            this.tileLocation = Vector2.Zero;
            this.modFolder    = modFolder;
            this.filename     = filename;
            string path = Path.Combine(modFolder, filename);

            this.loadJson        = JObject.Parse(File.ReadAllText(path));
            this.takeAll         = false;
            this.tileSize        = new Vector2(16, 32);
            this.category        = -8;
            this.mil             = 0;
            this.bigCraftable    = true;
            this.isRecipe        = false;
            this.animationFrame  = 0;
            this.animationFrames = 1;
            this.animationSpeed  = 300;

            this.crafting = "388 30";

            if (loadJson.Crafting != null)
            {
                this.crafting = (string)loadJson.Crafting;
            }

            if (loadJson.AnimationSpeed != null)
            {
                this.animationSpeed = (100 - (int)loadJson.AnimationSpeed) * 10;
                if (this.animationSpeed <= 0)
                {
                    this.animationSpeed = 1;
                }
            }

            this.displayItem     = false;
            this.displayItemX    = 0;
            this.displayItemY    = 0;
            this.displayItemZoom = 1.0;

            if (loadJson.displayItem != null && loadJson.displayItemX != null && loadJson.displayItemY != null && loadJson.displayItemZoom != null)
            {
                this.displayItem     = (bool)loadJson.displayItem;
                this.displayItemX    = (int)loadJson.displayItemX;
                this.displayItemY    = (int)loadJson.displayItemY;
                this.displayItemZoom = (double)loadJson.displayItemZoom;
            }

            this.isWorking        = false;
            this.parentSheetIndex = -1;
            this.readyForHarvest  = false;
            this.prefix           = "";
            this.suffix           = "";
            this.type             = "Crafting";
            this.isSpecial        = false;

            string tilesheetFile  = Path.Combine(modFolder, (string)loadJson.Tilesheet);
            Image  tilesheetImage = Image.FromFile(tilesheetFile);

            this.tilesheet = Bitmap2Texture(new Bitmap(tilesheetImage));

            this.tileWidth = 16;


            if (loadJson.TileWidth != null)
            {
                this.tileWidth = (int)loadJson.TileWidth;
            }

            this.tileHeight = tileWidth * 2;

            this.tilesheetWidth = (int)(tilesheet.Width / tileWidth);

            this.boundingBox         = new Microsoft.Xna.Framework.Rectangle((int)tileLocation.X * Game1.tileSize, (int)tileLocation.Y * Game1.tileSize, Game1.tileSize, Game1.tileSize);
            this.workAnimationFrames = 0;
            if (loadJson.WorkAnimationFrames != null)
            {
                this.workAnimationFrames = (int)loadJson.WorkAnimationFrames;
            }

            this.workAnimationOffset = (this.workAnimationFrames > 0) ? 1 : 0;

            this.animate     = (this.animationFrames > 1) ? true : false;
            this.animateWork = (this.workAnimationFrames > 1) ? true : false;

            this.tilesheetindex = (int)loadJson.TileIndex;
            this.tileindex      = this.tilesheetindex;
            this.readyTile      = this.tileindex;
            this.menuTileIndex  = this.tileindex;



            if (loadJson.MenuTileIndex != null)
            {
                this.menuTileIndex = (int)loadJson.MenuTileIndex;
            }

            if (loadJson.ReadyTileIndex != null)
            {
                this.readyTile = (int)loadJson.ReadyTileIndex;
            }


            this.name         = (string)loadJson.Name;
            this.categoryName = (string)loadJson.CategoryName;

            this.description    = (string)loadJson.Description;
            this.produceQuality = 0;

            if (loadJson.Produce != null && loadJson.Produce.Name != "")
            {
                string produceTilesheetFile = "none";
                this.produceIndex = 0;
                if (loadJson.Produce.Tilesheet != null)
                {
                    produceTilesheetFile = Path.Combine(modFolder, (string)loadJson.Produce.Tilesheet);
                    this.produceIndex    = (int)loadJson.Produce.TileIndex;
                }
                this.produceID = (int)loadJson.Produce.ProduceID;

                this.produceStack = (int)loadJson.Produce.Stack;
                this.produce      = new customNamedObject(this.produceID, produceTilesheetFile, this.produceIndex, this.produceStack, (string)loadJson.Produce.Name, (string)loadJson.Produce.Description, Microsoft.Xna.Framework.Color.White);

                if (loadJson.Produce != null && loadJson.Produce.Quality != null)
                {
                    this.produceQuality = (int)loadJson.Produce.Quality;
                }

                (this.produce as StardewValley.Object).quality = this.produceQuality;

                this.produceName = (string)loadJson.Produce.Name;
            }

            this.usePrefix = false;

            if (loadJson.Produce != null && loadJson.Produce.usePrefix != null)
            {
                this.usePrefix = (bool)loadJson.Produce.usePrefix;
            }



            this.useSuffix = false;

            if (loadJson.Produce != null && loadJson.Produce.useSuffix != null)
            {
                this.useSuffix = (bool)loadJson.Produce.useSuffix;
            }

            this.useColor = false;

            if (loadJson.Produce != null && loadJson.Produce.useColor != null)
            {
                this.useColor = (bool)loadJson.Produce.useColor;
            }

            this.productionTime = 0;

            if (loadJson.Produce != null && loadJson.Produce.ProductionTime != null)
            {
                this.productionTime = (int)loadJson.Produce.ProductionTime;
            }

            this.requiredStack = 0;
            if (loadJson.Produce != null && loadJson.RequieredStack != null)
            {
                this.requiredStack = (int)loadJson.RequieredStack;
            }


            this.specialProduce = (JArray)loadJson.SpecialProduce;


            this.starterMaterial      = 0;
            this.starterMaterialStack = 0;

            if (loadJson.StarterMaterial != null && loadJson.StarterMaterialStack != null)
            {
                this.starterMaterial      = (int)loadJson.StarterMaterial;
                this.starterMaterialStack = (int)loadJson.StarterMaterialStack;
            }

            updateSourceRectangle();



            this.materials = new List <StardewValley.Object>();

            if (loadJson.Materials != null)
            {
                JArray loadMaterials = (JArray)loadJson.Materials;

                if (loadMaterials.Count > 0)
                {
                    foreach (var material in loadMaterials)
                    {
                        int m = (int)material;

                        if (m == -999)
                        {
                            this.takeAll = true;
                        }

                        if (m > 0)
                        {
                            materials.Add(new StardewValley.Object(m, 1));
                        }
                        else
                        {
                            foreach (int keyI in Game1.objectInformation.Keys)
                            {
                                string[] splitData = Game1.objectInformation[keyI].Split('/');

                                string[] splitCategory = splitData[3].Split(' ');
                                if (splitCategory.Length > 1)
                                {
                                    int categoryInt = 0;
                                    int.TryParse(splitCategory[1], out categoryInt);

                                    if (categoryInt == m)
                                    {
                                        materials.Add(new StardewValley.Object(keyI, 1));
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }