Made the chart editor read the xml for the icons

This commit is contained in:
NeeEoo
2023-06-10 12:47:40 +02:00
parent 256c7ae40a
commit c3e42e0f7e
6 changed files with 45 additions and 5 deletions
@@ -1,5 +1,6 @@
package funkin.editors.charter;
import funkin.game.Character;
import funkin.backend.system.Conductor;
import funkin.game.HealthIcon;
import funkin.backend.chart.ChartData.ChartEvent;
@@ -43,8 +44,10 @@ class CharterEvent extends UISliceSprite {
var state = cast(FlxG.state, Charter);
if (event.params != null && event.params[0] != null && event.params[0] >= 0 && event.params[0] < state.strumLines.length) {
// camera movement, use health icon
var healthIcon = new HealthIcon('${state.strumLines.members[event.params[0]].strumLine.characters[0]}');
var icon = Character.getIconFromCharName(state.strumLines.members[event.params[0]].strumLine.characters[0]);
var healthIcon = new HealthIcon(icon);
healthIcon.setUnstretchedGraphicSize(32, 32, false);
healthIcon.active = false;
healthIcon;
} else
generateDefaultIcon(event.name);
@@ -1,5 +1,6 @@
package funkin.editors.charter;
import funkin.game.Character;
import funkin.editors.ui.UIContextMenu.UIContextMenuOption;
import funkin.editors.ui.UITopMenu.UITopMenuButton;
import funkin.game.HealthIcon;
@@ -21,7 +22,9 @@ class CharterStrumline extends UISprite {
scrollFactor.set(1, 0);
alpha = 0;
healthIcon = new HealthIcon(strumLine.characters != null ? strumLine.characters[0] : null);
var icon = Character.getIconFromCharName(strumLine.characters != null ? strumLine.characters[0] : null);
healthIcon = new HealthIcon(icon);
healthIcon.scale.set(80 / 150, 80 / 150);
healthIcon.updateHitbox();
if(strumLine.visible == null)
+34
View File
@@ -361,6 +361,40 @@ class Character extends FunkinSprite implements IBeatReceiver implements IOffset
public inline function getIcon() {
return (icon != null) ? icon : curCharacter;
}
public static function getIconFromCharName(?curCharacter:String) {
if(curCharacter == null) return "face";
var icon = curCharacter;
while(true) {
switch (curCharacter)
{
// case 'your-char': // To hardcode characters icons
default:
// load xml
var xmlPath = Paths.xml('characters/$curCharacter');
if (!Assets.exists(xmlPath)) {
curCharacter = "bf";
continue;
}
var xml = null;
var plainXML = Assets.getText(xmlPath);
try {
var charXML = Xml.parse(plainXML).firstElement();
if (charXML == null) throw new Exception("Missing \"character\" node in XML.");
xml = new Access(charXML);
} catch(e) {
Logs.trace('Error while loading character ${curCharacter}: ${e}', ERROR);
curCharacter = "bf";
continue;
}
if (xml.has.icon) icon = xml.att.icon;
}
break;
}
return icon;
}
}
typedef CharacterShadowFrame = {