Skip to content

Commit 252e750

Browse files
committed
Support mahogany trees
1 parent 992febe commit 252e750

File tree

2 files changed

+26
-45
lines changed

2 files changed

+26
-45
lines changed

TreeTransplant/TreeTransplant.cs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -142,9 +142,10 @@ private void loadTreeTexture()
142142
{
143143
// the list of seasons
144144
var seasons = new[] { "spring", "summer", "fall", "winter" };
145+
var trees = new[] { Tree.bushyTree, Tree.leafyTree, Tree.pineTree, Tree.mahoganyTree };
145146

146147
// create a render target to prepare the tree texture to
147-
var texture = new RenderTarget2D(Game1.graphics.GraphicsDevice, 144, 96 * seasons.Length);
148+
var texture = new RenderTarget2D(Game1.graphics.GraphicsDevice, 48 * trees.Length, 96 * seasons.Length);
148149

149150
// set the render target and clear the buffer
150151
Game1.graphics.GraphicsDevice.SetRenderTarget(texture);
@@ -156,20 +157,20 @@ private void loadTreeTexture()
156157
// Get source rectangle for tree tops.
157158
var treeTopSourceRect = new Tree().treeTopSourceRect;
158159

159-
for (int s = 0; s < seasons.Length; s++)
160+
for (var s = 0; s < seasons.Length; s++)
160161
{
161162
// loop through the three trees in the game
162-
for (int i = 0; i < 3; i++)
163+
for (var i = 0; i < trees.Length; i++)
163164
{
164165
// get the current season
165-
string season = seasons[s];
166+
var season = seasons[s];
166167

167168
// spring and summer share the same texture for the pine tree
168-
if (i == 2 && season.Equals("summer"))
169+
if (trees[i] == Tree.pineTree && season.Equals("summer"))
169170
season = "spring";
170171

171172
// load the texture into memory
172-
string treeString = $"TerrainFeatures\\tree{i + 1}_{season}";
173+
var treeString = $"TerrainFeatures\\tree{trees[i]}_{season}";
173174

174175
// get the current tree's texture
175176
var currentTreeTexture = Game1.content.Load<Texture2D>(treeString);
Lines changed: 19 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Linq;
23
using Microsoft.Xna.Framework;
34
using Microsoft.Xna.Framework.Graphics;
45
using StardewValley;
@@ -8,25 +9,23 @@ namespace TreeTransplant
89
{
910
public class TreeWrapper : ITree
1011
{
11-
private Tree tree;
12+
private readonly Tree tree;
13+
private readonly int[] basicTrees = new[] { Tree.bushyTree, Tree.leafyTree, Tree.pineTree, Tree.mahoganyTree };
1214

1315
public TreeWrapper(Tree t)
1416
{
1517
tree = t;
1618
}
1719

18-
public TerrainFeature getTerrainFeature()
19-
{
20-
return tree;
21-
}
20+
public TerrainFeature getTerrainFeature() => tree;
2221

2322
public Texture2D texture
2423
{
2524
get
2625
{
2726
if (isAdult() && !tree.stump.Value)
2827
{
29-
if (tree.treeType.Value == Tree.bushyTree || tree.treeType.Value == Tree.leafyTree || tree.treeType.Value == Tree.pineTree)
28+
if (basicTrees.Contains(tree.treeType.Value))
3029
return TreeTransplant.treeTexture;
3130
else if (tree.treeType.Value == Tree.mushroomTree || tree.treeType.Value == Tree.palmTree)
3231
return TreeTransplant.specialTreeTexture;
@@ -37,14 +36,11 @@ public Texture2D texture
3736

3837
public bool flipped
3938
{
40-
get { return tree.flipped.Value; }
41-
set { tree.flipped.Set(value); }
39+
get => tree.flipped.Value;
40+
set => tree.flipped.Set(value);
4241
}
4342

44-
public int treeType
45-
{
46-
get { return tree.treeType.Value; }
47-
}
43+
public int treeType => tree.treeType.Value;
4844

4945
public Rectangle treeTopSourceRect
5046
{
@@ -75,37 +71,21 @@ public Rectangle treeTopSourceRect
7571
return rect;
7672
}
7773

78-
bool basicTree = (tree.treeType.Value >= 1 && tree.treeType.Value <= 3);
79-
int xOffset = tree.treeType.Value - (basicTree ? 1 : 6);
80-
int yOffset = basicTree ? Utility.getSeasonNumber(Game1.currentSeason) : 0;
74+
// tree index refers to column in the generated texture, mahogany is hard coded as 4
75+
var treeIndex = tree.treeType.Value == Tree.mahoganyTree ? 4 : tree.treeType.Value;
76+
var basicTree = treeIndex >= 1 && treeIndex <= 4;
77+
// non-basic trees are palm and mushroom which are 6 and 7 so we subtract 6 to get 0 and 1
78+
var xOffset = treeIndex - (basicTree ? 1 : 6);
79+
var yOffset = basicTree ? Utility.getSeasonNumber(Game1.currentSeason) : 0;
8180

8281
return new Rectangle(48 * xOffset, yOffset * 96, 48, 96);
8382
}
8483
}
8584

86-
public Rectangle stumpSourceRect
87-
{
88-
get { return Tree.stumpSourceRect; }
89-
}
90-
91-
public Rectangle getBoundingBox(Vector2 tileLocation)
92-
{
93-
return tree.getBoundingBox(tileLocation);
94-
}
95-
96-
public bool stump
97-
{
98-
get { return tree.stump.Value; }
99-
}
100-
101-
public bool isAdult()
102-
{
103-
return tree.growthStage.Value > 4;
104-
}
105-
106-
public bool isStumpSeparate()
107-
{
108-
return isAdult();
109-
}
85+
public Rectangle stumpSourceRect => Tree.stumpSourceRect;
86+
public Rectangle getBoundingBox(Vector2 tileLocation) => tree.getBoundingBox(tileLocation);
87+
public bool stump => tree.stump.Value;
88+
public bool isAdult() => tree.growthStage.Value > 4;
89+
public bool isStumpSeparate() => isAdult();
11090
}
11191
}

0 commit comments

Comments
 (0)