limo stage
This commit is contained in:
@@ -3,6 +3,7 @@ package funkin.game;
|
||||
import flixel.math.FlxPoint;
|
||||
import funkin.interfaces.IBeatReceiver;
|
||||
import funkin.interfaces.IOffsetCompatible;
|
||||
import funkin.system.XMLUtil;
|
||||
|
||||
import flixel.FlxG;
|
||||
import flixel.FlxSprite;
|
||||
@@ -96,7 +97,7 @@ class Character extends FlxSprite implements IBeatReceiver implements IOffsetCom
|
||||
|
||||
frames = Paths.getSparrowAtlas('characters/$curCharacter');
|
||||
for(anim in character.nodes.anim) {
|
||||
CoolUtil.addXMLAnimation(this, anim);
|
||||
XMLUtil.addXMLAnimation(this, anim);
|
||||
}
|
||||
}
|
||||
break;
|
||||
@@ -686,7 +687,7 @@ class Character extends FlxSprite implements IBeatReceiver implements IOffsetCom
|
||||
else
|
||||
offset.set(0, 0);
|
||||
|
||||
offset.x += globalOffset.x - (isPlayer != playerOffsets ? 1 : -1);
|
||||
offset.x += globalOffset.x * (isPlayer != playerOffsets ? 1 : -1);
|
||||
offset.y -= globalOffset.y;
|
||||
|
||||
if (AnimName.startsWith("sing"))
|
||||
|
||||
@@ -1,13 +1,17 @@
|
||||
package funkin.game;
|
||||
|
||||
import funkin.system.XMLUtil;
|
||||
import flixel.FlxSprite;
|
||||
import openfl.utils.Assets;
|
||||
import haxe.xml.Access;
|
||||
import flixel.FlxBasic;
|
||||
import flixel.math.FlxMath;
|
||||
import funkin.interfaces.IBeatReceiver;
|
||||
import funkin.scripting.Script;
|
||||
import haxe.io.Path;
|
||||
|
||||
using StringTools;
|
||||
|
||||
class Stage extends FlxBasic implements IBeatReceiver {
|
||||
public var stageXML:Access;
|
||||
public var stagePath:String;
|
||||
@@ -42,13 +46,13 @@ class Stage extends FlxBasic implements IBeatReceiver {
|
||||
if (stageXML.has.name) PlayState.instance.curStage = stageXML.att.name;
|
||||
|
||||
for(node in stageXML.elements) {
|
||||
switch(node.name) {
|
||||
var sprite:Dynamic = switch(node.name) {
|
||||
case "sprite" | "spr" | "sparrow":
|
||||
var spr = new FlxSprite();
|
||||
var spr = new StageSprite();
|
||||
spr.antialiasing = true;
|
||||
if (!node.has.sprite || !node.has.name || !node.has.x || !node.has.y) continue;
|
||||
|
||||
if (Assets.exists(Paths.file('images/$spritesParentFolder${node.att.sprite}', TEXT))) {
|
||||
if (Assets.exists(Paths.file('images/$spritesParentFolder${node.att.sprite}.xml', TEXT))) {
|
||||
spr.frames = Paths.getSparrowAtlas('$spritesParentFolder${node.att.sprite}');
|
||||
} else {
|
||||
spr.loadGraphic(Paths.image('$spritesParentFolder${node.att.sprite}'));
|
||||
@@ -66,11 +70,17 @@ class Stage extends FlxBasic implements IBeatReceiver {
|
||||
if (scale != null) spr.scale.set(scale, scale);
|
||||
}
|
||||
if (node.has.updateHitbox && node.att.updateHitbox == "true") spr.updateHitbox();
|
||||
|
||||
for(anim in node.nodes.anim) {
|
||||
if (anim.has.name) spr.beatAnims.push(anim.att.name);
|
||||
XMLUtil.addXMLAnimation(spr, anim);
|
||||
}
|
||||
if (node.has.beatAnim && node.att.beatAnim.trim() != "") spr.beatAnims = [for(e in node.att.beatAnim.split(",")) e.trim()];
|
||||
|
||||
for(anim in node.nodes.anim) CoolUtil.addXMLAnimation(spr, anim);
|
||||
|
||||
stageSprites.set(node.att.name, spr);
|
||||
PlayState.instance.add(spr);
|
||||
spr;
|
||||
case "boyfriend" | "bf":
|
||||
if (node.has.x) {
|
||||
var x:Null<Float> = Std.parseFloat(node.att.x);
|
||||
@@ -81,6 +91,7 @@ class Stage extends FlxBasic implements IBeatReceiver {
|
||||
if (y != null) PlayState.instance.boyfriend.y = y;
|
||||
}
|
||||
PlayState.instance.add(PlayState.instance.boyfriend);
|
||||
PlayState.instance.boyfriend;
|
||||
case "girlfriend" | "gf":
|
||||
if (node.has.x) {
|
||||
var x:Null<Float> = Std.parseFloat(node.att.x);
|
||||
@@ -91,6 +102,7 @@ class Stage extends FlxBasic implements IBeatReceiver {
|
||||
if (y != null) PlayState.instance.gf.y = y;
|
||||
}
|
||||
PlayState.instance.add(PlayState.instance.gf);
|
||||
PlayState.instance.gf;
|
||||
case "dad" | "opponent":
|
||||
if (node.has.x) {
|
||||
var x:Null<Float> = Std.parseFloat(node.att.x);
|
||||
@@ -101,6 +113,13 @@ class Stage extends FlxBasic implements IBeatReceiver {
|
||||
if (y != null) PlayState.instance.dad.y = y;
|
||||
}
|
||||
PlayState.instance.add(PlayState.instance.dad);
|
||||
PlayState.instance.dad;
|
||||
default: null;
|
||||
}
|
||||
if (sprite != null) {
|
||||
for(e in node.nodes.property) {
|
||||
trace(XMLUtil.applyXMLProperty(sprite, e));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -114,4 +133,19 @@ class Stage extends FlxBasic implements IBeatReceiver {
|
||||
public function beatHit(curBeat:Int) {}
|
||||
|
||||
public function stepHit(curStep:Int) {}
|
||||
}
|
||||
|
||||
class StageSprite extends FlxSprite implements IBeatReceiver {
|
||||
public var beatAnims:Array<String> = [];
|
||||
|
||||
public override function update(elapsed:Float) {
|
||||
super.update(elapsed);
|
||||
}
|
||||
|
||||
public function beatHit(curBeat:Int) {
|
||||
if (beatAnims.length > 0)
|
||||
animation.play(beatAnims[FlxMath.wrap(curBeat, 0, beatAnims.length-1)]);
|
||||
|
||||
}
|
||||
public function stepHit(curBeat:Int) {}
|
||||
}
|
||||
@@ -64,7 +64,7 @@ class FreeplayState extends MusicBeatState
|
||||
|
||||
addWeek(['Bopeebo', 'Fresh', 'Dadbattle'], 1, ['dad']);
|
||||
addWeek(['Spookeez', 'South', 'Monster'], 2, ['spooky']);
|
||||
addWeek(['Pico', 'Philly', 'Blammed'], 3, ['pico']);
|
||||
addWeek(['Pico', 'Philly Nice', 'Blammed'], 3, ['pico']);
|
||||
addWeek(['Satin Panties', 'High', 'Milf'], 4, ['mom']);
|
||||
addWeek(['Cocoa', 'Eggnog', 'Winter Horrorland'], 5, ['parents-christmas', 'parents-christmas', 'monster']);
|
||||
addWeek(['Senpai', 'Roses', 'Thorns'], 6, ['senpai', 'senpai', 'spirit']);
|
||||
|
||||
@@ -33,7 +33,7 @@ class HScript extends Script {
|
||||
}
|
||||
|
||||
public override function onLoad() {
|
||||
interp.execute(expr);
|
||||
if (expr != null) interp.execute(expr);
|
||||
}
|
||||
|
||||
private override function onCall(funcName:String, parameters:Array<Dynamic>):Dynamic {
|
||||
|
||||
@@ -1,52 +1,12 @@
|
||||
package funkin.system;
|
||||
|
||||
import funkin.interfaces.IOffsetCompatible;
|
||||
import lime.utils.Assets;
|
||||
import flixel.animation.FlxAnimation;
|
||||
import haxe.xml.Access;
|
||||
import flixel.FlxSprite;
|
||||
|
||||
using StringTools;
|
||||
|
||||
class CoolUtil
|
||||
{
|
||||
public static function addXMLAnimation(sprite:FlxSprite, anim:Access) {
|
||||
var animData:AnimData = {
|
||||
name: null,
|
||||
anim: null,
|
||||
fps: 24,
|
||||
loop: false,
|
||||
x: 0,
|
||||
y: 0,
|
||||
indices: []
|
||||
};
|
||||
|
||||
if (anim.has.name) animData.name = anim.att.name;
|
||||
if (anim.has.anim) animData.anim = anim.att.anim;
|
||||
if (anim.has.fps) animData.fps = Std.parseInt(anim.att.fps);
|
||||
if (anim.has.x) animData.x = Std.parseFloat(anim.att.x);
|
||||
if (anim.has.y) animData.y = Std.parseFloat(anim.att.y);
|
||||
if (anim.has.indices) {
|
||||
var indicesSplit = anim.att.indices.split(",");
|
||||
for(indice in indicesSplit) {
|
||||
var i = Std.parseInt(indice.trim());
|
||||
if (i != null)
|
||||
animData.indices.push(i);
|
||||
}
|
||||
}
|
||||
|
||||
if (animData.name != null && animData.anim != null) {
|
||||
if (animData.fps <= 0 #if web || animData.fps == null #end) animData.fps = 24;
|
||||
|
||||
if (animData.indices.length > 0)
|
||||
sprite.animation.addByIndices(animData.name, animData.anim, animData.indices, "", animData.fps, animData.loop);
|
||||
else
|
||||
sprite.animation.addByPrefix(animData.name, animData.anim, animData.fps, animData.loop);
|
||||
|
||||
if (sprite is IOffsetCompatible)
|
||||
cast(sprite, IOffsetCompatible).addOffset(animData.name, animData.x, animData.y);
|
||||
}
|
||||
}
|
||||
public static var difficultyArray:Array<String> = ['EASY', "NORMAL", "HARD"];
|
||||
|
||||
public static function difficultyString():String
|
||||
@@ -70,14 +30,4 @@ class CoolUtil
|
||||
anim1.frames = anim2.frames;
|
||||
anim2.frames = old;
|
||||
}
|
||||
}
|
||||
|
||||
typedef AnimData = {
|
||||
var name:String;
|
||||
var anim:String;
|
||||
var fps:Int;
|
||||
var loop:Bool;
|
||||
var x:Float;
|
||||
var y:Float;
|
||||
var indices:Array<Int>;
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package funkin.system;
|
||||
|
||||
@:enum
|
||||
abstract ErrorCode(Int) {
|
||||
var OK = 0;
|
||||
var FAILED = 1;
|
||||
var MISSING_PROPERTY = 2;
|
||||
var TYPE_INCORRECT = 3;
|
||||
var VALUE_NULL = 4;
|
||||
var REFLECT_ERROR = 5;
|
||||
}
|
||||
@@ -0,0 +1,98 @@
|
||||
package funkin.system;
|
||||
|
||||
import haxe.xml.Access;
|
||||
import funkin.interfaces.IOffsetCompatible;
|
||||
import flixel.FlxSprite;
|
||||
|
||||
using StringTools;
|
||||
/**
|
||||
* Class made to make XML parsing easier.
|
||||
*/
|
||||
class XMLUtil {
|
||||
|
||||
/**
|
||||
* Applies a property XML node to an object.
|
||||
* @param object Object to which the xml property will be applied
|
||||
* @param property `property` node.
|
||||
*/
|
||||
public static function applyXMLProperty(object:Dynamic, property:Access):ErrorCode {
|
||||
if (!property.has.name || !property.has.type || !property.has.value) {
|
||||
// TODO: show in logs
|
||||
return MISSING_PROPERTY;
|
||||
}
|
||||
|
||||
var value:Dynamic = switch(property.att.type.toLowerCase()) {
|
||||
case "float" | "number": Std.parseFloat(property.att.value);
|
||||
case "int" | "integer": Std.parseInt(property.att.value);
|
||||
case "string" | "str" | "text": property.att.value;
|
||||
case "bool" | "boolean": property.att.value.toLowerCase() == "true";
|
||||
default: return TYPE_INCORRECT;
|
||||
}
|
||||
if (value == null) return VALUE_NULL;
|
||||
|
||||
try {
|
||||
Reflect.setProperty(object, property.att.name, value);
|
||||
} catch(e) {
|
||||
// TODO: Correct Logs
|
||||
trace(e);
|
||||
return REFLECT_ERROR;
|
||||
}
|
||||
return OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds an XML animation to `sprite`.
|
||||
* @param sprite Destination sprite
|
||||
* @param anim Animation (Must be a `anim` XML node)
|
||||
*/
|
||||
public static function addXMLAnimation(sprite:FlxSprite, anim:Access):ErrorCode {
|
||||
var animData:AnimData = {
|
||||
name: null,
|
||||
anim: null,
|
||||
fps: 24,
|
||||
loop: false,
|
||||
x: 0,
|
||||
y: 0,
|
||||
indices: []
|
||||
};
|
||||
|
||||
if (anim.has.name) animData.name = anim.att.name;
|
||||
if (anim.has.anim) animData.anim = anim.att.anim;
|
||||
if (anim.has.fps) animData.fps = Std.parseInt(anim.att.fps);
|
||||
if (anim.has.x) animData.x = Std.parseFloat(anim.att.x);
|
||||
if (anim.has.y) animData.y = Std.parseFloat(anim.att.y);
|
||||
if (anim.has.indices) {
|
||||
var indicesSplit = anim.att.indices.split(",");
|
||||
for(indice in indicesSplit) {
|
||||
var i = Std.parseInt(indice.trim());
|
||||
if (i != null)
|
||||
animData.indices.push(i);
|
||||
}
|
||||
}
|
||||
|
||||
if (animData.name != null && animData.anim != null) {
|
||||
if (animData.fps <= 0 #if web || animData.fps == null #end) animData.fps = 24;
|
||||
|
||||
if (animData.indices.length > 0)
|
||||
sprite.animation.addByIndices(animData.name, animData.anim, animData.indices, "", animData.fps, animData.loop);
|
||||
else
|
||||
sprite.animation.addByPrefix(animData.name, animData.anim, animData.fps, animData.loop);
|
||||
|
||||
if (sprite is IOffsetCompatible)
|
||||
cast(sprite, IOffsetCompatible).addOffset(animData.name, animData.x, animData.y);
|
||||
|
||||
return OK;
|
||||
}
|
||||
return MISSING_PROPERTY;
|
||||
}
|
||||
}
|
||||
|
||||
typedef AnimData = {
|
||||
var name:String;
|
||||
var anim:String;
|
||||
var fps:Int;
|
||||
var loop:Bool;
|
||||
var x:Float;
|
||||
var y:Float;
|
||||
var indices:Array<Int>;
|
||||
}
|
||||
Reference in New Issue
Block a user