@@ -5,6 +5,10 @@ enum abstract IconType(Int) to Int from Int //abstract so it can hold int values
55 var SINGLE = 0 ;
66 var DEFAULT = 1 ;
77 var WINNING = 2 ;
8+ var ANIMSINGLE = 3 ;
9+ var ANIMDEFAULT = 4 ;
10+ var ANIMWINNING = 5 ;
11+ var ANIMSINGING = 6 ;
812}
913
1014class HealthIcon extends FlxSprite
@@ -44,6 +48,7 @@ class HealthIcon extends FlxSprite
4448 var name : String = ' icons/' + char ;
4549 if (! Paths .fileExists (' images/' + name + ' .png' , IMAGE )) name = ' icons/icon-' + char ; // Older versions of psych engine's support
4650 if (! Paths .fileExists (' images/' + name + ' .png' , IMAGE )) name = ' icons/icon-face' ; // Prevents crash from missing icon
51+
4752 var file : Dynamic = Paths .image (name );
4853
4954 var jsonPath : String = haxe.io. Path .directory (Paths .file (' images/icons/icons/' ));
@@ -58,48 +63,110 @@ class HealthIcon extends FlxSprite
5863 }
5964 }
6065
61- // Determine type based on JSON or fallback to size-based guessing
62- if (jsonData != null && Reflect .hasField (jsonData , ' type' )) {
63- var jsonType : String = jsonData .type ;
64- switch (jsonType ) {
65- case ' SINGLE' : type = SINGLE ;
66- case ' DEFAULT' : type = DEFAULT ;
67- case ' WINNING' : type = WINNING ;
68- default :
69- trace (' Invalid type in JSON: ' + jsonType );
70- loadGraphic (file ); // Load to guess size
71- type = (width < 200 ? SINGLE : ((width > 199 && width < 301 ) ? DEFAULT : WINNING ));
72- }
73- } else {
74- loadGraphic (file ); // Load to guess size
75- type = (width < 200 ? SINGLE : ((width > 199 && width < 301 ) ? DEFAULT : WINNING ));
76-
77- // trace('No JSON file found, guessing type based on size: ' + type + ' (' + width + 'px)');
78-
79- // Create or update JSON file with guessed type
80- jsonData = { type : switch (type ) {
81- case SINGLE : ' SINGLE' ;
82- case DEFAULT : ' DEFAULT' ;
83- case WINNING : ' WINNING' ;
84- }};
85- if (! sys. FileSystem .exists (jsonPath )) {
66+ if (Paths .fileExists (' images/' + name + ' .xml' , TEXT )) { // if the icon is animated
67+ frames = Paths .getSparrowAtlas (name );
68+
69+ // Try to load JSON file
70+ if (Paths .fileExists (Paths .json (name ), TEXT )) {
8671 try {
87- var file = sys.io. File .write (jsonPath , true ); // ???
88- file .close ();
89- } catch (e ) {trace (" Failed to write JSON for " + char );}
72+ jsonData = haxe. Json .parse (File .getContent (Paths .json (name )));
73+ } catch (e : Dynamic ) {
74+ trace (' Invalid JSON file: ' + jsonPath );
75+ }
76+ var jsonType : String = jsonData .type ;
77+ switch (jsonType ) {
78+ case ' ANIMSINGLE' : type = ANIMSINGLE ;
79+ case ' ANIMDEFAULT' : type = ANIMDEFAULT ;
80+ case ' ANIMWINNING' : type = ANIMWINNING ;
81+ case ' ANIMSINGING' : type = ANIMSINGING ;
82+ default :
83+ trace (' WRONG TYPE USED! DEFAULTING TO SINGLEANIM!' );
84+ type = ANIMSINGLE ;
85+ }
86+ }
87+ else {
88+ trace (' ANIMATED ICON DETECTED, BUT NO ICON JSON WAS FOUND! DEFAULTING TO ANIMSINGLE' );
89+ type = ANIMSINGLE ;
90+ }
91+ updateHitbox ();
92+
93+ switch (type ) {
94+ case DEFAULT :
95+ trace (' if you see this trace you messed up somewhere bro' );
96+ case SINGLE :
97+ trace (' if you see this trace you messed up somewhere bro' );
98+ case WINNING :
99+ trace (' if you see this trace you messed up somewhere bro' );
100+ case ANIMSINGLE :
101+ animation .addByPrefix (' idle' , ' idle' , 24 , true );
102+ animation .play (' idle' );
103+ case ANIMDEFAULT :
104+ animation .addByPrefix (' normal' , ' normal' , 24 , true );
105+ animation .addByPrefix (' losing' , ' losing' , 24 , true );
106+ animation .play (' normal' );
107+ case ANIMWINNING :
108+ animation .addByPrefix (' winning' , ' winning' , 24 , true );
109+ animation .addByPrefix (' normal' , ' normal' , 24 , true );
110+ animation .addByPrefix (' losing' , ' losing' , 24 , true );
111+ animation .play (' normal' );
112+ case ANIMSINGING :
113+ animation .addByPrefix (' idle' , ' idle' , 24 , true );
114+ animation .addByPrefix (' left' , ' left' , 24 , true );
115+ animation .addByPrefix (' down' , ' down' , 24 , true );
116+ animation .addByPrefix (' up' , ' up' , 24 , true );
117+ animation .addByPrefix (' right' , ' right' ,24 , true );
118+ animation .play (' idle' );
90119 }
91- sys.io. File .saveContent (jsonPath , haxe. Json .stringify (jsonData , null , ' \t ' ));
92- // trace('Remembering this type for future use: ' + jsonPath);
93120 }
121+ else {
122+ // Determine type based on JSON or fallback to size-based guessing
123+ if (jsonData != null && Reflect .hasField (jsonData , ' type' )) {
124+ var jsonType : String = jsonData .type ;
125+ switch (jsonType ) {
126+ case ' SINGLE' : type = SINGLE ;
127+ case ' DEFAULT' : type = DEFAULT ;
128+ case ' WINNING' : type = WINNING ;
129+ default :
130+ trace (' Invalid type in JSON: ' + jsonType );
131+ loadGraphic (file ); // Load to guess size
132+ type = (width < 200 ? SINGLE : ((width > 199 && width < 301 ) ? DEFAULT : WINNING ));
133+ }
134+ } else {
135+ loadGraphic (file ); // Load to guess size
136+ type = (width < 200 ? SINGLE : ((width > 199 && width < 301 ) ? DEFAULT : WINNING ));
137+
138+ // trace('No JSON file found, guessing type based on size: ' + type + ' (' + width + 'px)');
139+
140+ // Create or update JSON file with guessed type
141+ jsonData = { type : switch (type ) {
142+ case SINGLE : ' SINGLE' ;
143+ case DEFAULT : ' DEFAULT' ;
144+ case WINNING : ' WINNING' ;
145+ case ANIMSINGLE : ' ANIMSINGLE' ;
146+ case ANIMDEFAULT : ' ANIMDEFAULT' ;
147+ case ANIMWINNING : ' ANIMWINNING' ;
148+ case ANIMSINGING : ' ANIMSINGING' ;
149+ }};
150+ if (! sys. FileSystem .exists (jsonPath )) {
151+ try {
152+ var file = sys.io. File .write (jsonPath , true ); // ???
153+ file .close ();
154+ } catch (e ) {trace (" Failed to write JSON for " + char );}
155+ }
156+ sys.io. File .saveContent (jsonPath , haxe. Json .stringify (jsonData , null , ' \t ' ));
157+ // trace('Remembering this type for future use: ' + jsonPath);
158+ }
94159
95- loadGraphic (file , true , Math .floor (width / (type + 1 )), Math .floor (height ));
96- iconOffsets [0 ] = iconOffsets [1 ] = (width - 150 ) / (type + 1 );
97- var frames : Array <Int > = [];
98- for (i in 0 ... type + 1 ) frames .push (i );
99- updateHitbox ();
160+ loadGraphic (file , true , Math .floor (width / (type + 1 )), Math .floor (height ));
161+ iconOffsets [0 ] = iconOffsets [1 ] = (width - 150 ) / (type + 1 );
162+ var frames : Array <Int > = [];
163+ for (i in 0 ... type + 1 ) frames .push (i );
164+ updateHitbox ();
100165
101- animation .add (char , frames , 0 , false , isPlayer );
102- animation .play (char );
166+ animation .add (char , frames , 0 , false , isPlayer );
167+ animation .play (char );
168+ }
169+
103170 this .char = char ;
104171
105172 if (char .endsWith (' -pixel' ))
0 commit comments