public void customRotate() { fRotation = (FurnitureRotation)currentRotation.Value; flipped.Value = false; if (rotations < 2) { return; } switch (fRotation) { case FurnitureRotation.horizontal: fRotation = FurnitureRotation.vertical; break; case FurnitureRotation.vertical: fRotation = (rotations > 2) ? FurnitureRotation.back : FurnitureRotation.horizontal; break; case FurnitureRotation.back: fRotation = FurnitureRotation.flipped; flipped.Value = true; break; case FurnitureRotation.flipped: fRotation = FurnitureRotation.horizontal; break; } currentRotation.Value = (int)fRotation; sourceRect.Value = getCurrentSourceRectangle(); boundingBox.Value = getCurrentBoundingBox(); }
public void rebuild(Dictionary <string, string> additionalSaveData, object replacement) { if (replacement is Furniture f) { string id = additionalSaveData["id"]; CustomFurnitureMod.log("Rebuild:" + id); if (!CustomFurnitureMod.furniture.ContainsKey(id)) { id = new List <string>(CustomFurnitureMod.furniture.Keys).Find(k => id.Contains(Path.Combine("Furniture", k))); } if (id == null || !CustomFurnitureMod.furniture.ContainsKey(id)) { id = CustomFurnitureMod.furniture.Keys.First <string>(); } build(CustomFurnitureMod.furniture[id].data, id, f.TileLocation); rotations.Value = additionalSaveData.ContainsKey("rotations") ? int.Parse(additionalSaveData["rotations"]) : (replacement as Furniture).rotations.Value; currentRotation.Value = additionalSaveData.ContainsKey("rotation") ? int.Parse(additionalSaveData["rotation"]) : (replacement as Furniture).currentRotation.Value; fRotation = (FurnitureRotation)currentRotation.Value; tileLocation.Value = (replacement as Furniture).TileLocation; rotate(); rotate(); rotate(); rotate(); if (f.heldObject.Value != null) { this.heldObject.Value = f.heldObject.Value; } } }
public void build(CustomFurnitureData data, string objectID, Vector2 tile) { id = objectID; rotatedWidth = data.rotatedWidth == -1 ? data.height : data.rotatedWidth; rotatedWidth *= 16; rotatedHeight = data.rotatedHeight == -1 ? data.width : data.rotatedHeight; rotatedHeight *= 16; rotatedBoxWidth = data.rotatedBoxWidth == -1 ? data.boxHeight : data.rotatedBoxWidth; rotatedBoxWidth *= Game1.tileSize; rotatedBoxHeight = data.rotatedBoxHeight == -1 ? data.boxWidth : data.rotatedBoxHeight; rotatedBoxHeight *= Game1.tileSize; string folder = new DirectoryInfo(data.folderName).Name; texture = CustomFurnitureMod.helper.Content.Load <Texture2D>($"Furniture/{folder}/{data.texture}"); animationFrames = data.animationFrames; this.data = data; frameWidth = data.setWidth; frame = 0; skipFrame = 60 / data.fps; counter = 0; tileLocation = tile; CustomFurnitureMod.helper.Reflection.GetPrivateField <string>(this, "_description").SetValue(data.description); parentSheetIndex = data.index; name = data.name; List <string> decorTypes = new List <string>(); decorTypes.Add("chair"); decorTypes.Add("bench"); decorTypes.Add("couch"); decorTypes.Add("armchair"); decorTypes.Add("dresser"); decorTypes.Add("bookcase"); decorTypes.Add("other"); string typename = data.type.Contains("table") ? "table" : decorTypes.Contains(data.type) ? "decor" : data.type; furniture_type = data.type.Contains("table") ? 11 : decorTypes.Contains(data.type) ? 8 : CustomFurnitureMod.helper.Reflection.GetPrivateMethod(new Furniture(), "getTypeNumberFromName").Invoke <int>(new[] { data.type }); furniture_type = getTypeFromName(typename); defaultSourceRect = new Rectangle(data.index * 16 % texture.Width, data.index * 16 / texture.Width * 16, 1, 1); drawHeldObjectLow = false; defaultSourceRect.Width = data.width * 16; defaultSourceRect.Height = data.height * 16; sourceRect = new Rectangle(defaultSourceRect.X, defaultSourceRect.Y, defaultSourceRect.Width, defaultSourceRect.Height); animatedSourceRect = sourceRect; defaultSourceRect = sourceRect; defaultBoundingBox = new Rectangle((int)tileLocation.X, (int)tileLocation.Y, data.boxWidth * Game1.tileSize, data.boxHeight * Game1.tileSize); boundingBox = new Rectangle((int)tileLocation.X * Game1.tileSize, (int)tileLocation.Y * Game1.tileSize, defaultBoundingBox.Width, defaultBoundingBox.Height); defaultBoundingBox = boundingBox; updateDrawPosition(); rotations = data.rotations; price = data.price; fRotation = FurnitureRotation.horizontal; }
public void build(CustomFurnitureData data, string objectID, Vector2 tile) { id = objectID; rotatedWidth = data.rotatedWidth == -1 ? data.height : data.rotatedWidth; rotatedWidth *= 16; rotatedHeight = data.rotatedHeight == -1 ? data.width : data.rotatedHeight; rotatedHeight *= 16; rotatedBoxWidth = data.rotatedBoxWidth == -1 ? data.boxHeight : data.rotatedBoxWidth; rotatedBoxWidth *= Game1.tileSize; rotatedBoxHeight = data.rotatedBoxHeight == -1 ? data.boxWidth : data.rotatedBoxHeight; rotatedBoxHeight *= Game1.tileSize; this.data = data; animationFrames = data.animationFrames; frameWidth = data.setWidth; frame = 0; skipFrame = 60 / data.fps; counter = 0; tileLocation.Value = tile; CustomFurnitureMod.helper.Reflection.GetField <string>(this, "_description").SetValue(data.description); CustomFurnitureMod.helper.Reflection.GetField <int>(this, "_placementRestriction").SetValue(2); parentSheetIndex.Set(data.index); setTexture(); name = data.name; List <string> decorTypes = new List <string>(); /* decorTypes.Add("chair"); * decorTypes.Add("bench"); * decorTypes.Add("couch"); * decorTypes.Add("armchair");*/ decorTypes.Add("dresser"); decorTypes.Add("bookcase"); decorTypes.Add("other"); string typename = data.type.Contains("table") ? "table" : decorTypes.Contains(data.type) ? "decor" : data.type; if (this.Name.Contains("Stool") || data.type == "stool") { isStool = true; } //furniture_type.Value = data.type.Contains("table") ? 11 : decorTypes.Contains(data.type) ? 8 : CustomFurnitureMod.helper.Reflection.GetMethod(new Furniture(), "getTypeNumberFromName").Invoke<int>(data.type); furniture_type.Value = getTypeFromName(typename); defaultSourceRect.Value = new Rectangle(data.index * 16 % texture.Width, data.index * 16 / texture.Width * 16, 1, 1); drawHeldObjectLow.Value = false; defaultSourceRect.Width = data.width * 16; defaultSourceRect.Height = data.height * 16; sourceRect.Value = new Rectangle(defaultSourceRect.X, defaultSourceRect.Y, defaultSourceRect.Width, defaultSourceRect.Height); animatedSourceRect = sourceRect; defaultSourceRect.Value = sourceRect; defaultBoundingBox.Value = new Rectangle((int)tileLocation.X, (int)tileLocation.Y, data.boxWidth * Game1.tileSize, data.boxHeight * Game1.tileSize); boundingBox.Value = new Rectangle((int)tileLocation.X * Game1.tileSize, (int)tileLocation.Y * Game1.tileSize, defaultBoundingBox.Width, defaultBoundingBox.Height); defaultBoundingBox.Value = boundingBox; updateDrawPosition(); rotations.Value = data.rotations; price.Value = data.price; fRotation = FurnitureRotation.horizontal; texture = null; textureOverlay = null; textureUnderlay = null; }