11using System ;
2+ using System . Linq ;
23using Microsoft . Xna . Framework ;
34using Microsoft . Xna . Framework . Graphics ;
45using 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