Skip to content

Commit 1c42f6c

Browse files
committed
e
1 parent 47ac7a8 commit 1c42f6c

File tree

2 files changed

+40
-3
lines changed

2 files changed

+40
-3
lines changed

source/objects/HealthIcon.hx

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,45 @@ class HealthIcon extends FlxSprite
4646
if(!Paths.fileExists('images/' + name + '.png', IMAGE)) name = 'icons/icon-face'; //Prevents crash from missing icon
4747
var file:Dynamic = Paths.image(name);
4848

49-
loadGraphic(file); //Load stupidly first for getting the file size
50-
type = (width < 200 ? SINGLE : ((width > 199 && width < 301) ? DEFAULT : WINNING));
49+
var jsonPath:String = name;
50+
var jsonData:Dynamic = null;
51+
52+
// Try to load JSON file
53+
if (Paths.fileExists(jsonPath, TEXT)) {
54+
try {
55+
jsonData = haxe.Json.parse(Paths.modsImagesJson(jsonPath));
56+
} catch (e:Dynamic) {
57+
trace('Invalid JSON file: ' + jsonPath);
58+
}
59+
}
60+
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+
sys.io.File.saveContent(jsonPath, haxe.Json.stringify(jsonData, null, '\t'));
86+
trace('Remembering this type for future use: ' + jsonPath);
87+
}
5188

5289
loadGraphic(file, true, Math.floor(width / (type+1)), Math.floor(height));
5390
iconOffsets[0] = iconOffsets[1] = (width - 150) / (type+1);

source/yutautil/YScriptParser.hx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -590,7 +590,7 @@ class YScriptParser {
590590
// -------------------------
591591
// PROGRAM STRUCTURE
592592
// -------------------------
593-
593+
594594
typedef YScriptProgram = {
595595
classes:Array<YClass<Dynamic>>,
596596
functions:Array<YFunction>,

0 commit comments

Comments
 (0)