-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c76cf35
commit 4f409e6
Showing
8 changed files
with
229 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,155 @@ | ||
package psychlua; | ||
|
||
package psychlua; | ||
|
||
import openfl.utils.Assets; | ||
|
||
#if (LUA_ALLOWED && flxanimate) | ||
class FlxAnimateFunctions | ||
{ | ||
public static function implement(funk:FunkinLua) | ||
{ | ||
var lua:State = funk.lua; | ||
Lua_helper.add_callback(lua, "makeFlxAnimateSprite", function(tag:String, ?x:Float = 0, ?y:Float = 0, ?loadFolder:String = null) { | ||
tag = tag.replace('.', ''); | ||
var lastSprite = PlayState.instance.variables.get(tag); | ||
if(lastSprite != null) | ||
{ | ||
lastSprite.kill(); | ||
PlayState.instance.remove(lastSprite); | ||
lastSprite.destroy(); | ||
} | ||
|
||
var mySprite:ModchartAnimateSprite = new ModchartAnimateSprite(x, y); | ||
if(loadFolder != null) loadAtlasCustom(mySprite, loadFolder); | ||
PlayState.instance.variables.set(tag, mySprite); | ||
mySprite.active = true; | ||
}); | ||
|
||
Lua_helper.add_callback(lua, "loadAnimateAtlas", function(tag:String, folderOrImg:Dynamic, ?spriteJson:Dynamic = null, ?animationJson:Dynamic = null) { | ||
var spr:FlxAnimate = PlayState.instance.variables.get(tag); | ||
if(spr != null) loadAtlasCustom(spr, folderOrImg, spriteJson, animationJson); | ||
}); | ||
|
||
Lua_helper.add_callback(lua, "addAnimationBySymbol", function(tag:String, name:String, symbol:String, ?framerate:Float = 24, ?loop:Bool = false, ?matX:Float = 0, ?matY:Float = 0) | ||
{ | ||
var obj:Dynamic = PlayState.instance.variables.get(tag); | ||
if(cast (obj, FlxAnimate) == null) return false; | ||
|
||
obj.anim.addBySymbol(name, symbol, framerate, loop, matX, matY); | ||
if(obj.anim.lastPlayedAnim == null) | ||
{ | ||
if(obj.playAnim != null) obj.playAnim(name, true); //is ModchartAnimateSprite | ||
else obj.animation.play(name, true); | ||
} | ||
return true; | ||
}); | ||
|
||
Lua_helper.add_callback(lua, "addAnimationBySymbolIndices", function(tag:String, name:String, symbol:String, ?indices:Any = null, ?framerate:Float = 24, ?loop:Bool = false, ?matX:Float = 0, ?matY:Float = 0) | ||
{ | ||
var obj:Dynamic = PlayState.instance.variables.get(tag); | ||
if(cast (obj, FlxAnimate) == null) return false; | ||
|
||
if(indices == null) | ||
indices = [0]; | ||
else if(Std.isOfType(indices, String)) | ||
{ | ||
var strIndices:Array<String> = cast (indices, String).trim().split(','); | ||
var myIndices:Array<Int> = []; | ||
for (i in 0...strIndices.length) { | ||
myIndices.push(Std.parseInt(strIndices[i])); | ||
} | ||
indices = myIndices; | ||
} | ||
|
||
obj.anim.addBySymbolIndices(name, symbol, indices, framerate, loop, matX, matY); | ||
if(obj.anim.lastPlayedAnim == null) | ||
{ | ||
if(obj.playAnim != null) obj.playAnim(name, true); //is ModchartAnimateSprite | ||
else obj.animation.play(name, true); | ||
} | ||
return true; | ||
}); | ||
} | ||
|
||
private static function loadAtlasCustom(spr:FlxAnimate, folderOrImg:Dynamic, spriteJson:Dynamic = null, animationJson:Dynamic = null) | ||
{ | ||
var changedAnimJson = false; | ||
var changedAtlasJson = false; | ||
var changedImage = false; | ||
|
||
if(spriteJson != null) | ||
{ | ||
changedAtlasJson = true; | ||
spriteJson = File.getContent(spriteJson); | ||
} | ||
|
||
if(animationJson != null) | ||
{ | ||
changedAnimJson = true; | ||
animationJson = File.getContent(animationJson); | ||
} | ||
|
||
// is folder or image path | ||
if(Std.isOfType(folderOrImg, String)) | ||
{ | ||
var originalPath:String = folderOrImg; | ||
for (i in 0...10) | ||
{ | ||
var st:String = '$i'; | ||
if(i == 0) st = ''; | ||
|
||
if(!changedAtlasJson) | ||
{ | ||
spriteJson = getContentFromFile('images/$originalPath/spritemap$st.json'); | ||
if(spriteJson != null) | ||
{ | ||
//trace('found Sprite Json'); | ||
changedImage = true; | ||
changedAtlasJson = true; | ||
folderOrImg = Paths.image('$originalPath/spritemap$st'); | ||
break; | ||
} | ||
} | ||
else if(Paths.fileExists('images/$originalPath/spritemap$st.png', IMAGE)) | ||
{ | ||
//trace('found Sprite PNG'); | ||
changedImage = true; | ||
folderOrImg = Paths.image('$originalPath/spritemap$st'); | ||
break; | ||
} | ||
} | ||
|
||
if(!changedImage) | ||
{ | ||
//trace('Changing folderOrImg to FlxGraphic'); | ||
changedImage = true; | ||
folderOrImg = Paths.image(originalPath); | ||
} | ||
|
||
if(!changedAnimJson) | ||
{ | ||
//trace('found Animation Json'); | ||
changedAnimJson = true; | ||
animationJson = getContentFromFile('images/$originalPath/Animation.json'); | ||
} | ||
} | ||
|
||
//trace(folderOrImg); | ||
//trace(spriteJson); | ||
//trace(animationJson); | ||
spr.loadAtlasEx(folderOrImg, spriteJson, animationJson); | ||
} | ||
|
||
private static function getContentFromFile(path:String):String | ||
{ | ||
var onAssets:Bool = false; | ||
var path:String = Paths.getPath(path, TEXT, true); | ||
if(FileSystem.exists(path) || (onAssets = true && Assets.exists(path, TEXT))) | ||
{ | ||
return !onAssets ? File.getContent(path) : Assets.getText(path); | ||
} | ||
return null; | ||
} | ||
} | ||
#end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package psychlua; | ||
|
||
package psychlua; | ||
|
||
#if flxanimate | ||
class ModchartAnimateSprite extends FlxAnimate | ||
{ | ||
public var animOffsets:Map<String, Array<Float>> = new Map<String, Array<Float>>(); | ||
public function new(?x:Float = 0, ?y:Float = 0, ?path:String, ?settings:FlxAnimate.Settings) | ||
{ | ||
super(x, y, path, settings); | ||
antialiasing = ClientPrefs.data.antialiasing; | ||
} | ||
|
||
public function playAnim(name:String, forced:Bool = false, ?reverse:Bool = false, ?startFrame:Int = 0) | ||
{ | ||
anim.play(name, forced, reverse, startFrame); | ||
|
||
var daOffset = animOffsets.get(name); | ||
if (animOffsets.exists(name)) offset.set(daOffset[0], daOffset[1]); | ||
} | ||
|
||
public function addOffset(name:String, x:Float, y:Float) | ||
{ | ||
animOffsets.set(name, [x, y]); | ||
} | ||
} | ||
#end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters