@@ -9,6 +9,14 @@ export interface LeafInfo {
99 brightness : number ;
1010}
1111
12+ type BranchSide = 'leftSide' | 'rightSide' ;
13+ type BranchLabel = 'Branch_01' | 'Branch_02' ;
14+ type LeafLabel = 'Leaf 01' | 'Leaf 02' | 'Leaf 03' | 'Leaf 04' | 'Leaf 05' | 'Leaf 06' | 'Leaf 07' | 'Leaf 08' | 'Leaf 09' | 'Leaf 10' | 'Leaf 11' | 'Leaf 12' | 'Leaf 13' | 'Leaf 14' | 'Leaf 15' ;
15+
16+ function isLeafLabel ( label : string ) : label is LeafLabel {
17+ return [ 'Leaf 01' , 'Leaf 02' , 'Leaf 03' , 'Leaf 04' , 'Leaf 05' , 'Leaf 06' , 'Leaf 07' , 'Leaf 08' , 'Leaf 09' , 'Leaf 10' , 'Leaf 11' , 'Leaf 12' , 'Leaf 13' , 'Leaf 14' , 'Leaf 15' ] . includes ( label ) ;
18+ }
19+
1220export default class Leaf extends Container {
1321 private readonly prerequisites ?: Container [ ] ;
1422 private readonly leafSprite ;
@@ -17,6 +25,17 @@ export default class Leaf extends Container {
1725
1826 private hasDonation = false ;
1927
28+ private static readonly leavesToRotate : Record < BranchSide , Record < BranchLabel , LeafLabel [ ] > > = {
29+ 'leftSide' : {
30+ 'Branch_01' : [ 'Leaf 01' , 'Leaf 02' , 'Leaf 03' , 'Leaf 04' , 'Leaf 05' , 'Leaf 06' , 'Leaf 07' , 'Leaf 08' , 'Leaf 09' , 'Leaf 10' , 'Leaf 11' , 'Leaf 12' , 'Leaf 14' , 'Leaf 15' ] ,
31+ 'Branch_02' : [ 'Leaf 01' , 'Leaf 02' , 'Leaf 03' , 'Leaf 04' , 'Leaf 05' , 'Leaf 06' , 'Leaf 07' , 'Leaf 08' , 'Leaf 09' , 'Leaf 11' , 'Leaf 12' , 'Leaf 13' , 'Leaf 15' ]
32+ } ,
33+ 'rightSide' : {
34+ 'Branch_01' : [ 'Leaf 12' , 'Leaf 13' ] ,
35+ 'Branch_02' : [ 'Leaf 13' , 'Leaf 14' ]
36+ }
37+ } ;
38+
2039 // tint, brightness
2140 public static readonly sakuraThemeLeafColors : [ number , number ] [ ] = [
2241 [ 0xff8bd4 , 1.75 ] ,
@@ -111,7 +130,7 @@ export default class Leaf extends Container {
111130 }
112131 }
113132
114- setDonation ( donation : Donation ) : LeafInfo {
133+ setDonation ( donation : Donation , branchLabel : string , leafLabel : string , isLeftBranch : boolean ) : LeafInfo {
115134 if ( this . hasDonation ) {
116135 throw new Error ( 'Cannot reassign leaf!' ) ;
117136 }
@@ -122,12 +141,27 @@ export default class Leaf extends Container {
122141 this . usernameText . text = donation . username ;
123142 this . amountText . text = `$${ donation . amount } ` ;
124143
144+ const currentBranch : BranchSide = isLeftBranch ? 'leftSide' : 'rightSide' ;
145+ const currentBranchLabel : BranchLabel = branchLabel === 'Branch_01' ? 'Branch_01' : 'Branch_02' ; // Oof...
146+
147+ if ( isLeafLabel ( leafLabel ) ) {
148+ const shouldRotateText = Leaf . leavesToRotate [ currentBranch ] [ currentBranchLabel ] . includes ( leafLabel ) ;
149+
150+ if ( shouldRotateText ) {
151+ this . usernameText . angle += 180 ;
152+ this . usernameText . y = 40 ;
153+ this . amountText . angle += 180 ;
154+ this . amountText . y = - 40 ;
155+ }
156+ } else {
157+ console . error ( `Error! Invalid leaf label: ${ leafLabel } \nSkipping rotation check for this leaf!` ) ;
158+ }
159+
125160 const [ tint , brightness ] = this . getTint ( donation . amount ) ;
126161 this . leafSprite . tint = tint ;
127162 const brightnessFilter = new ColorMatrixFilter ( ) ;
128163 brightnessFilter . brightness ( brightness , true ) ;
129164 this . leafSprite . filters = brightnessFilter ;
130-
131165 this . eventMode = 'static' ;
132166 this . cursor = 'pointer' ;
133167 this . on ( 'pointerdown' , ( ) => {
0 commit comments