diff --git a/.github/workflows/html5.yml b/.github/workflows/html5.yml new file mode 100644 index 0000000000..3edd1fecdc --- /dev/null +++ b/.github/workflows/html5.yml @@ -0,0 +1,54 @@ +# This is a basic workflow to help you get started with Actions + +name: HTML5 Build CI + +# Controls when the workflow will run +on: push + +# A workflow run is made up of one or more jobs that can run sequentially or in parallel +jobs: + # This workflow contains a single job called "build" + build: + # The type of runner that the job will run on + runs-on: ubuntu-latest + + # Steps represent a sequence of tasks that will be executed as part of the job + steps: + # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it + - uses: actions/checkout@v2 + - uses: krdlab/setup-haxe@v1 + with: + haxe-version: 4.1.5 + # Runs a set of commands using the runners shell + - name: script run line haha + run: | + sudo add-apt-repository ppa:haxe/releases -y + sudo apt-get update + sudo apt-get install gcc-multilib g++-multilib haxe -y + mkdir "%HAXELIB_ROOT%" + haxelib setup "%HAXELIB_ROOT%" + haxelib install lime 7.9.0 + haxelib install openfl + haxelib install flixel + haxelib run lime setup flixel + haxelib run lime setup + haxelib install flixel-tools + haxelib install flixel-addons + haxelib install flixel-ui + haxelib install hscript + haxelib install flixel-addons + haxelib git faxe https://github.com/uhrobots/faxe + haxelib git polymod https://github.com/larsiusprime/polymod.git + haxelib git discord_rpc https://github.com/Aidan63/linc_discord-rpc + haxelib git extension-webm https://github.com/KadeDev/extension-webm + haxelib run lime rebuild extension-webm linux + haxelib git linc_luajit https://github.com/MasterEric/linc_luajit.git + haxelib git hxvm-luajit https://github.com/nebulazorua/hxvm-luajit.git + haxelib install actuate + haxelib list + haxelib run lime build html5 + + - uses: actions/upload-artifact@v2 + with: + name: HTML5 Build + path: export/release/html5/bin diff --git a/.github/workflows/linux.yml b/.github/workflows/linux.yml new file mode 100644 index 0000000000..bdd9a4fa42 --- /dev/null +++ b/.github/workflows/linux.yml @@ -0,0 +1,54 @@ +# This is a basic workflow to help you get started with Actions + +name: Linux Build CI + +# Controls when the workflow will run +on: push + +# A workflow run is made up of one or more jobs that can run sequentially or in parallel +jobs: + # This workflow contains a single job called "build" + build: + # The type of runner that the job will run on + runs-on: ubuntu-latest + + # Steps represent a sequence of tasks that will be executed as part of the job + steps: + # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it + - uses: actions/checkout@v2 + - uses: krdlab/setup-haxe@v1 + with: + haxe-version: 4.1.5 + # Runs a set of commands using the runners shell + - name: script run line haha + run: | + sudo add-apt-repository ppa:haxe/releases -y + sudo apt-get update + sudo apt-get install gcc-multilib g++-multilib haxe -y + mkdir "%HAXELIB_ROOT%" + haxelib setup "%HAXELIB_ROOT%" + haxelib install lime 7.9.0 + haxelib install openfl + haxelib install flixel + haxelib run lime setup flixel + haxelib run lime setup + haxelib install flixel-tools + haxelib install flixel-addons + haxelib install flixel-ui + haxelib install hscript + haxelib install flixel-addons + haxelib git faxe https://github.com/uhrobots/faxe + haxelib git polymod https://github.com/larsiusprime/polymod.git + haxelib git discord_rpc https://github.com/Aidan63/linc_discord-rpc + haxelib git extension-webm https://github.com/KadeDev/extension-webm + haxelib run lime rebuild extension-webm linux + haxelib git linc_luajit https://github.com/MasterEric/linc_luajit.git + haxelib git hxvm-luajit https://github.com/nebulazorua/hxvm-luajit.git + haxelib install actuate + haxelib list + haxelib run lime build linux + + - uses: actions/upload-artifact@v2 + with: + name: Linux Build + path: export/release/linux/bin diff --git a/.github/workflows/superlinter.yml b/.github/workflows/superlinter.yml deleted file mode 100644 index a10058fc04..0000000000 --- a/.github/workflows/superlinter.yml +++ /dev/null @@ -1,10 +0,0 @@ -jobs: - build: - runs-on: [ubuntu-latest, macos-latest] - steps: - - uses: krdlab/setup-haxe@v1 - with: - haxe-version: 4.0.5 - - run: | - haxe -version - haxelib install hxnodejs diff --git a/.github/workflows/windows.yml b/.github/workflows/windows.yml index 38c970df52..8e28227f47 100644 --- a/.github/workflows/windows.yml +++ b/.github/workflows/windows.yml @@ -1,6 +1,6 @@ # This is a basic workflow to help you get started with Actions -name: CI +name: Windows Build CI # Controls when the workflow will run on: push @@ -18,16 +18,14 @@ jobs: - uses: actions/checkout@v2 - uses: krdlab/setup-haxe@v1 with: - haxe-version: 4.0.5 + haxe-version: 4.1.5 # Runs a set of commands using the runners shell - name: script run line haha run: | - cinst neko --version 2.3.0 -y cinst haxe --version 4.1.5 -y RefreshEnv mkdir "%HAXELIB_ROOT%" haxelib setup "%HAXELIB_ROOT%" - Install project dependencies haxelib install lime 7.9.0 RefreshEnv haxelib install openfl @@ -35,7 +33,6 @@ jobs: haxelib run lime setup flixel haxelib run lime setup haxelib install flixel-tools - haxelib run flixel-tools setup -y # Can't do this since it asks [y/n] even with -y argument! Stupid haxelib install flixel-addons haxelib install flixel-ui haxelib install hscript @@ -45,7 +42,8 @@ jobs: haxelib git discord_rpc https://github.com/Aidan63/linc_discord-rpc haxelib git extension-webm https://github.com/KadeDev/extension-webm haxelib run lime rebuild extension-webm windows - haxelib install linc_luajit + haxelib git linc_luajit https://github.com/nebulazorua/linc_luajit.git + haxelib git hxvm-luajit https://github.com/nebulazorua/hxvm-luajit haxelib install actuate haxelib list haxelib run lime build windows diff --git a/.gitignore b/.gitignore index 8e2966de9d..1fe2d30330 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1 @@ -export/ -.vscode/ -assets/preload/data/milf/modchart.lua +export/ \ No newline at end of file diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000000..e9fbe66de4 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,47 @@ +{ + "version": "0.2.0", + "configurations": [ + { + "name": "Windows (Debug)", + "type": "hxcpp", + "preLaunchTask": "Build Windows (Debug)", + "request": "launch", + "program": "${workspaceFolder}/export/debug/windows/bin/Kade Engine.exe" + }, + { + "name": "Windows (Release)", + "type": "hxcpp", + "preLaunchTask": "Build Windows (Release)", + "request": "launch", + "program": "${workspaceFolder}/export/debug/windows/bin/Kade Engine.exe" + }, + { + "name": "HTML5 (Debug)", + "request": "launch", + "preLaunchTask": "Build HTML5 (Debug)", + "type": "node-terminal", + "command": "npx live-server \"${workspaceFolder}/export/debug/html5/bin/\"" + }, + { + "name": "HTML5 (Release)", + "request": "launch", + "preLaunchTask": "Build HTML5 (Release)", + "type": "node-terminal", + "command": "npx live-server \"${workspaceFolder}/export/release/html5/bin/\"" + }, + { + "name": "Linux (Debug)", + "type": "hxcpp", + "preLaunchTask": "Build Linux (Debug)", + "request": "launch", + "program": "${workspaceFolder}/export/debug/linux/bin/Kade Engine" + }, + { + "name": "Linux (Release)", + "type": "hxcpp", + "preLaunchTask": "Build Linux (Release)", + "request": "launch", + "program": "${workspaceFolder}/export/debug/linux/bin/Kade Engine" + }, + ], +} \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000000..10160415cb --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,46 @@ +{ + "lime.targetConfigurations": [ + { + "label": "Build Windows (Debug)", + "target": "windows", + "args": [ + "-debug" + ] + }, + { + "label": "Build Windows (Release)", + "target": "windows", + "args": [ + "-release" + ] + }, + { + "label": "Build Linux (Debug)", + "target": "linux", + "args": [ + "-debug" + ] + }, + { + "label": "Build Linux (Release)", + "target": "linux", + "args": [ + "-release" + ] + }, + { + "label": "Build HTML5 (Debug)", + "target": "html5", + "args": [ + "-debug" + ] + }, + { + "label": "Build HTML5 (Release)", + "target": "html5", + "args": [ + "-release" + ] + } + ] +} \ No newline at end of file diff --git a/.vscode/tasks.json b/.vscode/tasks.json index 0930c09c67..012d4d784b 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -1,21 +1,65 @@ { "version": "2.0.0", "tasks": [ - { - "type": "lime", - "command": "test", - "group": { - "kind": "build", - "isDefault": true - } - }, - { - "type": "lime", - "command": "build", - "group": { - "kind": "build", - "isDefault": true - } - } + { + "label": "Build Windows (Debug)", + "type": "lime", + "targetConfiguration": "Build Windows (Debug)", + "command": "build", + "group": { + "kind": "build", + "isDefault": true + } + }, + { + "label": "Build Windows (Release)", + "type": "lime", + "targetConfiguration": "Build Windows (Release)", + "command": "build", + "group": { + "kind": "build", + "isDefault": true + } + }, + { + "label": "Build HTML5 (Debug)", + "type": "lime", + "targetConfiguration": "Build HTML5 (Debug)", + "command": "build", + "group": { + "kind": "build", + "isDefault": true + } + }, + { + "label": "Build HTML5 (Release)", + "type": "lime", + "targetConfiguration": "Build HTML5 (Release)", + "command": "build", + "group": { + "kind": "build", + "isDefault": true + } + }, + { + "label": "Build Linux (Debug)", + "type": "lime", + "targetConfiguration": "Build Linux (Debug)", + "command": "build", + "group": { + "kind": "build", + "isDefault": true + } + }, + { + "label": "Build Linux (Release)", + "type": "lime", + "targetConfiguration": "Build Linux (Release)", + "command": "build", + "group": { + "kind": "build", + "isDefault": true + } + } ] } diff --git a/Project.xml b/Project.xml index 3bb076cb35..fe4df8fdf0 100644 --- a/Project.xml +++ b/Project.xml @@ -126,7 +126,7 @@ - + @@ -185,5 +185,21 @@ - + + + + + + + + + + + + + + + + + diff --git a/source/Caching.hx b/source/Caching.hx index 9b62ff0997..d6084c4206 100644 --- a/source/Caching.hx +++ b/source/Caching.hx @@ -1,8 +1,8 @@ -#if sys +#if FEATURE_FILESYSTEM package; import lime.app.Application; -#if desktop +#if FEATURE_DISCORD import Discord.DiscordClient; #end import openfl.display.BitmapData; @@ -11,7 +11,7 @@ import flixel.ui.FlxBar; import haxe.Exception; import flixel.tweens.FlxEase; import flixel.tweens.FlxTween; -#if cpp +#if FEATURE_FILESYSTEM import sys.FileSystem; import sys.io.File; #end @@ -80,7 +80,7 @@ class Caching extends MusicBeatState FlxGraphic.defaultPersist = FlxG.save.data.cacheImages; - #if cpp + #if FEATURE_FILESYSTEM if (FlxG.save.data.cacheImages) { trace("caching images..."); @@ -113,7 +113,7 @@ class Caching extends MusicBeatState trace('starting caching..'); - #if cpp + #if FEATURE_MULTITHREADING // update thread sys.thread.Thread.create(() -> @@ -150,7 +150,7 @@ class Caching extends MusicBeatState function cache() { - #if !linux + #if FEATURE_FILESYSTEM trace("LOADING: " + toBeDone + " OBJECTS."); for (i in images) diff --git a/source/ChartingState.hx b/source/ChartingState.hx index a4e7e25f07..aa2b3102d6 100644 --- a/source/ChartingState.hx +++ b/source/ChartingState.hx @@ -2,7 +2,7 @@ package; import openfl.system.System; import lime.app.Application; -#if sys +#if FEATURE_FILESYSTEM import sys.io.File; import sys.FileSystem; #end @@ -45,7 +45,7 @@ import openfl.events.IOErrorEvent; import openfl.media.Sound; import openfl.net.FileReference; import openfl.utils.ByteArray; -#if desktop +#if FEATURE_DISCORD import Discord.DiscordClient; #end @@ -141,7 +141,7 @@ class ChartingState extends MusicBeatState override function create() { - #if desktop + #if FEATURE_DISCORD DiscordClient.changePresence("Chart Editor", null, null, true); #end @@ -172,10 +172,11 @@ class ChartingState extends MusicBeatState if (PlayState.SONG != null) { - if (PlayState.isSM) - _song = Song.conversionChecks(Song.loadFromJsonRAW(File.getContent(PlayState.pathToSm + "/converted.json"))); - else - { + if (PlayState.isSM) { + #if FEATURE_STEPMANIA + _song = Song.conversionChecks(Song.loadFromJsonRAW(File.getContent(PlayState.pathToSm + "/converted.json"))); + #end + } else { var songFormat = StringTools.replace(PlayState.SONG.song, " ", "-"); switch (songFormat) { @@ -1036,7 +1037,7 @@ class ChartingState extends MusicBeatState var stepperSpeedLabel = new FlxText(74, 80, 'Scroll Speed'); var stepperVocalVol:FlxUINumericStepper = new FlxUINumericStepper(10, 95, 0.1, 1, 0.1, 10, 1); - #if sys + #if FEATURE_STEPMANIA if (!PlayState.isSM) stepperVocalVol.value = vocals.volume; else @@ -1466,7 +1467,7 @@ class ChartingState extends MusicBeatState } if (reloadFromFile) { - #if sys + #if FEATURE_STEPMANIA if (PlayState.isSM) { trace("Loading " + PlayState.pathToSm + "/" + PlayState.sm.header.MUSIC); @@ -1481,9 +1482,12 @@ class ChartingState extends MusicBeatState FlxG.sound.playMusic(Paths.inst(daSong), 0.6); #end - if (PlayState.isSM) - _song = Song.conversionChecks(Song.loadFromJsonRAW(File.getContent(PlayState.pathToSm + "/converted.json"))); - else + if (PlayState.isSM) { + #if FEATURE_STEPMANIA + _song = Song.conversionChecks(Song.loadFromJsonRAW(File.getContent(PlayState.pathToSm + "/converted.json"))); + #end + } + else { var songFormat = StringTools.replace(PlayState.SONG.song, " ", "-"); switch (songFormat) @@ -1502,7 +1506,7 @@ class ChartingState extends MusicBeatState } } // WONT WORK FOR TUTORIAL OR TEST SONG!!! REDO LATER - #if sys + #if FEATURE_STEPMANIA if (PlayState.isSM) vocals = null; else @@ -1844,6 +1848,8 @@ class ChartingState extends MusicBeatState { @:privateAccess { + #if desktop + // The __backend.handle attribute is only available on native. lime.media.openal.AL.sourcef(FlxG.sound.music._channel.__source.__backend.handle, lime.media.openal.AL.PITCH, speed); try { @@ -1855,9 +1861,10 @@ class ChartingState extends MusicBeatState } } catch (e) - { - // trace("failed to pitch vocals (probably cuz they don't exist)"); - } + { + // trace("failed to pitch vocals (probably cuz they don't exist)"); + } + #end } } } @@ -2826,7 +2833,7 @@ class ChartingState extends MusicBeatState function updateHeads():Void { var mustHit = check_mustHitSection.checked; - #if sys + #if FEATURE_FILESYSTEM var head = (mustHit ? _song.player1 : _song.player2); var i = sectionRenderes.members[curSection]; diff --git a/source/DiffOverview.hx b/source/DiffOverview.hx index 2a11393c99..5d648446a5 100644 --- a/source/DiffOverview.hx +++ b/source/DiffOverview.hx @@ -23,7 +23,6 @@ import flixel.util.FlxSort; import flixel.tweens.FlxEase; import flixel.tweens.FlxTween; import flixel.util.FlxColor; -import io.newgrounds.NG; import lime.app.Application; import lime.utils.Assets; import flixel.math.FlxMath; diff --git a/source/Discord.hx b/source/Discord.hx index 5dc9c640f9..658e3521df 100644 --- a/source/Discord.hx +++ b/source/Discord.hx @@ -1,4 +1,5 @@ package; +#if FEATURE_DISCORD import Sys.sleep; import discord_rpc.DiscordRpc; @@ -84,4 +85,5 @@ class DiscordClient //trace('Discord RPC Updated. Arguments: $details, $state, $smallImageKey, $hasStartTimestamp, $endTimestamp'); } -} \ No newline at end of file +} +#end \ No newline at end of file diff --git a/source/FreeplayState.hx b/source/FreeplayState.hx index ef7096c954..926c4046b4 100644 --- a/source/FreeplayState.hx +++ b/source/FreeplayState.hx @@ -3,8 +3,10 @@ import lime.app.Application; import openfl.utils.Future; import openfl.media.Sound; import flixel.system.FlxSound; -#if sys +#if FEATURE_STEPMANIA import smTools.SMFile; +#end +#if FEATURE_FILESYSTEM import sys.FileSystem; import sys.io.File; #end @@ -21,7 +23,7 @@ import flixel.util.FlxColor; import lime.utils.Assets; -#if desktop +#if FEATURE_DISCORD import Discord.DiscordClient; #end @@ -93,7 +95,7 @@ class FreeplayState extends MusicBeatState var diffsThatExist = []; - #if sys + #if FEATURE_FILESYSTEM if (FileSystem.exists('assets/data/${format}/${format}-hard.json')) diffsThatExist.push("Hard"); if (FileSystem.exists('assets/data/${format}/${format}-easy.json')) @@ -129,7 +131,7 @@ class FreeplayState extends MusicBeatState trace("tryin to load sm files"); - #if sys + #if FEATURE_STEPMANIA for(i in FileSystem.readDirectory("assets/sm/")) { trace(i); @@ -178,7 +180,7 @@ class FreeplayState extends MusicBeatState } */ - #if desktop + #if FEATURE_DISCORD // Updating Discord Rich Presence DiscordClient.changePresence("In the Freeplay Menu", null); #end @@ -448,7 +450,7 @@ class FreeplayState extends MusicBeatState PlayState.storyDifficulty = curDifficulty; PlayState.storyWeek = songs[curSelected].week; trace('CUR WEEK' + PlayState.storyWeek); - #if sys + #if FEATURE_STEPMANIA if (songs[curSelected].songCharacter == "sm") { PlayState.isSM = true; @@ -606,7 +608,7 @@ class SongMetadata { public var songName:String = ""; public var week:Int = 0; - #if sys + #if FEATURE_STEPMANIA public var sm:SMFile; public var path:String; #end @@ -614,7 +616,7 @@ class SongMetadata public var diffs = []; - #if sys + #if FEATURE_STEPMANIA public function new(song:String, week:Int, songCharacter:String, ?sm:SMFile = null, ?path:String = "") { this.songName = song; diff --git a/source/GameplayCustomizeState.hx b/source/GameplayCustomizeState.hx index 16dd43fb76..4fcbbb537a 100644 --- a/source/GameplayCustomizeState.hx +++ b/source/GameplayCustomizeState.hx @@ -6,9 +6,8 @@ import flixel.math.FlxMath; import flixel.FlxCamera; import flixel.math.FlxPoint; import flixel.FlxObject; -#if desktop +#if FEATURE_DISCORD import Discord.DiscordClient; -import sys.thread.Thread; #end import flixel.group.FlxGroup.FlxTypedGroup; @@ -41,7 +40,7 @@ class GameplayCustomizeState extends MusicBeatState private var camHUD:FlxCamera; public override function create() { - #if desktop + #if FEATURE_DISCORD // Updating Discord Rich Presence DiscordClient.changePresence("Customizing Gameplay Modules", null); #end diff --git a/source/KeyBindMenu.hx b/source/KeyBindMenu.hx index 12d1a5e35f..c7b3075575 100644 --- a/source/KeyBindMenu.hx +++ b/source/KeyBindMenu.hx @@ -19,7 +19,6 @@ import flixel.text.FlxText; import flixel.tweens.FlxEase; import flixel.tweens.FlxTween; import flixel.util.FlxColor; -import io.newgrounds.NG; import lime.app.Application; import lime.utils.Assets; import flixel.math.FlxMath; diff --git a/source/LoadReplayState.hx b/source/LoadReplayState.hx index 2cf4e9e624..9014e480df 100644 --- a/source/LoadReplayState.hx +++ b/source/LoadReplayState.hx @@ -3,9 +3,8 @@ package; import haxe.Exception; import lime.app.Application; -#if sys +#if FEATURE_STEPMANIA import smTools.SMFile; -import sys.FileSystem; #end import Controls.KeyboardScheme; import Controls.Control; @@ -19,7 +18,8 @@ import flixel.math.FlxMath; import flixel.text.FlxText; import flixel.util.FlxColor; import lime.utils.Assets; -#if sys +#if FEATURE_FILESYSTEM +import sys.FileSystem; import sys.io.File; #end @@ -39,7 +39,7 @@ class LoadReplayState extends MusicBeatState override function create() { var menuBG:FlxSprite = new FlxSprite().loadGraphic(Paths.image('menuDesat')); - #if sys + #if FEATURE_FILESYSTEM controlsStrings = sys.FileSystem.readDirectory(Sys.getCwd() + "/assets/replays/"); #end trace(controlsStrings); @@ -179,7 +179,7 @@ class LoadReplayState extends MusicBeatState var poop = ""; - #if sys + #if FEATURE_STEPMANIA if (PlayState.rep.replay.sm) if (!FileSystem.exists(StringTools.replace(PlayState.rep.replay.chartPath,"converted.json",""))) { @@ -189,12 +189,12 @@ class LoadReplayState extends MusicBeatState #end PlayState.isSM = PlayState.rep.replay.sm; - #if sys + #if FEATURE_STEPMANIA if (PlayState.isSM) PlayState.pathToSm = StringTools.replace(PlayState.rep.replay.chartPath,"converted.json",""); #end - #if sys + #if FEATURE_STEPMANIA if (PlayState.isSM) { poop = File.getContent(PlayState.rep.replay.chartPath); diff --git a/source/LuaClass.hx b/source/LuaClass.hx index 375054d1f4..0fb9579ef1 100644 --- a/source/LuaClass.hx +++ b/source/LuaClass.hx @@ -1,3 +1,4 @@ +#if FEATURE_LUAMODCHART import flixel.FlxG; import llua.Convert; import llua.Lua; @@ -7,9 +8,11 @@ import flixel.util.FlxAxes; import flixel.FlxSprite; import lime.app.Application; import openfl.Lib; +#if FEATURE_FILESYSTEM import sys.io.File; -import flash.display.BitmapData; import sys.FileSystem; +#end +import flash.display.BitmapData; import flixel.graphics.frames.FlxAtlasFrames; import flixel.FlxCamera; import flixel.tweens.FlxEase; @@ -18,1772 +21,1936 @@ import haxe.DynamicAccess; // completely yoinked from andromeda (thats what you get for stealing my callback inputs you fuckers /j) -typedef LuaProperty = { - var defaultValue:Any; - var getter:(State,Any)->Int; - var setter:State->Int; +typedef LuaProperty = +{ + var defaultValue:Any; + var getter:(State, Any) -> Int; + var setter:State->Int; } -class LuaStorage { - public static var ListOfCameras:Array = []; - public static var objectProperties:Map> = []; - public static var objects:Map = []; +class LuaStorage +{ + public static var ListOfCameras:Array = []; + public static var objectProperties:Map> = []; + public static var objects:Map = []; } -class LuaClass { - public var properties:Map = []; - public var methods:MapInt> > = []; - public var className:String = "BaseClass"; - private static var state:State; - public var addToGlobal:Bool=true; - public function Register(l:State){ - Lua.newtable(l); - state=l; - LuaStorage.objectProperties[className]=this.properties; - - var classIdx = Lua.gettop(l); - Lua.pushvalue(l,classIdx); - if(addToGlobal) - Lua.setglobal(l,className); - - for (k in methods.keys()){ - Lua.pushcfunction(l,methods[k]); - Lua.setfield(l,classIdx,k); - } - - LuaL.newmetatable(l,className + "Metatable"); - var mtIdx = Lua.gettop(l); - Lua.pushstring(l, "__index"); - Lua.pushcfunction(l,cpp.Callable.fromStaticFunction(index)); +class LuaClass +{ + public var properties:Map = []; + public var methods:MapInt>> = []; + public var className:String = "BaseClass"; + + private static var state:State; + + public var addToGlobal:Bool = true; + + public function Register(l:State) + { + Lua.newtable(l); + state = l; + LuaStorage.objectProperties[className] = this.properties; + + var classIdx = Lua.gettop(l); + Lua.pushvalue(l, classIdx); + if (addToGlobal) + Lua.setglobal(l, className); + + for (k in methods.keys()) + { + Lua.pushcfunction(l, methods[k]); + Lua.setfield(l, classIdx, k); + } + + LuaL.newmetatable(l, className + "Metatable"); + var mtIdx = Lua.gettop(l); + Lua.pushstring(l, "__index"); + Lua.pushcfunction(l, cpp.Callable.fromStaticFunction(index)); + Lua.settable(l, mtIdx); + + Lua.pushstring(l, "__newindex"); + Lua.pushcfunction(l, cpp.Callable.fromStaticFunction(newindex)); + Lua.settable(l, mtIdx); + + for (k in properties.keys()) + { + Lua.pushstring(l, k + "PropertyData"); + Convert.toLua(l, properties[k].defaultValue); + Lua.settable(l, mtIdx); + } + Lua.pushstring(l, "_CLASSNAME"); + Lua.pushstring(l, className); Lua.settable(l, mtIdx); - Lua.pushstring(l, "__newindex"); - Lua.pushcfunction(l,cpp.Callable.fromStaticFunction(newindex)); + Lua.pushstring(l, "__metatable"); + Lua.pushstring(l, "This metatable is locked."); Lua.settable(l, mtIdx); - - for (k in properties.keys()){ - Lua.pushstring(l,k + "PropertyData"); - Convert.toLua(l,properties[k].defaultValue); - Lua.settable(l,mtIdx); - } - Lua.pushstring(l,"_CLASSNAME"); - Lua.pushstring(l,className); - Lua.settable(l,mtIdx); - - Lua.pushstring(l,"__metatable"); - Lua.pushstring(l,"This metatable is locked."); - Lua.settable(l,mtIdx); - - Lua.setmetatable(l,classIdx); - - }; - - - public static function index(l:StatePointer):Int{ - var l = state; - var index = Lua.tostring(l,-1); - if(Lua.getmetatable(l,-2)!=0){ - var mtIdx = Lua.gettop(l); - Lua.pushstring(l,index + "PropertyData"); - Lua.rawget(l,mtIdx); - var data:Any = Convert.fromLua(l,-1); - if(data!=null){ - Lua.pushstring(l,"_CLASSNAME"); - Lua.rawget(l,mtIdx); - var clName = Lua.tostring(l,-1); - if(LuaStorage.objectProperties[clName]!=null && LuaStorage.objectProperties[clName][index]!=null){ - return LuaStorage.objectProperties[clName][index].getter(l,data); - } - }; - }else{ - // TODO: throw an error! - }; - return 0; - } - - public static function newindex(l:StatePointer):Int{ - var l = state; - var index = Lua.tostring(l,2); - if(Lua.getmetatable(l,1)!=0){ - var mtIdx = Lua.gettop(l); - Lua.pushstring(l,index + "PropertyData"); - Lua.rawget(l,mtIdx); - var data:Any = Convert.fromLua(l,-1); - if(data!=null){ - Lua.pushstring(l,"_CLASSNAME"); - Lua.rawget(l,mtIdx); - var clName = Lua.tostring(l,-1); - if(LuaStorage.objectProperties[clName]!=null && LuaStorage.objectProperties[clName][index]!=null){ - Lua.pop(l,2); - return LuaStorage.objectProperties[clName][index].setter(l); - } - }; - }else{ - // TODO: throw an error! - }; - return 0; - } - - public static function SetProperty(l:State,tableIndex:Int,key:String,value:Any){ - Lua.pushstring(l,key + "PropertyData"); - Convert.toLua(l,value); - Lua.settable(l,tableIndex ); - - Lua.pop(l,2); - } - - public static function DefaultSetter(l:State){ - var key = Lua.tostring(l,2); - - Lua.pushstring(l,key + "PropertyData"); - Lua.pushvalue(l,3); - Lua.settable(l,4); - - Lua.pop(l,2); - }; - public function new(){} + + Lua.setmetatable(l, classIdx); + }; + + public static function index(l:StatePointer):Int + { + var l = state; + var index = Lua.tostring(l, -1); + if (Lua.getmetatable(l, -2) != 0) + { + var mtIdx = Lua.gettop(l); + Lua.pushstring(l, index + "PropertyData"); + Lua.rawget(l, mtIdx); + var data:Any = Convert.fromLua(l, -1); + if (data != null) + { + Lua.pushstring(l, "_CLASSNAME"); + Lua.rawget(l, mtIdx); + var clName = Lua.tostring(l, -1); + if (LuaStorage.objectProperties[clName] != null && LuaStorage.objectProperties[clName][index] != null) + { + return LuaStorage.objectProperties[clName][index].getter(l, data); + } + }; + } + else + { + // TODO: throw an error! + }; + return 0; + } + + public static function newindex(l:StatePointer):Int + { + var l = state; + var index = Lua.tostring(l, 2); + if (Lua.getmetatable(l, 1) != 0) + { + var mtIdx = Lua.gettop(l); + Lua.pushstring(l, index + "PropertyData"); + Lua.rawget(l, mtIdx); + var data:Any = Convert.fromLua(l, -1); + if (data != null) + { + Lua.pushstring(l, "_CLASSNAME"); + Lua.rawget(l, mtIdx); + var clName = Lua.tostring(l, -1); + if (LuaStorage.objectProperties[clName] != null && LuaStorage.objectProperties[clName][index] != null) + { + Lua.pop(l, 2); + return LuaStorage.objectProperties[clName][index].setter(l); + } + }; + } + else + { + // TODO: throw an error! + }; + return 0; + } + + public static function SetProperty(l:State, tableIndex:Int, key:String, value:Any) + { + Lua.pushstring(l, key + "PropertyData"); + Convert.toLua(l, value); + Lua.settable(l, tableIndex); + + Lua.pop(l, 2); + } + + public static function DefaultSetter(l:State) + { + var key = Lua.tostring(l, 2); + + Lua.pushstring(l, key + "PropertyData"); + Lua.pushvalue(l, 3); + Lua.settable(l, 4); + + Lua.pop(l, 2); + }; + + public function new() + { + } +} + +class LuaNote extends LuaClass +{ // again, stolen from andromeda but improved a lot for better thinking interoperability (I made that up) + private static var state:State; + + public var note:Note; + + public function new(connectedNote:Note, index:Int) + { + super(); + className = "note_" + index; + + note = connectedNote; + + properties = [ + "alpha" => { + defaultValue: 1, + getter: function(l:State, data:Any):Int + { + Lua.pushnumber(l, connectedNote.alpha); + return 1; + }, + setter: SetNumProperty + }, + + "angle" => { + defaultValue: 1, + getter: function(l:State, data:Any):Int + { + Lua.pushnumber(l, connectedNote.angle); + return 1; + }, + setter: function(l:State):Int + { + // 1 = self + // 2 = key + // 3 = value + // 4 = metatable + if (Lua.type(l, 3) != Lua.LUA_TNUMBER) + { + LuaL.error(l, "invalid argument #3 (number expected, got " + Lua.typename(l, Lua.type(l, 3)) + ")"); + return 0; + } + + var angle = Lua.tonumber(l, 3); + connectedNote.modAngle = angle; + + LuaClass.DefaultSetter(l); + return 0; + } + }, + + "strumTime" => { + defaultValue: 1, + getter: function(l:State, data:Any):Int + { + Lua.pushnumber(l, connectedNote.strumTime); + return 1; + }, + setter: function(l:State):Int + { + // 1 = self + // 2 = key + // 3 = value + // 4 = metatable + // mf you can't modify this shit + return 0; + } + }, + + "data" => { + defaultValue: 1, + getter: function(l:State, data:Any):Int + { + Lua.pushnumber(l, connectedNote.noteData); + return 1; + }, + setter: SetNumProperty + }, + + "mustPress" => { + defaultValue: 1, + getter: function(l:State, data:Any):Int + { + Lua.pushboolean(l, connectedNote.mustPress); + return 1; + }, + setter: SetNumProperty + }, + + "beat" => { + defaultValue: 1, + getter: function(l:State, data:Any):Int + { + Lua.pushnumber(l, connectedNote.beat); + return 1; + }, + setter: SetNumProperty + }, + + "isSustain" => { + defaultValue: 1, + getter: function(l:State, data:Any):Int + { + Lua.pushnumber(l, connectedNote.rawNoteData); + return 1; + }, + setter: SetNumProperty + }, + + "isParent" => { + defaultValue: 1, + getter: function(l:State, data:Any):Int + { + Lua.pushboolean(l, connectedNote.isParent); + return 1; + }, + setter: function(l:State) + { + LuaL.error(l, "isParent is read-only."); + return 0; + } + }, + + "getParent" => { + defaultValue: 1, + getter: function(l:State, data:Any):Int + { + Lua.pushstring(l, "note_" + connectedNote.parent.luaID); + return 1; + }, + setter: function(l:State) + { + LuaL.error(l, "getParent is read-only."); + return 0; + } + }, + + "getChildren" => { + defaultValue: 1, + getter: function(l:State, data:Any):Int + { + Lua.newtable(l); + + for (i in 0...connectedNote.children.length) + { + var note = connectedNote.children[i]; + Lua.pushstring(l, "note_" + note.luaID); + Lua.rawseti(l, -2, i); + } + + return 1; + }, + setter: function(l:State) + { + LuaL.error(l, "getChildren is read-only."); + return 0; + } + }, + + "getSpotInline" => { + defaultValue: 1, + getter: function(l:State, data:Any):Int + { + Lua.pushnumber(l, connectedNote.spotInLine); + return 1; + }, + setter: function(l:State) + { + LuaL.error(l, "spot in line is read-only."); + return 0; + } + }, + + "x" => { + defaultValue: connectedNote.x, + getter: function(l:State, data:Any):Int + { + Lua.pushnumber(l, connectedNote.x); + return 1; + }, + setter: SetNumProperty + }, + + "tweenPos" => { + defaultValue: 0, + getter: function(l:State, data:Any) + { + Lua.pushcfunction(l, tweenPosC); + return 1; + }, + setter: function(l:State) + { + LuaL.error(l, "tweenPos is read-only."); + return 0; + } + }, + + "tweenAlpha" => { + defaultValue: 0, + getter: function(l:State, data:Any) + { + Lua.pushcfunction(l, tweenAlphaC); + return 1; + }, + setter: function(l:State) + { + LuaL.error(l, "tweenAlpha is read-only."); + return 0; + } + }, + + "tweenAngle" => { + defaultValue: 0, + getter: function(l:State, data:Any) + { + Lua.pushcfunction(l, tweenAngleC); + return 1; + }, + setter: function(l:State) + { + LuaL.error(l, "tweenAngle is read-only."); + return 0; + } + }, + + "y" => { + defaultValue: connectedNote.y, + getter: function(l:State, data:Any):Int + { + Lua.pushnumber(l, connectedNote.y); + return 1; + }, + setter: SetNumProperty + } + + ]; + } + + private static function findNote(time:Float, data:Int) + { + for (i in PlayState.instance.notes) + { + if (i.strumTime == time && i.noteData == data) + { + return i; + } + } + return null; + } + + private static function tweenPos(l:StatePointer):Int + { + // 1 = self + // 2 = x + // 3 = y + // 4 = time + var xp = LuaL.checknumber(state, 2); + var yp = LuaL.checknumber(state, 3); + var time = LuaL.checknumber(state, 4); + + Lua.getfield(state, 1, "strumTime"); + var time = Lua.tonumber(state, -1); + Lua.getfield(state, 1, "data"); + var data = Lua.tonumber(state, -1); + + var note = findNote(time, Math.floor(data)); + + if (note == null) + { + LuaL.error(state, "Failure to tween (couldn't find note " + time + ")"); + return 0; + } + + FlxTween.tween(note, {x: xp, y: yp}, time); + + return 0; + } + + private static function tweenAngle(l:StatePointer):Int + { + // 1 = self + // 2 = angle + // 3 = time + var nangle = LuaL.checknumber(state, 2); + var time = LuaL.checknumber(state, 3); + + Lua.getfield(state, 1, "strumTime"); + var time = Lua.tonumber(state, -1); + Lua.getfield(state, 1, "data"); + var data = Lua.tonumber(state, -1); + + var note = findNote(time, Math.floor(data)); + + if (note == null) + { + LuaL.error(state, "Failure to tween (couldn't find note " + time + ")"); + return 0; + } + + FlxTween.tween(note, {modAngle: nangle}, time); + + return 0; + } + + private static function tweenAlpha(l:StatePointer):Int + { + // 1 = self + // 2 = alpha + // 3 = time + var nalpha = LuaL.checknumber(state, 2); + var time = LuaL.checknumber(state, 3); + + Lua.getfield(state, 1, "strumTime"); + var time = Lua.tonumber(state, -1); + Lua.getfield(state, 1, "data"); + var data = Lua.tonumber(state, -1); + + var note = findNote(time, Math.floor(data)); + + if (note == null) + { + LuaL.error(state, "Failure to tween (couldn't find note " + time + ")"); + return 0; + } + FlxTween.tween(note, {alpha: nalpha}, time); + + return 0; + } + + private static var tweenPosC:cpp.CallableInt> = cpp.Callable.fromStaticFunction(tweenPos); + private static var tweenAngleC:cpp.CallableInt> = cpp.Callable.fromStaticFunction(tweenAngle); + private static var tweenAlphaC:cpp.CallableInt> = cpp.Callable.fromStaticFunction(tweenAlpha); + + private function SetNumProperty(l:State) + { + // 1 = self + // 2 = key + // 3 = value + // 4 = metatable + if (Lua.type(l, 3) != Lua.LUA_TNUMBER) + { + LuaL.error(l, "invalid argument #3 (number expected, got " + Lua.typename(l, Lua.type(l, 3)) + ")"); + return 0; + } + note.modifiedByLua = true; + Reflect.setProperty(note, Lua.tostring(l, 2), Lua.tonumber(l, 3)); + return 0; + } + + override function Register(l:State) + { + state = l; + super.Register(l); + } +} + +class LuaReceptor extends LuaClass +{ // again, stolen from andromeda but improved a lot for better thinking interoperability (I made that up) + private static var state:State; + + public var sprite:StaticArrow; + + public function new(connectedSprite:StaticArrow, name:String) + { + super(); + var defaultY = connectedSprite.y; + var defaultX = connectedSprite.x; + var defaultAngle = connectedSprite.angle; + + sprite = connectedSprite; + + className = name; + + properties = [ + "alpha" => { + defaultValue: 1, + getter: function(l:State, data:Any):Int + { + Lua.pushnumber(l, connectedSprite.alpha); + return 1; + }, + setter: SetNumProperty + }, + + "id" => { + defaultValue: name, + getter: function(l:State, data:Any):Int + { + Lua.pushstring(l, name); + return 1; + }, + setter: SetNumProperty + }, + + "angle" => { + defaultValue: 0, + getter: function(l:State, data:Any):Int + { + Lua.pushnumber(l, connectedSprite.angle); + return 1; + }, + setter: function(l:State):Int + { + // 1 = self + // 2 = key + // 3 = value + // 4 = metatable + if (Lua.type(l, 3) != Lua.LUA_TNUMBER) + { + LuaL.error(l, "invalid argument #3 (number expected, got " + Lua.typename(l, Lua.type(l, 3)) + ")"); + return 0; + } + + var angle = Lua.tonumber(l, 3); + connectedSprite.modAngle = angle; + + LuaClass.DefaultSetter(l); + return 0; + } + }, + + "x" => { + defaultValue: connectedSprite.x, + getter: function(l:State, data:Any):Int + { + Lua.pushnumber(l, connectedSprite.x); + return 1; + }, + setter: SetNumProperty + }, + + "y" => { + defaultValue: connectedSprite.y, + getter: function(l:State, data:Any):Int + { + Lua.pushnumber(l, connectedSprite.y); + return 1; + }, + setter: SetNumProperty + }, + + "defaultAngle" => { + defaultValue: defaultAngle, + getter: function(l:State, data:Any):Int + { + Lua.pushnumber(l, defaultAngle); + return 1; + }, + setter: SetNumProperty + }, + + "defaultX" => { + defaultValue: defaultX, + getter: function(l:State, data:Any):Int + { + Lua.pushnumber(l, defaultX); + return 1; + }, + setter: SetNumProperty + }, + + "tweenPos" => { + defaultValue: 0, + getter: function(l:State, data:Any) + { + Lua.pushcfunction(l, tweenPosC); + return 1; + }, + setter: function(l:State) + { + LuaL.error(l, "tweenPos is read-only."); + return 0; + } + }, + + "tweenAlpha" => { + defaultValue: 0, + getter: function(l:State, data:Any) + { + Lua.pushcfunction(l, tweenAlphaC); + return 1; + }, + setter: function(l:State) + { + LuaL.error(l, "tweenAlpha is read-only."); + return 0; + } + }, + + "tweenAngle" => { + defaultValue: 0, + getter: function(l:State, data:Any) + { + Lua.pushcfunction(l, tweenAngleC); + return 1; + }, + setter: function(l:State) + { + LuaL.error(l, "tweenAngle is read-only."); + return 0; + } + }, + + "defaultY" => { + defaultValue: defaultY, + getter: function(l:State, data:Any):Int + { + Lua.pushnumber(l, defaultY); + return 1; + }, + setter: function(l:State):Int + { + // 1 = self + // 2 = key + // 3 = value + // 4 = metatable + return 0; + } + } + + ]; + } + + private static function findReceptor(index:Int) + { + for (i in 0...PlayState.strumLineNotes.length) + { + if (index == i) + { + return PlayState.strumLineNotes.members[i]; + } + } + return null; + } + + private static function tweenPos(l:StatePointer):Int + { + // 1 = self + // 2 = x + // 3 = y + // 4 = time + var xp = LuaL.checknumber(state, 2); + var yp = LuaL.checknumber(state, 3); + var time = LuaL.checknumber(state, 4); + + Lua.getfield(state, 1, "id"); + var index = Std.parseInt(Lua.tostring(state, -1).split('_')[1]); + + var receptor = findReceptor(index); + + if (receptor == null) + { + LuaL.error(state, "Failure to tween (couldn't find receptor " + index + ")"); + return 0; + } + + FlxTween.tween(receptor, {x: xp, y: yp}, time); + + return 0; + } + + private static function tweenAngle(l:StatePointer):Int + { + // 1 = self + // 2 = angle + // 3 = time + var nangle = LuaL.checknumber(state, 2); + var time = LuaL.checknumber(state, 3); + + Lua.getfield(state, 1, "id"); + var index = Std.parseInt(Lua.tostring(state, -1).split('_')[1]); + + var receptor = findReceptor(index); + + if (receptor == null) + { + LuaL.error(state, "Failure to tween (couldn't find receptor " + index + ")"); + return 0; + } + + FlxTween.tween(receptor, {modAngle: nangle}, time); + + return 0; + } + + private static function tweenAlpha(l:StatePointer):Int + { + // 1 = self + // 2 = alpha + // 3 = time + var nalpha = LuaL.checknumber(state, 2); + var time = LuaL.checknumber(state, 3); + + Lua.getfield(state, 1, "id"); + var index = Std.parseInt(Lua.tostring(state, -1).split('_')[1]); + + var receptor = findReceptor(index); + + if (receptor == null) + { + LuaL.error(state, "Failure to tween (couldn't find receptor " + index + ")"); + return 0; + } + + FlxTween.tween(receptor, {alpha: nalpha}, time); + + return 0; + } + + private static var tweenPosC:cpp.CallableInt> = cpp.Callable.fromStaticFunction(tweenPos); + private static var tweenAngleC:cpp.CallableInt> = cpp.Callable.fromStaticFunction(tweenAngle); + private static var tweenAlphaC:cpp.CallableInt> = cpp.Callable.fromStaticFunction(tweenAlpha); + + private function SetNumProperty(l:State) + { + // 1 = self + // 2 = key + // 3 = value + // 4 = metatable + if (Lua.type(l, 3) != Lua.LUA_TNUMBER) + { + LuaL.error(l, "invalid argument #3 (number expected, got " + Lua.typename(l, Lua.type(l, 3)) + ")"); + return 0; + } + + sprite.modifiedByLua = true; + + Reflect.setProperty(sprite, Lua.tostring(l, 2), Lua.tonumber(l, 3)); + return 0; + } + + override function Register(l:State) + { + state = l; + super.Register(l); + trace("Registered " + className); + } +} + +class LuaCamera extends LuaClass +{ // again, stolen from andromeda but improved a lot for better thinking interoperability (I made that up) + private static var state:State; + + public var cam:FlxCamera; + + public function new(connectedCamera:FlxCamera, name:String) + { + super(); + cam = connectedCamera; + + className = name; + + properties = [ + "alpha" => { + defaultValue: 1, + getter: function(l:State, data:Any):Int + { + Lua.pushnumber(l, connectedCamera.alpha); + return 1; + }, + setter: SetNumProperty + }, + + "angle" => { + defaultValue: 0, + getter: function(l:State, data:Any):Int + { + Lua.pushnumber(l, connectedCamera.angle); + return 1; + }, + setter: SetNumProperty + }, + + "x" => { + defaultValue: connectedCamera.x, + getter: function(l:State, data:Any):Int + { + Lua.pushnumber(l, connectedCamera.x); + return 1; + }, + setter: SetNumProperty + }, + + "y" => { + defaultValue: connectedCamera.y, + getter: function(l:State, data:Any):Int + { + Lua.pushnumber(l, connectedCamera.y); + return 1; + }, + setter: SetNumProperty + }, + + "id" => { + defaultValue: className, + getter: function(l:State, data:Any):Int + { + Lua.pushstring(l, className); + return 1; + }, + setter: SetNumProperty + }, + + "tweenZoom" => { + defaultValue: 0, + getter: function(l:State, data:Any) + { + Lua.pushcfunction(l, tweenZoomC); + return 1; + }, + setter: function(l:State) + { + LuaL.error(l, "tweenZoom is read-only."); + return 0; + } + }, + + "tweenPos" => { + defaultValue: 0, + getter: function(l:State, data:Any) + { + Lua.pushcfunction(l, tweenPosC); + return 1; + }, + setter: function(l:State) + { + LuaL.error(l, "tweenPos is read-only."); + return 0; + } + }, + + "tweenAlpha" => { + defaultValue: 0, + getter: function(l:State, data:Any) + { + Lua.pushcfunction(l, tweenAlphaC); + return 1; + }, + setter: function(l:State) + { + LuaL.error(l, "tweenAlpha is read-only."); + return 0; + } + }, + + "tweenAngle" => { + defaultValue: 0, + getter: function(l:State, data:Any) + { + Lua.pushcfunction(l, tweenAngleC); + return 1; + }, + setter: function(l:State) + { + LuaL.error(l, "tweenAngle is read-only."); + return 0; + } + }, + ]; + + LuaStorage.ListOfCameras.push(this); + } + + private function SetNumProperty(l:State) + { + // 1 = self + // 2 = key + // 3 = value + // 4 = metatable + if (Lua.type(l, 3) != Lua.LUA_TNUMBER) + { + LuaL.error(l, "invalid argument #3 (number expected, got " + Lua.typename(l, Lua.type(l, 3)) + ")"); + return 0; + } + Reflect.setProperty(cam, Lua.tostring(l, 2), Lua.tonumber(l, 3)); + return 0; + } + + private static function tweenZoom(l:StatePointer):Int + { + // 1 = self + // 2 = zoom + // 3 = time + var nzoom = LuaL.checknumber(state, 2); + var time = LuaL.checknumber(state, 3); + + Lua.getfield(state, 1, "id"); + var index = Lua.tostring(state, -1); + + var camera:FlxCamera = null; + + for (i in LuaStorage.ListOfCameras) + { + if (i.className == index) + { + camera = i.cam; + } + } + + if (camera == null) + { + LuaL.error(state, "Failure to tween (couldn't find camera " + index + ")"); + return 0; + } + + FlxTween.tween(camera, {zoom: nzoom}, time); + + return 0; + } + + private static var tweenZoomC:cpp.CallableInt> = cpp.Callable.fromStaticFunction(tweenZoom); + + private static function tweenPos(l:StatePointer):Int + { + // 1 = self + // 2 = x + // 3 = y + // 4 = time + var xp = LuaL.checknumber(state, 2); + var yp = LuaL.checknumber(state, 3); + var time = LuaL.checknumber(state, 4); + + Lua.getfield(state, 1, "id"); + var index = Lua.tostring(state, -1); + + var camera:FlxCamera = null; + + for (i in LuaStorage.ListOfCameras) + { + if (i.className == index) + camera = i.cam; + } + + if (camera == null) + { + LuaL.error(state, "Failure to tween (couldn't find camera " + index + ")"); + return 0; + } + + FlxTween.tween(camera, {x: xp, y: yp}, time); + + return 0; + } + + private static function tweenAngle(l:StatePointer):Int + { + // 1 = self + // 2 = angle + // 3 = time + var nangle = LuaL.checknumber(state, 2); + var time = LuaL.checknumber(state, 3); + + Lua.getfield(state, 1, "id"); + var index = Lua.tostring(state, -1); + + var camera:FlxCamera = null; + + for (i in LuaStorage.ListOfCameras) + { + if (i.className == index) + camera = i.cam; + } + + if (camera == null) + { + LuaL.error(state, "Failure to tween (couldn't find camera " + index + ")"); + return 0; + } + + FlxTween.tween(camera, {modAngle: nangle}, time); + + return 0; + } + + private static function tweenAlpha(l:StatePointer):Int + { + // 1 = self + // 2 = alpha + // 3 = time + var nalpha = LuaL.checknumber(state, 2); + var time = LuaL.checknumber(state, 3); + + Lua.getfield(state, 1, "id"); + var index = Lua.tostring(state, -1); + + var camera:FlxCamera = null; + + for (i in LuaStorage.ListOfCameras) + { + if (i.className == index) + camera = i.cam; + } + + if (camera == null) + { + LuaL.error(state, "Failure to tween (couldn't find camera " + index + ")"); + return 0; + } + + FlxTween.tween(camera, {alpha: nalpha}, time); + + return 0; + } + + private static var tweenPosC:cpp.CallableInt> = cpp.Callable.fromStaticFunction(tweenPos); + private static var tweenAngleC:cpp.CallableInt> = cpp.Callable.fromStaticFunction(tweenAngle); + private static var tweenAlphaC:cpp.CallableInt> = cpp.Callable.fromStaticFunction(tweenAlpha); + + override function Register(l:State) + { + state = l; + super.Register(l); + trace("Registered " + className); + } +} + +class LuaCharacter extends LuaClass +{ // again, stolen from andromeda but improved a lot for better thinking interoperability (I made that up) + private static var state:State; + + public var char:Character; + public var isPlayer:Bool = false; + + public static var ListOfCharacters:Array = []; + + public function new(connectedCharacter:Character, name:String) + { + super(); + className = name; + + char = connectedCharacter; + + isPlayer = char.isPlayer; + + properties = [ + "alpha" => { + defaultValue: 1, + getter: function(l:State, data:Any):Int + { + Lua.pushnumber(l, connectedCharacter.alpha); + return 1; + }, + setter: SetNumProperty + }, + + "angle" => { + defaultValue: 1, + getter: function(l:State, data:Any):Int + { + Lua.pushnumber(l, connectedCharacter.angle); + return 1; + }, + setter: function(l:State):Int + { + // 1 = self + // 2 = key + // 3 = value + // 4 = metatable + if (Lua.type(l, 3) != Lua.LUA_TNUMBER) + { + LuaL.error(l, "invalid argument #3 (number expected, got " + Lua.typename(l, Lua.type(l, 3)) + ")"); + return 0; + } + + var angle = Lua.tonumber(l, 3); + connectedCharacter.angle = angle; + + LuaClass.DefaultSetter(l); + return 0; + } + }, + + "x" => { + defaultValue: connectedCharacter.x, + getter: function(l:State, data:Any):Int + { + Lua.pushnumber(l, connectedCharacter.x); + return 1; + }, + setter: SetNumProperty + }, + + "tweenPos" => { + defaultValue: 0, + getter: function(l:State, data:Any) + { + Lua.pushcfunction(l, tweenPosC); + return 1; + }, + setter: function(l:State) + { + LuaL.error(l, "tweenPos is read-only."); + return 0; + } + }, + + "id" => { + defaultValue: name, + getter: function(l:State, data:Any):Int + { + Lua.pushstring(l, name); + return 1; + }, + setter: SetNumProperty + }, + + "tweenAlpha" => { + defaultValue: 0, + getter: function(l:State, data:Any) + { + Lua.pushcfunction(l, tweenAlphaC); + return 1; + }, + setter: function(l:State) + { + LuaL.error(l, "tweenAlpha is read-only."); + return 0; + } + }, + + "tweenAngle" => { + defaultValue: 0, + getter: function(l:State, data:Any) + { + Lua.pushcfunction(l, tweenAngleC); + return 1; + }, + setter: function(l:State) + { + LuaL.error(l, "tweenAngle is read-only."); + return 0; + } + }, + + "changeCharacter" => { + defaultValue: 0, + getter: function(l:State, data:Any) + { + Lua.pushcfunction(l, changeCharacterC); + return 1; + }, + setter: function(l:State) + { + LuaL.error(l, "changeCharacter is read-only."); + return 0; + } + }, + + "playAnim" => { + defaultValue: 0, + getter: function(l:State, data:Any) + { + Lua.pushcfunction(l, playAnimC); + return 1; + }, + setter: function(l:State) + { + LuaL.error(l, "playAnim is read-only."); + return 0; + } + }, + + "y" => { + defaultValue: connectedCharacter.y, + getter: function(l:State, data:Any):Int + { + Lua.pushnumber(l, connectedCharacter.y); + return 1; + }, + setter: SetNumProperty + } + + ]; + + ListOfCharacters.push(this); + } + + private static function findNote(time:Float, data:Int) + { + for (i in PlayState.instance.notes) + { + if (i.strumTime == time && i.noteData == data) + { + return i; + } + } + return null; + } + + private static function tweenPos(l:StatePointer):Int + { + // 1 = self + // 2 = x + // 3 = y + // 4 = time + var xp = LuaL.checknumber(state, 2); + var yp = LuaL.checknumber(state, 3); + var time = LuaL.checknumber(state, 4); + + Lua.getfield(state, 1, "id"); + var index = Lua.tostring(state, -1); + + var char:Character = null; + + for (i in ListOfCharacters) + { + if (i.className == index) + char = i.char; + } + + if (char == null) + { + LuaL.error(state, "Failure to tween (couldn't find character " + index + ")"); + return 0; + } + + FlxTween.tween(char, {x: xp, y: yp}, time); + + return 0; + } + + private static function tweenAngle(l:StatePointer):Int + { + // 1 = self + // 2 = angle + // 3 = time + var nangle = LuaL.checknumber(state, 2); + var time = LuaL.checknumber(state, 3); + + Lua.getfield(state, 1, "id"); + var index = Lua.tostring(state, -1); + + var char:Character = null; + + for (i in ListOfCharacters) + { + if (i.className == index) + char = i.char; + } + + if (char == null) + { + LuaL.error(state, "Failure to tween (couldn't find character " + index + ")"); + return 0; + } + + FlxTween.tween(char, {angle: nangle}, time); + + return 0; + } + + private static function tweenAlpha(l:StatePointer):Int + { + // 1 = self + // 2 = alpha + // 3 = time + var nalpha = LuaL.checknumber(state, 2); + var time = LuaL.checknumber(state, 3); + + Lua.getfield(state, 1, "id"); + var index = Lua.tostring(state, -1); + + var char:Character = null; + + for (i in ListOfCharacters) + { + if (i.className == index) + char = i.char; + } + + if (char == null) + { + LuaL.error(state, "Failure to tween (couldn't find character " + index + ")"); + return 0; + } + + FlxTween.tween(char, {alpha: nalpha}, time); + + return 0; + } + + private static function changeCharacter(l:StatePointer):Int + { + // 1 = self + // 2 = newName + // 3 = x + // 4 = y + var newName = LuaL.checkstring(state, 2); + var x = LuaL.checknumber(state, 3); + var y = LuaL.checknumber(state, 4); + + Lua.getfield(state, 1, "id"); + var index = Lua.tostring(state, -1); + + var char:Character = null; + var property:LuaCharacter = null; + + for (i in ListOfCharacters) + { + if (i.className == index) + { + char = i.char; + property = i; + } + } + + trace("fuck " + char); + + if (char == null) + { + LuaL.error(state, "Failure to tween (couldn't find character " + index + ")"); + return 0; + } + + PlayState.instance.remove(char); + + PlayState.dad = new Character(x, y, newName, char.isPlayer); + + property.char = PlayState.dad; + + PlayState.instance.add(PlayState.dad); + + return 0; + } + + private static function playAnim(l:StatePointer):Int + { + // 1 = self + // 2 = animation + var anim = LuaL.checkstring(state, 2); + + Lua.getfield(state, 1, "id"); + var index = Lua.tostring(state, -1); + + var char:Character = null; + + for (i in ListOfCharacters) + { + if (i.className == index) + { + char = i.char; + } + } + + if (char == null) + { + LuaL.error(state, "Failure to tween (couldn't find character " + index + ")"); + return 0; + } + + char.playAnim(anim); + + return 0; + } + + private static var playAnimC:cpp.CallableInt> = cpp.Callable.fromStaticFunction(playAnim); + private static var changeCharacterC:cpp.CallableInt> = cpp.Callable.fromStaticFunction(changeCharacter); + private static var tweenPosC:cpp.CallableInt> = cpp.Callable.fromStaticFunction(tweenPos); + private static var tweenAngleC:cpp.CallableInt> = cpp.Callable.fromStaticFunction(tweenAngle); + private static var tweenAlphaC:cpp.CallableInt> = cpp.Callable.fromStaticFunction(tweenAlpha); + + private function SetNumProperty(l:State) + { + // 1 = self + // 2 = key + // 3 = value + // 4 = metatable + if (Lua.type(l, 3) != Lua.LUA_TNUMBER) + { + LuaL.error(l, "invalid argument #3 (number expected, got " + Lua.typename(l, Lua.type(l, 3)) + ")"); + return 0; + } + Reflect.setProperty(char, Lua.tostring(l, 2), Lua.tonumber(l, 3)); + return 0; + } + + override function Register(l:State) + { + state = l; + super.Register(l); + } } -class LuaNote extends LuaClass { // again, stolen from andromeda but improved a lot for better thinking interoperability (I made that up) - private static var state:State; - public var note:Note; - public function new(connectedNote:Note, index:Int){ - super(); - className= "note_" + index; - - note = connectedNote; - - properties=[ - "alpha"=>{ - defaultValue: 1 , - getter: function(l:State,data:Any):Int{ - Lua.pushnumber(l,connectedNote.alpha); - return 1; - }, - setter: SetNumProperty - }, - - "angle"=>{ - defaultValue: 1 , - getter: function(l:State,data:Any):Int{ - Lua.pushnumber(l,connectedNote.angle); - return 1; - }, - setter: function(l:State):Int{ - // 1 = self - // 2 = key - // 3 = value - // 4 = metatable - if(Lua.type(l,3)!=Lua.LUA_TNUMBER){ - LuaL.error(l,"invalid argument #3 (number expected, got " + Lua.typename(l,Lua.type(l,3)) + ")"); - return 0; - } - - var angle = Lua.tonumber(l,3); - connectedNote.modAngle = angle; - - LuaClass.DefaultSetter(l); - return 0; - } - }, - - "strumTime"=>{ - defaultValue: 1 , - getter: function(l:State,data:Any):Int{ - Lua.pushnumber(l,connectedNote.strumTime); - return 1; - }, - setter: function(l:State):Int{ - // 1 = self - // 2 = key - // 3 = value - // 4 = metatable - // mf you can't modify this shit - return 0; - } - }, - - "data"=>{ - defaultValue: 1 , - getter: function(l:State,data:Any):Int{ - Lua.pushnumber(l,connectedNote.noteData); - return 1; - }, - setter: SetNumProperty - }, - - "mustPress"=>{ - defaultValue: 1 , - getter: function(l:State,data:Any):Int{ - Lua.pushboolean(l,connectedNote.mustPress); - return 1; - }, - setter: SetNumProperty - }, - - "beat"=>{ - defaultValue: 1 , - getter: function(l:State,data:Any):Int{ - Lua.pushnumber(l,connectedNote.beat); - return 1; - }, - setter: SetNumProperty - }, - - "isSustain"=>{ - defaultValue: 1 , - getter: function(l:State,data:Any):Int{ - Lua.pushnumber(l,connectedNote.rawNoteData); - return 1; - }, - setter: SetNumProperty - }, - - "isParent"=>{ - defaultValue: 1 , - getter: function(l:State,data:Any):Int{ - Lua.pushboolean(l,connectedNote.isParent); - return 1; - }, - setter:function(l:State){ - LuaL.error(l,"isParent is read-only."); - return 0; - } - }, - - "getParent"=>{ - defaultValue: 1 , - getter: function(l:State,data:Any):Int{ - Lua.pushstring(l,"note_" + connectedNote.parent.luaID); - return 1; - }, - setter:function(l:State){ - LuaL.error(l,"getParent is read-only."); - return 0; - } - }, - - "getChildren"=>{ - defaultValue: 1 , - getter: function(l:State,data:Any):Int{ - Lua.newtable(l); - - for(i in 0...connectedNote.children.length) - { - var note = connectedNote.children[i]; - Lua.pushstring(l,"note_" + note.luaID); - Lua.rawseti(l, -2, i); - } - - return 1; - }, - setter:function(l:State){ - LuaL.error(l,"getChildren is read-only."); - return 0; - } - }, - - "getSpotInline"=>{ - defaultValue: 1 , - getter: function(l:State,data:Any):Int{ - Lua.pushnumber(l,connectedNote.spotInLine); - return 1; - }, - setter:function(l:State){ - LuaL.error(l,"spot in line is read-only."); - return 0; - } - }, - - "x"=> { - defaultValue: connectedNote.x, - getter: function(l:State,data:Any):Int{ - Lua.pushnumber(l,connectedNote.x); - return 1; - }, - setter: SetNumProperty - }, - - "tweenPos"=>{ - defaultValue:0, - getter:function(l:State,data:Any){ - Lua.pushcfunction(l,tweenPosC); - return 1; - }, - setter:function(l:State){ - LuaL.error(l,"tweenPos is read-only."); - return 0; - } - }, - - "tweenAlpha"=>{ - defaultValue:0, - getter:function(l:State,data:Any){ - Lua.pushcfunction(l,tweenAlphaC); - return 1; - }, - setter:function(l:State){ - LuaL.error(l,"tweenAlpha is read-only."); - return 0; - } - }, - - "tweenAngle"=>{ - defaultValue:0, - getter:function(l:State,data:Any){ - Lua.pushcfunction(l,tweenAngleC); - return 1; - }, - setter:function(l:State){ - LuaL.error(l,"tweenAngle is read-only."); - return 0; - } - }, - - - "y"=> { - defaultValue: connectedNote.y, - getter: function(l:State,data:Any):Int{ - Lua.pushnumber(l,connectedNote.y); - return 1; - }, - setter: SetNumProperty - } - - ]; - } - - - private static function findNote(time:Float,data:Int) - { - - for(i in PlayState.instance.notes) - { - if (i.strumTime == time && i.noteData == data) - { - return i; - } - } - return null; - } - - private static function tweenPos(l:StatePointer):Int{ - // 1 = self - // 2 = x - // 3 = y - // 4 = time - var xp = LuaL.checknumber(state,2); - var yp = LuaL.checknumber(state,3); - var time = LuaL.checknumber(state,4); - - Lua.getfield(state,1,"strumTime"); - var time = Lua.tonumber(state,-1); - Lua.getfield(state,1,"data"); - var data = Lua.tonumber(state,-1); - - var note = findNote(time,Math.floor(data)); - - if (note == null) - { - LuaL.error(state,"Failure to tween (couldn't find note " + time + ")"); - return 0; - - } - - FlxTween.tween(note,{x: xp,y:yp},time); - - return 0; - } - - private static function tweenAngle(l:StatePointer):Int{ - // 1 = self - // 2 = angle - // 3 = time - var nangle = LuaL.checknumber(state,2); - var time = LuaL.checknumber(state,3); - - Lua.getfield(state,1,"strumTime"); - var time = Lua.tonumber(state,-1); - Lua.getfield(state,1,"data"); - var data = Lua.tonumber(state,-1); - - var note = findNote(time,Math.floor(data)); - - if (note == null) - { - LuaL.error(state,"Failure to tween (couldn't find note " + time + ")"); - return 0; - - } - - FlxTween.tween(note,{modAngle: nangle},time); - - return 0; - } - - private static function tweenAlpha(l:StatePointer):Int{ - // 1 = self - // 2 = alpha - // 3 = time - var nalpha = LuaL.checknumber(state,2); - var time = LuaL.checknumber(state,3); - - Lua.getfield(state,1,"strumTime"); - var time = Lua.tonumber(state,-1); - Lua.getfield(state,1,"data"); - var data = Lua.tonumber(state,-1); - - var note = findNote(time,Math.floor(data)); - - if (note == null) - { - LuaL.error(state,"Failure to tween (couldn't find note " + time + ")"); - return 0; - - } - FlxTween.tween(note,{alpha: nalpha},time); - - return 0; - } - - private static var tweenPosC:cpp.CallableInt> = cpp.Callable.fromStaticFunction(tweenPos); - private static var tweenAngleC:cpp.CallableInt> = cpp.Callable.fromStaticFunction(tweenAngle); - private static var tweenAlphaC:cpp.CallableInt> = cpp.Callable.fromStaticFunction(tweenAlpha); - - private function SetNumProperty(l:State){ - // 1 = self - // 2 = key - // 3 = value - // 4 = metatable - if(Lua.type(l,3)!=Lua.LUA_TNUMBER){ - LuaL.error(l,"invalid argument #3 (number expected, got " + Lua.typename(l,Lua.type(l,3)) + ")"); - return 0; - } - note.modifiedByLua = true; - Reflect.setProperty(note,Lua.tostring(l,2),Lua.tonumber(l,3)); - return 0; - } - - override function Register(l:State){ - state=l; - super.Register(l); - } - } - - class LuaReceptor extends LuaClass { // again, stolen from andromeda but improved a lot for better thinking interoperability (I made that up) - private static var state:State; - public var sprite:StaticArrow; - public function new(connectedSprite:StaticArrow, name:String){ - super(); - var defaultY = connectedSprite.y; - var defaultX = connectedSprite.x; - var defaultAngle = connectedSprite.angle; - - sprite = connectedSprite; - - className= name; - - properties=[ - "alpha"=>{ - defaultValue: 1 , - getter: function(l:State,data:Any):Int{ - Lua.pushnumber(l,connectedSprite.alpha); - return 1; - }, - setter: SetNumProperty - }, - - "id"=>{ - defaultValue: name , - getter: function(l:State,data:Any):Int{ - Lua.pushstring(l,name); - return 1; - }, - setter: SetNumProperty - }, - - "angle"=>{ - defaultValue: 0 , - getter: function(l:State,data:Any):Int{ - Lua.pushnumber(l,connectedSprite.angle); - return 1; - }, - setter: function(l:State):Int{ - // 1 = self - // 2 = key - // 3 = value - // 4 = metatable - if(Lua.type(l,3)!=Lua.LUA_TNUMBER){ - LuaL.error(l,"invalid argument #3 (number expected, got " + Lua.typename(l,Lua.type(l,3)) + ")"); - return 0; - } - - var angle = Lua.tonumber(l,3); - connectedSprite.modAngle = angle; - - LuaClass.DefaultSetter(l); - return 0; - } - }, - - "x"=> { - defaultValue: connectedSprite.x, - getter: function(l:State,data:Any):Int{ - Lua.pushnumber(l,connectedSprite.x); - return 1; - }, - setter: SetNumProperty - }, - - - "y"=> { - defaultValue: connectedSprite.y, - getter: function(l:State,data:Any):Int{ - Lua.pushnumber(l,connectedSprite.y); - return 1; - }, - setter: SetNumProperty - }, - - "defaultAngle"=>{ - defaultValue: defaultAngle , - getter: function(l:State,data:Any):Int{ - Lua.pushnumber(l,defaultAngle); - return 1; - }, - setter: SetNumProperty - }, - - "defaultX"=> { - defaultValue: defaultX, - getter: function(l:State,data:Any):Int{ - Lua.pushnumber(l,defaultX); - return 1; - }, - setter: SetNumProperty - }, - - - - "tweenPos"=>{ - defaultValue:0, - getter:function(l:State,data:Any){ - Lua.pushcfunction(l,tweenPosC); - return 1; - }, - setter:function(l:State){ - LuaL.error(l,"tweenPos is read-only."); - return 0; - } - }, - - "tweenAlpha"=>{ - defaultValue:0, - getter:function(l:State,data:Any){ - Lua.pushcfunction(l,tweenAlphaC); - return 1; - }, - setter:function(l:State){ - LuaL.error(l,"tweenAlpha is read-only."); - return 0; - } - }, - - "tweenAngle"=>{ - defaultValue:0, - getter:function(l:State,data:Any){ - Lua.pushcfunction(l,tweenAngleC); - return 1; - }, - setter:function(l:State){ - LuaL.error(l,"tweenAngle is read-only."); - return 0; - } - }, - - - "defaultY"=> { - defaultValue: defaultY, - getter: function(l:State,data:Any):Int{ - Lua.pushnumber(l,defaultY); - return 1; - }, - setter: function(l:State):Int{ - // 1 = self - // 2 = key - // 3 = value - // 4 = metatable - return 0; - } - } - - ]; - } - - private static function findReceptor(index:Int) - { - for(i in 0...PlayState.strumLineNotes.length) - { - if (index == i) - { - return PlayState.strumLineNotes.members[i]; - } - } - return null; - } - - private static function tweenPos(l:StatePointer):Int{ - // 1 = self - // 2 = x - // 3 = y - // 4 = time - var xp = LuaL.checknumber(state,2); - var yp = LuaL.checknumber(state,3); - var time = LuaL.checknumber(state,4); - - Lua.getfield(state,1,"id"); - var index = Std.parseInt(Lua.tostring(state,-1).split('_')[1]); - - var receptor = findReceptor(index); - - if (receptor == null) - { - LuaL.error(state,"Failure to tween (couldn't find receptor " + index + ")"); - return 0; - } - - FlxTween.tween(receptor,{x: xp,y:yp},time); - - return 0; - } - - private static function tweenAngle(l:StatePointer):Int{ - // 1 = self - // 2 = angle - // 3 = time - var nangle = LuaL.checknumber(state,2); - var time = LuaL.checknumber(state,3); - - Lua.getfield(state,1,"id"); - var index = Std.parseInt(Lua.tostring(state,-1).split('_')[1]); - - var receptor = findReceptor(index); - - if (receptor == null) - { - LuaL.error(state,"Failure to tween (couldn't find receptor " + index + ")"); - return 0; - } - - FlxTween.tween(receptor,{modAngle: nangle},time); - - return 0; - } - - private static function tweenAlpha(l:StatePointer):Int{ - // 1 = self - // 2 = alpha - // 3 = time - var nalpha = LuaL.checknumber(state,2); - var time = LuaL.checknumber(state,3); - - Lua.getfield(state,1,"id"); - var index = Std.parseInt(Lua.tostring(state,-1).split('_')[1]); - - var receptor = findReceptor(index); - - if (receptor == null) - { - LuaL.error(state,"Failure to tween (couldn't find receptor " + index + ")"); - return 0; - } - - FlxTween.tween(receptor,{alpha: nalpha},time); - - return 0; - } - - private static var tweenPosC:cpp.CallableInt> = cpp.Callable.fromStaticFunction(tweenPos); - private static var tweenAngleC:cpp.CallableInt> = cpp.Callable.fromStaticFunction(tweenAngle); - private static var tweenAlphaC:cpp.CallableInt> = cpp.Callable.fromStaticFunction(tweenAlpha); - - private function SetNumProperty(l:State){ - // 1 = self - // 2 = key - // 3 = value - // 4 = metatable - if(Lua.type(l,3)!=Lua.LUA_TNUMBER){ - LuaL.error(l,"invalid argument #3 (number expected, got " + Lua.typename(l,Lua.type(l,3)) + ")"); - return 0; - } - - sprite.modifiedByLua = true; - - Reflect.setProperty(sprite,Lua.tostring(l,2),Lua.tonumber(l,3)); - return 0; - } - - override function Register(l:State){ - state=l; - super.Register(l); - trace("Registered " + className); - } - } - - class LuaCamera extends LuaClass { // again, stolen from andromeda but improved a lot for better thinking interoperability (I made that up) - private static var state:State; - public var cam:FlxCamera; - - public function new(connectedCamera:FlxCamera, name:String){ - super(); - cam = connectedCamera; - - className= name; - - properties=[ - "alpha"=>{ - defaultValue: 1 , - getter: function(l:State,data:Any):Int{ - Lua.pushnumber(l,connectedCamera.alpha); - return 1; - }, - setter: SetNumProperty - }, - - "angle"=>{ - defaultValue: 0 , - getter: function(l:State,data:Any):Int{ - Lua.pushnumber(l,connectedCamera.angle); - return 1; - }, - setter: SetNumProperty - }, - - "x"=> { - defaultValue: connectedCamera.x, - getter: function(l:State,data:Any):Int{ - Lua.pushnumber(l,connectedCamera.x); - return 1; - }, - setter: SetNumProperty - }, - - - "y"=> { - defaultValue: connectedCamera.y, - getter: function(l:State,data:Any):Int{ - Lua.pushnumber(l,connectedCamera.y); - return 1; - }, - setter: SetNumProperty - }, - - "id"=> { - defaultValue: className, - getter: function(l:State,data:Any):Int{ - Lua.pushstring(l,className); - return 1; - }, - setter: SetNumProperty - }, - - "tweenZoom"=>{ - defaultValue:0, - getter:function(l:State,data:Any){ - Lua.pushcfunction(l,tweenZoomC); - return 1; - }, - setter:function(l:State){ - LuaL.error(l,"tweenZoom is read-only."); - return 0; - } - }, - - "tweenPos"=>{ - defaultValue:0, - getter:function(l:State,data:Any){ - Lua.pushcfunction(l,tweenPosC); - return 1; - }, - setter:function(l:State){ - LuaL.error(l,"tweenPos is read-only."); - return 0; - } - }, - - "tweenAlpha"=>{ - defaultValue:0, - getter:function(l:State,data:Any){ - Lua.pushcfunction(l,tweenAlphaC); - return 1; - }, - setter:function(l:State){ - LuaL.error(l,"tweenAlpha is read-only."); - return 0; - } - }, - - "tweenAngle"=>{ - defaultValue:0, - getter:function(l:State,data:Any){ - Lua.pushcfunction(l,tweenAngleC); - return 1; - }, - setter:function(l:State){ - LuaL.error(l,"tweenAngle is read-only."); - return 0; - } - }, - ]; - - LuaStorage.ListOfCameras.push(this); - } - - private function SetNumProperty(l:State){ - // 1 = self - // 2 = key - // 3 = value - // 4 = metatable - if(Lua.type(l,3)!=Lua.LUA_TNUMBER){ - LuaL.error(l,"invalid argument #3 (number expected, got " + Lua.typename(l,Lua.type(l,3)) + ")"); - return 0; - } - Reflect.setProperty(cam,Lua.tostring(l,2),Lua.tonumber(l,3)); - return 0; - } - - private static function tweenZoom(l:StatePointer):Int{ - // 1 = self - // 2 = zoom - // 3 = time - var nzoom = LuaL.checknumber(state,2); - var time = LuaL.checknumber(state,3); - - Lua.getfield(state,1,"id"); - var index = Lua.tostring(state,-1); - - var camera:FlxCamera = null; - - for(i in LuaStorage.ListOfCameras) - { - if (i.className == index) - { - camera = i.cam; - } - } - - if (camera == null) - { - LuaL.error(state,"Failure to tween (couldn't find camera " + index + ")"); - return 0; - } - - FlxTween.tween(camera,{zoom: nzoom},time); - - return 0; - } - - private static var tweenZoomC:cpp.CallableInt> = cpp.Callable.fromStaticFunction(tweenZoom); - - private static function tweenPos(l:StatePointer):Int{ - // 1 = self - // 2 = x - // 3 = y - // 4 = time - var xp = LuaL.checknumber(state,2); - var yp = LuaL.checknumber(state,3); - var time = LuaL.checknumber(state,4); - - Lua.getfield(state,1,"id"); - var index = Lua.tostring(state,-1); - - var camera:FlxCamera = null; - - for(i in LuaStorage.ListOfCameras) - { - if (i.className == index) - camera = i.cam; - } - - if (camera == null) - { - LuaL.error(state,"Failure to tween (couldn't find camera " + index + ")"); - return 0; - } - - FlxTween.tween(camera,{x: xp,y:yp},time); - - return 0; - } - - private static function tweenAngle(l:StatePointer):Int{ - // 1 = self - // 2 = angle - // 3 = time - var nangle = LuaL.checknumber(state,2); - var time = LuaL.checknumber(state,3); - - Lua.getfield(state,1,"id"); - var index = Lua.tostring(state,-1); - - var camera:FlxCamera = null; - - for(i in LuaStorage.ListOfCameras) - { - if (i.className == index) - camera = i.cam; - } - - if (camera == null) - { - LuaL.error(state,"Failure to tween (couldn't find camera " + index + ")"); - return 0; - } - - FlxTween.tween(camera,{modAngle: nangle},time); - - return 0; - } - - private static function tweenAlpha(l:StatePointer):Int{ - // 1 = self - // 2 = alpha - // 3 = time - var nalpha = LuaL.checknumber(state,2); - var time = LuaL.checknumber(state,3); - - Lua.getfield(state,1,"id"); - var index = Lua.tostring(state,-1); - - var camera:FlxCamera = null; - - for(i in LuaStorage.ListOfCameras) - { - if (i.className == index) - camera = i.cam; - } - - if (camera == null) - { - LuaL.error(state,"Failure to tween (couldn't find camera " + index + ")"); - return 0; - } - - FlxTween.tween(camera,{alpha: nalpha},time); - - return 0; - } - - private static var tweenPosC:cpp.CallableInt> = cpp.Callable.fromStaticFunction(tweenPos); - private static var tweenAngleC:cpp.CallableInt> = cpp.Callable.fromStaticFunction(tweenAngle); - private static var tweenAlphaC:cpp.CallableInt> = cpp.Callable.fromStaticFunction(tweenAlpha); - - override function Register(l:State){ - state=l; - super.Register(l); - trace("Registered " + className); - } - - } - - class LuaCharacter extends LuaClass { // again, stolen from andromeda but improved a lot for better thinking interoperability (I made that up) - private static var state:State; - public var char:Character; - public var isPlayer:Bool = false; - - public static var ListOfCharacters:Array = []; - - public function new(connectedCharacter:Character, name:String){ - super(); - className= name; - - char = connectedCharacter; - - isPlayer = char.isPlayer; - - properties=[ - "alpha"=>{ - defaultValue: 1 , - getter: function(l:State,data:Any):Int{ - Lua.pushnumber(l,connectedCharacter.alpha); - return 1; - }, - setter: SetNumProperty - }, - - "angle"=>{ - defaultValue: 1 , - getter: function(l:State,data:Any):Int{ - Lua.pushnumber(l,connectedCharacter.angle); - return 1; - }, - setter: function(l:State):Int{ - // 1 = self - // 2 = key - // 3 = value - // 4 = metatable - if(Lua.type(l,3)!=Lua.LUA_TNUMBER){ - LuaL.error(l,"invalid argument #3 (number expected, got " + Lua.typename(l,Lua.type(l,3)) + ")"); - return 0; - } - - var angle = Lua.tonumber(l,3); - connectedCharacter.angle = angle; - - LuaClass.DefaultSetter(l); - return 0; - } - }, - - "x"=> { - defaultValue: connectedCharacter.x, - getter: function(l:State,data:Any):Int{ - Lua.pushnumber(l,connectedCharacter.x); - return 1; - }, - setter: SetNumProperty - }, - - "tweenPos"=>{ - defaultValue:0, - getter:function(l:State,data:Any){ - Lua.pushcfunction(l,tweenPosC); - return 1; - }, - setter:function(l:State){ - LuaL.error(l,"tweenPos is read-only."); - return 0; - } - }, - - "id"=>{ - defaultValue: name , - getter: function(l:State,data:Any):Int{ - Lua.pushstring(l,name); - return 1; - }, - setter: SetNumProperty - }, - - "tweenAlpha"=>{ - defaultValue:0, - getter:function(l:State,data:Any){ - Lua.pushcfunction(l,tweenAlphaC); - return 1; - }, - setter:function(l:State){ - LuaL.error(l,"tweenAlpha is read-only."); - return 0; - } - }, - - "tweenAngle"=>{ - defaultValue:0, - getter:function(l:State,data:Any){ - Lua.pushcfunction(l,tweenAngleC); - return 1; - }, - setter:function(l:State){ - LuaL.error(l,"tweenAngle is read-only."); - return 0; - } - }, - - "changeCharacter"=>{ - defaultValue:0, - getter:function(l:State,data:Any){ - Lua.pushcfunction(l,changeCharacterC); - return 1; - }, - setter:function(l:State){ - LuaL.error(l,"changeCharacter is read-only."); - return 0; - } - }, - - "playAnim"=>{ - defaultValue:0, - getter:function(l:State,data:Any){ - Lua.pushcfunction(l,playAnimC); - return 1; - }, - setter:function(l:State){ - LuaL.error(l,"playAnim is read-only."); - return 0; - } - }, - - "y"=> { - defaultValue: connectedCharacter.y, - getter: function(l:State,data:Any):Int{ - Lua.pushnumber(l,connectedCharacter.y); - return 1; - }, - setter: SetNumProperty - } - - ]; - - ListOfCharacters.push(this); - } - - - private static function findNote(time:Float,data:Int) - { - - for(i in PlayState.instance.notes) - { - if (i.strumTime == time && i.noteData == data) - { - return i; - } - } - return null; - } - - private static function tweenPos(l:StatePointer):Int{ - // 1 = self - // 2 = x - // 3 = y - // 4 = time - var xp = LuaL.checknumber(state,2); - var yp = LuaL.checknumber(state,3); - var time = LuaL.checknumber(state,4); - - Lua.getfield(state,1,"id"); - var index = Lua.tostring(state,-1); - - var char:Character = null; - - for(i in ListOfCharacters) - { - if (i.className == index) - char = i.char; - } - - if (char == null) - { - LuaL.error(state,"Failure to tween (couldn't find character " + index + ")"); - return 0; - } - - FlxTween.tween(char,{x: xp,y:yp},time); - - return 0; - } - - private static function tweenAngle(l:StatePointer):Int{ - // 1 = self - // 2 = angle - // 3 = time - var nangle = LuaL.checknumber(state,2); - var time = LuaL.checknumber(state,3); - - Lua.getfield(state,1,"id"); - var index = Lua.tostring(state,-1); - - var char:Character = null; - - for(i in ListOfCharacters) - { - if (i.className == index) - char = i.char; - } - - if (char == null) - { - LuaL.error(state,"Failure to tween (couldn't find character " + index + ")"); - return 0; - } - - FlxTween.tween(char,{angle: nangle},time); - - return 0; - } - - private static function tweenAlpha(l:StatePointer):Int{ - // 1 = self - // 2 = alpha - // 3 = time - var nalpha = LuaL.checknumber(state,2); - var time = LuaL.checknumber(state,3); - - Lua.getfield(state,1,"id"); - var index = Lua.tostring(state,-1); - - var char:Character = null; - - for(i in ListOfCharacters) - { - if (i.className == index) - char = i.char; - } - - if (char == null) - { - LuaL.error(state,"Failure to tween (couldn't find character " + index + ")"); - return 0; - } - - FlxTween.tween(char,{alpha: nalpha},time); - - return 0; - } - - private static function changeCharacter(l:StatePointer):Int{ - // 1 = self - // 2 = newName - // 3 = x - // 4 = y - var newName = LuaL.checkstring(state,2); - var x = LuaL.checknumber(state,3); - var y = LuaL.checknumber(state,4); - - Lua.getfield(state,1,"id"); - var index = Lua.tostring(state,-1); - - var char:Character = null; - var property:LuaCharacter = null; - - for(i in ListOfCharacters) - { - if (i.className == index) - { - char = i.char; - property = i; - } - } - - trace("fuck " + char); - - if (char == null) - { - LuaL.error(state,"Failure to tween (couldn't find character " + index + ")"); - return 0; - } - - - PlayState.instance.remove(char); - - PlayState.dad = new Character(x,y,newName,char.isPlayer); - - property.char = PlayState.dad; - - PlayState.instance.add(PlayState.dad); - - return 0; - } - - private static function playAnim(l:StatePointer):Int{ - // 1 = self - // 2 = animation - var anim = LuaL.checkstring(state,2); - - Lua.getfield(state,1,"id"); - var index = Lua.tostring(state,-1); - - var char:Character = null; - - for(i in ListOfCharacters) - { - if (i.className == index) - { - char = i.char; - } - } - - if (char == null) - { - LuaL.error(state,"Failure to tween (couldn't find character " + index + ")"); - return 0; - } - - char.playAnim(anim); - - return 0; - } - - private static var playAnimC:cpp.CallableInt> = cpp.Callable.fromStaticFunction(playAnim); - private static var changeCharacterC:cpp.CallableInt> = cpp.Callable.fromStaticFunction(changeCharacter); - private static var tweenPosC:cpp.CallableInt> = cpp.Callable.fromStaticFunction(tweenPos); - private static var tweenAngleC:cpp.CallableInt> = cpp.Callable.fromStaticFunction(tweenAngle); - private static var tweenAlphaC:cpp.CallableInt> = cpp.Callable.fromStaticFunction(tweenAlpha); - - private function SetNumProperty(l:State){ - // 1 = self - // 2 = key - // 3 = value - // 4 = metatable - if(Lua.type(l,3)!=Lua.LUA_TNUMBER){ - LuaL.error(l,"invalid argument #3 (number expected, got " + Lua.typename(l,Lua.type(l,3)) + ")"); - return 0; - } - Reflect.setProperty(char,Lua.tostring(l,2),Lua.tonumber(l,3)); - return 0; - } - - override function Register(l:State){ - state=l; - super.Register(l); - } - } - - class LuaSprite extends LuaClass { // again, stolen from andromeda but improved a lot for better thinking interoperability (I made that up) - private static var state:State; - public var sprite:FlxSprite; - - public static var ListOfSprites:Array = []; - - public function new(connectedSprite:FlxSprite, name:String){ - super(); - className= name; - - properties=[ - "alpha"=>{ - defaultValue: 1 , - getter: function(l:State,data:Any):Int{ - Lua.pushnumber(l,connectedSprite.alpha); - return 1; - }, - setter: SetNumProperty - }, - - "angle"=>{ - defaultValue: 1 , - getter: function(l:State,data:Any):Int{ - Lua.pushnumber(l,connectedSprite.angle); - return 1; - }, - setter: function(l:State):Int{ - // 1 = self - // 2 = key - // 3 = value - // 4 = metatable - if(Lua.type(l,3)!=Lua.LUA_TNUMBER){ - LuaL.error(l,"invalid argument #3 (number expected, got " + Lua.typename(l,Lua.type(l,3)) + ")"); - return 0; - } - - var angle = Lua.tonumber(l,3); - connectedSprite.angle = angle; - - LuaClass.DefaultSetter(l); - return 0; - } - }, - - "x"=> { - defaultValue: connectedSprite.x, - getter: function(l:State,data:Any):Int{ - Lua.pushnumber(l,connectedSprite.x); - return 1; - }, - setter: SetNumProperty - }, - - "tweenPos"=>{ - defaultValue:0, - getter:function(l:State,data:Any){ - Lua.pushcfunction(l,tweenPosC); - return 1; - }, - setter:function(l:State){ - LuaL.error(l,"tweenPos is read-only."); - return 0; - } - }, - - "id"=>{ - defaultValue: name , - getter: function(l:State,data:Any):Int{ - Lua.pushstring(l,name); - return 1; - }, - setter: SetNumProperty - }, - - "tweenAlpha"=>{ - defaultValue:0, - getter:function(l:State,data:Any){ - Lua.pushcfunction(l,tweenAlphaC); - return 1; - }, - setter:function(l:State){ - LuaL.error(l,"tweenAlpha is read-only."); - return 0; - } - }, - - "tweenAngle"=>{ - defaultValue:0, - getter:function(l:State,data:Any){ - Lua.pushcfunction(l,tweenAngleC); - return 1; - }, - setter:function(l:State){ - LuaL.error(l,"tweenAngle is read-only."); - return 0; - } - }, - - "destroy"=>{ - defaultValue:0, - getter:function(l:State,data:Any){ - Lua.pushcfunction(l,destroyC); - return 1; - }, - setter:function(l:State){ - LuaL.error(l,"destroy is read-only."); - return 0; - } - }, - - "y"=> { - defaultValue: connectedSprite.y, - getter: function(l:State,data:Any):Int{ - Lua.pushnumber(l,connectedSprite.y); - return 1; - }, - setter: SetNumProperty - } - - ]; - - ListOfSprites.push(this); - } - - - private static function findNote(time:Float,data:Int) - { - - for(i in PlayState.instance.notes) - { - if (i.strumTime == time && i.noteData == data) - { - return i; - } - } - return null; - } - - private static function tweenPos(l:StatePointer):Int{ - // 1 = self - // 2 = x - // 3 = y - // 4 = time - var xp = LuaL.checknumber(state,2); - var yp = LuaL.checknumber(state,3); - var time = LuaL.checknumber(state,4); - - Lua.getfield(state,1,"id"); - var index = Lua.tostring(state,-1); - - var sprite:FlxSprite = null; - - for(i in ListOfSprites) - { - if (i.className == index) - sprite = i.sprite; - } - - if (sprite == null) - { - LuaL.error(state,"Failure to tween (couldn't find sprite " + index + ")"); - return 0; - } - - FlxTween.tween(sprite,{x: xp,y:yp},time); - - return 0; - } - - private static function tweenAngle(l:StatePointer):Int{ - // 1 = self - // 2 = angle - // 3 = time - var nangle = LuaL.checknumber(state,2); - var time = LuaL.checknumber(state,3); - - Lua.getfield(state,1,"id"); - var index = Lua.tostring(state,-1); - - var sprite:FlxSprite = null; - - for(i in ListOfSprites) - { - if (i.className == index) - sprite = i.sprite; - } - - if (sprite == null) - { - LuaL.error(state,"Failure to tween (couldn't find sprite " + index + ")"); - return 0; - } - - FlxTween.tween(sprite,{angle: nangle},time); - - return 0; - } - - private static function tweenAlpha(l:StatePointer):Int{ - // 1 = self - // 2 = alpha - // 3 = time - var nalpha = LuaL.checknumber(state,2); - var time = LuaL.checknumber(state,3); - - Lua.getfield(state,1,"id"); - var index = Lua.tostring(state,-1); - - var sprite:FlxSprite = null; - - for(i in ListOfSprites) - { - if (i.className == index) - sprite = i.sprite; - } - - if (sprite == null) - { - LuaL.error(state,"Failure to tween (couldn't find sprite " + index + ")"); - return 0; - } - - FlxTween.tween(sprite,{alpha: nalpha},time); - - return 0; - } - - - private static function destroy(l:StatePointer):Int{ - // 1 = self - - Lua.getfield(state,1,"id"); - var index = Lua.tostring(state,-1); - - var sprite:FlxSprite = null; - - for(i in ListOfSprites) - { - if (i.className == index) - sprite = i.sprite; - } - - if (sprite == null) - { - LuaL.error(state,"Failure to tween (couldn't find sprite " + index + ")"); - return 0; - } - - PlayState.instance.remove(sprite); - sprite.destroy(); - - return 0; - } - - private static var destroyC:cpp.CallableInt> = cpp.Callable.fromStaticFunction(destroy); - private static var tweenPosC:cpp.CallableInt> = cpp.Callable.fromStaticFunction(tweenPos); - private static var tweenAngleC:cpp.CallableInt> = cpp.Callable.fromStaticFunction(tweenAngle); - private static var tweenAlphaC:cpp.CallableInt> = cpp.Callable.fromStaticFunction(tweenAlpha); - - private function SetNumProperty(l:State){ - // 1 = self - // 2 = key - // 3 = value - // 4 = metatable - if(Lua.type(l,3)!=Lua.LUA_TNUMBER){ - LuaL.error(l,"invalid argument #3 (number expected, got " + Lua.typename(l,Lua.type(l,3)) + ")"); - return 0; - } - Reflect.setProperty(sprite,Lua.tostring(l,2),Lua.tonumber(l,3)); - return 0; - } - - override function Register(l:State){ - state=l; - super.Register(l); - } - } - - class LuaWindow extends LuaClass { // again, stolen from andromeda but improved a lot for better thinking interoperability (I made that up) - private static var state:State; - - public function new(){ - super(); - className= "Window"; - - properties=[ - "x"=> { - defaultValue: Application.current.window.x, - getter: function(l:State,data:Any):Int{ - Lua.pushnumber(l,Application.current.window.x); - return 1; - }, - setter: SetNumProperty - }, - - "y"=> { - defaultValue: Application.current.window.y, - getter: function(l:State,data:Any):Int{ - Lua.pushnumber(l,Application.current.window.y); - return 1; - }, - setter: SetNumProperty - }, - - - "width"=> { - defaultValue: Application.current.window.width, - getter: function(l:State,data:Any):Int{ - Lua.pushnumber(l,Application.current.window.width); - return 1; - }, - setter: SetNumProperty - }, - - "height"=> { - defaultValue: Application.current.window.height, - getter: function(l:State,data:Any):Int{ - Lua.pushnumber(l,Application.current.window.height); - return 1; - }, - setter: SetNumProperty - }, - - "tweenPos"=>{ - defaultValue:0, - getter:function(l:State,data:Any){ - Lua.pushcfunction(l,tweenPosC); - return 1; - }, - setter:function(l:State){ - LuaL.error(l,"tweenPos is read-only."); - return 0; - }, - - }, - ]; - - } - private static function tweenPos(l:StatePointer):Int{ - // 1 = self - // 2 = x - // 3 = y - // 4 = time - var xp = LuaL.checknumber(state,2); - var yp = LuaL.checknumber(state,3); - var time = LuaL.checknumber(state,4); - - FlxTween.tween(Application.current.window,{x: xp,y:yp},time); - - return 0; - } - - - private static var tweenPosC:cpp.CallableInt> = cpp.Callable.fromStaticFunction(tweenPos); - - private function SetNumProperty(l:State){ - // 1 = self - // 2 = key - // 3 = value - // 4 = metatable - if(Lua.type(l,3)!=Lua.LUA_TNUMBER){ - LuaL.error(l,"invalid argument #3 (number expected, got " + Lua.typename(l,Lua.type(l,3)) + ")"); - return 0; - } - Reflect.setProperty(Application.current.window,Lua.tostring(l,2),Lua.tonumber(l,3)); - return 0; - } - - override function Register(l:State){ - state=l; - super.Register(l); - } - } - - class LuaGame extends LuaClass { // again, stolen from andromeda but improved a lot for better thinking interoperability (I made that up) - private static var state:State; - - public function new(){ - super(); - className= "Game"; - - properties=[ - - "health"=> { - defaultValue: PlayState.instance.health, - getter: function(l:State,data:Any):Int{ - Lua.pushnumber(l,PlayState.instance.health); - return 1; - }, - setter: function(l:State):Int{ - PlayState.instance.health = Lua.tonumber(l,3); - return 0; - }, - }, - - "accuracy"=> { - defaultValue: PlayState.instance.accuracy, - getter: function(l:State,data:Any):Int{ - Lua.pushnumber(l,PlayState.instance.accuracy); - return 1; - }, - setter: SetNumProperty - }, - "changeStage"=>{ - defaultValue:0, - getter:function(l:State,data:Any){ - Lua.pushcfunction(l,changeStageC); - return 1; - }, - setter:function(l:State){ - LuaL.error(l,"changeStage is read-only."); - return 0; - }, - } - ]; - - } - - private static function changeStage(l:StatePointer):Int{ - // 1 = self - // 2 = stage - var stageName = LuaL.checkstring(state,2); - - for (i in PlayState.Stage.toAdd) - { - PlayState.instance.remove(i); - } - - PlayState.Stage = new Stage(stageName); - - for (i in PlayState.Stage.toAdd) - { - PlayState.instance.add(i); - } - - return 0; - } - - - private static var changeStageC:cpp.CallableInt> = cpp.Callable.fromStaticFunction(changeStage); - - private function SetNumProperty(l:State){ - // 1 = self - // 2 = key - // 3 = value - // 4 = metatable - if(Lua.type(l,3)!=Lua.LUA_TNUMBER){ - LuaL.error(l,"invalid argument #3 (number expected, got " + Lua.typename(l,Lua.type(l,3)) + ")"); - return 0; - } - Reflect.setProperty(Application.current.window,Lua.tostring(l,2),Lua.tonumber(l,3)); - return 0; - } - - override function Register(l:State){ - state=l; - super.Register(l); - } - } \ No newline at end of file +class LuaSprite extends LuaClass +{ // again, stolen from andromeda but improved a lot for better thinking interoperability (I made that up) + private static var state:State; + + public var sprite:FlxSprite; + + public static var ListOfSprites:Array = []; + + public function new(connectedSprite:FlxSprite, name:String) + { + super(); + className = name; + + properties = [ + "alpha" => { + defaultValue: 1, + getter: function(l:State, data:Any):Int + { + Lua.pushnumber(l, connectedSprite.alpha); + return 1; + }, + setter: SetNumProperty + }, + + "angle" => { + defaultValue: 1, + getter: function(l:State, data:Any):Int + { + Lua.pushnumber(l, connectedSprite.angle); + return 1; + }, + setter: function(l:State):Int + { + // 1 = self + // 2 = key + // 3 = value + // 4 = metatable + if (Lua.type(l, 3) != Lua.LUA_TNUMBER) + { + LuaL.error(l, "invalid argument #3 (number expected, got " + Lua.typename(l, Lua.type(l, 3)) + ")"); + return 0; + } + + var angle = Lua.tonumber(l, 3); + connectedSprite.angle = angle; + + LuaClass.DefaultSetter(l); + return 0; + } + }, + + "x" => { + defaultValue: connectedSprite.x, + getter: function(l:State, data:Any):Int + { + Lua.pushnumber(l, connectedSprite.x); + return 1; + }, + setter: SetNumProperty + }, + + "tweenPos" => { + defaultValue: 0, + getter: function(l:State, data:Any) + { + Lua.pushcfunction(l, tweenPosC); + return 1; + }, + setter: function(l:State) + { + LuaL.error(l, "tweenPos is read-only."); + return 0; + } + }, + + "id" => { + defaultValue: name, + getter: function(l:State, data:Any):Int + { + Lua.pushstring(l, name); + return 1; + }, + setter: SetNumProperty + }, + + "tweenAlpha" => { + defaultValue: 0, + getter: function(l:State, data:Any) + { + Lua.pushcfunction(l, tweenAlphaC); + return 1; + }, + setter: function(l:State) + { + LuaL.error(l, "tweenAlpha is read-only."); + return 0; + } + }, + + "tweenAngle" => { + defaultValue: 0, + getter: function(l:State, data:Any) + { + Lua.pushcfunction(l, tweenAngleC); + return 1; + }, + setter: function(l:State) + { + LuaL.error(l, "tweenAngle is read-only."); + return 0; + } + }, + + "destroy" => { + defaultValue: 0, + getter: function(l:State, data:Any) + { + Lua.pushcfunction(l, destroyC); + return 1; + }, + setter: function(l:State) + { + LuaL.error(l, "destroy is read-only."); + return 0; + } + }, + + "y" => { + defaultValue: connectedSprite.y, + getter: function(l:State, data:Any):Int + { + Lua.pushnumber(l, connectedSprite.y); + return 1; + }, + setter: SetNumProperty + } + + ]; + + ListOfSprites.push(this); + } + + private static function findNote(time:Float, data:Int) + { + for (i in PlayState.instance.notes) + { + if (i.strumTime == time && i.noteData == data) + { + return i; + } + } + return null; + } + + private static function tweenPos(l:StatePointer):Int + { + // 1 = self + // 2 = x + // 3 = y + // 4 = time + var xp = LuaL.checknumber(state, 2); + var yp = LuaL.checknumber(state, 3); + var time = LuaL.checknumber(state, 4); + + Lua.getfield(state, 1, "id"); + var index = Lua.tostring(state, -1); + + var sprite:FlxSprite = null; + + for (i in ListOfSprites) + { + if (i.className == index) + sprite = i.sprite; + } + + if (sprite == null) + { + LuaL.error(state, "Failure to tween (couldn't find sprite " + index + ")"); + return 0; + } + + FlxTween.tween(sprite, {x: xp, y: yp}, time); + + return 0; + } + + private static function tweenAngle(l:StatePointer):Int + { + // 1 = self + // 2 = angle + // 3 = time + var nangle = LuaL.checknumber(state, 2); + var time = LuaL.checknumber(state, 3); + + Lua.getfield(state, 1, "id"); + var index = Lua.tostring(state, -1); + + var sprite:FlxSprite = null; + + for (i in ListOfSprites) + { + if (i.className == index) + sprite = i.sprite; + } + + if (sprite == null) + { + LuaL.error(state, "Failure to tween (couldn't find sprite " + index + ")"); + return 0; + } + + FlxTween.tween(sprite, {angle: nangle}, time); + + return 0; + } + + private static function tweenAlpha(l:StatePointer):Int + { + // 1 = self + // 2 = alpha + // 3 = time + var nalpha = LuaL.checknumber(state, 2); + var time = LuaL.checknumber(state, 3); + + Lua.getfield(state, 1, "id"); + var index = Lua.tostring(state, -1); + + var sprite:FlxSprite = null; + + for (i in ListOfSprites) + { + if (i.className == index) + sprite = i.sprite; + } + + if (sprite == null) + { + LuaL.error(state, "Failure to tween (couldn't find sprite " + index + ")"); + return 0; + } + + FlxTween.tween(sprite, {alpha: nalpha}, time); + + return 0; + } + + private static function destroy(l:StatePointer):Int + { + // 1 = self + + Lua.getfield(state, 1, "id"); + var index = Lua.tostring(state, -1); + + var sprite:FlxSprite = null; + + for (i in ListOfSprites) + { + if (i.className == index) + sprite = i.sprite; + } + + if (sprite == null) + { + LuaL.error(state, "Failure to tween (couldn't find sprite " + index + ")"); + return 0; + } + + PlayState.instance.remove(sprite); + sprite.destroy(); + + return 0; + } + + private static var destroyC:cpp.CallableInt> = cpp.Callable.fromStaticFunction(destroy); + private static var tweenPosC:cpp.CallableInt> = cpp.Callable.fromStaticFunction(tweenPos); + private static var tweenAngleC:cpp.CallableInt> = cpp.Callable.fromStaticFunction(tweenAngle); + private static var tweenAlphaC:cpp.CallableInt> = cpp.Callable.fromStaticFunction(tweenAlpha); + + private function SetNumProperty(l:State) + { + // 1 = self + // 2 = key + // 3 = value + // 4 = metatable + if (Lua.type(l, 3) != Lua.LUA_TNUMBER) + { + LuaL.error(l, "invalid argument #3 (number expected, got " + Lua.typename(l, Lua.type(l, 3)) + ")"); + return 0; + } + Reflect.setProperty(sprite, Lua.tostring(l, 2), Lua.tonumber(l, 3)); + return 0; + } + + override function Register(l:State) + { + state = l; + super.Register(l); + } +} + +class LuaWindow extends LuaClass +{ // again, stolen from andromeda but improved a lot for better thinking interoperability (I made that up) + private static var state:State; + + public function new() + { + super(); + className = "Window"; + + properties = [ + "x" => { + defaultValue: Application.current.window.x, + getter: function(l:State, data:Any):Int + { + Lua.pushnumber(l, Application.current.window.x); + return 1; + }, + setter: SetNumProperty + }, + + "y" => { + defaultValue: Application.current.window.y, + getter: function(l:State, data:Any):Int + { + Lua.pushnumber(l, Application.current.window.y); + return 1; + }, + setter: SetNumProperty + }, + + "width" => { + defaultValue: Application.current.window.width, + getter: function(l:State, data:Any):Int + { + Lua.pushnumber(l, Application.current.window.width); + return 1; + }, + setter: SetNumProperty + }, + + "height" => { + defaultValue: Application.current.window.height, + getter: function(l:State, data:Any):Int + { + Lua.pushnumber(l, Application.current.window.height); + return 1; + }, + setter: SetNumProperty + }, + + "tweenPos" => { + defaultValue: 0, + getter: function(l:State, data:Any) + { + Lua.pushcfunction(l, tweenPosC); + return 1; + }, + setter: function(l:State) + { + LuaL.error(l, "tweenPos is read-only."); + return 0; + }, + }, + ]; + } + + private static function tweenPos(l:StatePointer):Int + { + // 1 = self + // 2 = x + // 3 = y + // 4 = time + var xp = LuaL.checknumber(state, 2); + var yp = LuaL.checknumber(state, 3); + var time = LuaL.checknumber(state, 4); + + FlxTween.tween(Application.current.window, {x: xp, y: yp}, time); + + return 0; + } + + private static var tweenPosC:cpp.CallableInt> = cpp.Callable.fromStaticFunction(tweenPos); + + private function SetNumProperty(l:State) + { + // 1 = self + // 2 = key + // 3 = value + // 4 = metatable + if (Lua.type(l, 3) != Lua.LUA_TNUMBER) + { + LuaL.error(l, "invalid argument #3 (number expected, got " + Lua.typename(l, Lua.type(l, 3)) + ")"); + return 0; + } + Reflect.setProperty(Application.current.window, Lua.tostring(l, 2), Lua.tonumber(l, 3)); + return 0; + } + + override function Register(l:State) + { + state = l; + super.Register(l); + } +} + +class LuaGame extends LuaClass +{ // again, stolen from andromeda but improved a lot for better thinking interoperability (I made that up) + private static var state:State; + + public function new() + { + super(); + className = "Game"; + + properties = [ + + "health" => { + defaultValue: PlayState.instance.health, + getter: function(l:State, data:Any):Int + { + Lua.pushnumber(l, PlayState.instance.health); + return 1; + }, + setter: function(l:State):Int + { + PlayState.instance.health = Lua.tonumber(l, 3); + return 0; + }, + }, + + "accuracy" => { + defaultValue: PlayState.instance.accuracy, + getter: function(l:State, data:Any):Int + { + Lua.pushnumber(l, PlayState.instance.accuracy); + return 1; + }, + setter: SetNumProperty + }, + "changeStage" => { + defaultValue: 0, + getter: function(l:State, data:Any) + { + Lua.pushcfunction(l, changeStageC); + return 1; + }, + setter: function(l:State) + { + LuaL.error(l, "changeStage is read-only."); + return 0; + }, + } + ]; + } + + private static function changeStage(l:StatePointer):Int + { + // 1 = self + // 2 = stage + var stageName = LuaL.checkstring(state, 2); + + for (i in PlayState.Stage.toAdd) + { + PlayState.instance.remove(i); + } + + PlayState.Stage = new Stage(stageName); + + for (i in PlayState.Stage.toAdd) + { + PlayState.instance.add(i); + } + + return 0; + } + + private static var changeStageC:cpp.CallableInt> = cpp.Callable.fromStaticFunction(changeStage); + + private function SetNumProperty(l:State) + { + // 1 = self + // 2 = key + // 3 = value + // 4 = metatable + if (Lua.type(l, 3) != Lua.LUA_TNUMBER) + { + LuaL.error(l, "invalid argument #3 (number expected, got " + Lua.typename(l, Lua.type(l, 3)) + ")"); + return 0; + } + Reflect.setProperty(Application.current.window, Lua.tostring(l, 2), Lua.tonumber(l, 3)); + return 0; + } + + override function Register(l:State) + { + state = l; + super.Register(l); + } +} +#end diff --git a/source/Main.hx b/source/Main.hx index d3b690e4dc..c2a9a202f5 100644 --- a/source/Main.hx +++ b/source/Main.hx @@ -1,7 +1,7 @@ package; import lime.app.Application; -#if desktop +#if FEATURE_DISCORD import Discord.DiscordClient; #end import openfl.display.BlendMode; @@ -82,14 +82,14 @@ class Main extends Sprite framerate = 60; #end - #if cpp + #if FEATURE_FILESYSTEM initialState = Caching; game = new FlxGame(gameWidth, gameHeight, initialState, zoom, framerate, framerate, skipSplash, startFullscreen); #else game = new FlxGame(gameWidth, gameHeight, initialState, zoom, framerate, framerate, skipSplash, startFullscreen); #end addChild(game); - #if desktop + #if FEATURE_DISCORD DiscordClient.initialize(); Application.current.onExit.add (function (exitCode) { diff --git a/source/MainMenuState.hx b/source/MainMenuState.hx index 53c3cb0e48..d53e1d25e6 100644 --- a/source/MainMenuState.hx +++ b/source/MainMenuState.hx @@ -13,10 +13,9 @@ import flixel.tweens.FlxEase; import flixel.tweens.FlxTween; import flixel.util.FlxColor; import flixel.util.FlxTimer; -import io.newgrounds.NG; import lime.app.Application; -#if desktop +#if FEATURE_DISCORD import Discord.DiscordClient; #end @@ -51,7 +50,7 @@ class MainMenuState extends MusicBeatState { trace(0 / 2); clean(); - #if desktop + #if FEATURE_DISCORD // Updating Discord Rich Presence DiscordClient.changePresence("In the Menus", null); #end diff --git a/source/ModchartState.hx b/source/ModchartState.hx index cef30ec75a..12aaf7301d 100644 --- a/source/ModchartState.hx +++ b/source/ModchartState.hx @@ -1,6 +1,7 @@ // this file is for modchart things, this is to declutter playstate.hx // Lua +#if FEATURE_LUAMODCHART import LuaClass.LuaGame; import LuaClass.LuaWindow; import LuaClass.LuaSprite; @@ -9,7 +10,6 @@ import LuaClass.LuaReceptor; import openfl.display3D.textures.VideoTexture; import flixel.graphics.FlxGraphic; import flixel.graphics.frames.FlxAtlasFrames; -#if cpp import flixel.tweens.FlxEase; import openfl.filters.ShaderFilter; import flixel.tweens.FlxTween; @@ -259,7 +259,7 @@ class ModchartState function makeAnimatedLuaSprite(spritePath:String,names:Array,prefixes:Array,startAnim:String, id:String) { - #if sys + #if FEATURE_FILESYSTEM // pre lowercasing the song name (makeAnimatedLuaSprite) var songLowercase = StringTools.replace(PlayState.SONG.song, " ", "-").toLowerCase(); switch (songLowercase) { @@ -294,7 +294,7 @@ class ModchartState function makeLuaSprite(spritePath:String,toBeCalled:String, drawBehind:Bool) { - #if sys + #if FEATURE_FILESYSTEM // pre lowercasing the song name (makeLuaSprite) var songLowercase = StringTools.replace(PlayState.SONG.song, " ", "-").toLowerCase(); switch (songLowercase) { diff --git a/source/MusicBeatState.hx b/source/MusicBeatState.hx index 5c67e48c08..91abadba55 100644 --- a/source/MusicBeatState.hx +++ b/source/MusicBeatState.hx @@ -1,7 +1,7 @@ package; import flixel.FlxBasic; -#if desktop +#if FEATURE_DISCORD import Discord.DiscordClient; #end import flixel.util.FlxColor; diff --git a/source/Note.hx b/source/Note.hx index 09d118a998..51b644ba82 100644 --- a/source/Note.hx +++ b/source/Note.hx @@ -96,7 +96,7 @@ class Note extends FlxSprite else { this.strumTime = strumTime; - #if sys + #if FEATURE_STEPMANIA if (PlayState.isSM) { rStrumTime = strumTime; diff --git a/source/Paths.hx b/source/Paths.hx index 9bc8fd35a9..17333fcae9 100644 --- a/source/Paths.hx +++ b/source/Paths.hx @@ -131,12 +131,12 @@ class Paths inline static public function getSparrowAtlas(key:String, ?library:String, ?isCharacter:Bool = false) { var usecahce = FlxG.save.data.cacheImages; - #if !cpp + #if !FEATURE_FILESYSTEM usecahce = false; #end if (isCharacter) if (usecahce) - #if cpp + #if FEATURE_FILESYSTEM return FlxAtlasFrames.fromSparrow(imageCached(key), file('images/characters/$key.xml', library)); #else return null; @@ -146,7 +146,7 @@ class Paths return FlxAtlasFrames.fromSparrow(image(key, library), file('images/$key.xml', library)); } - #if cpp + #if FEATURE_FILESYSTEM inline static public function imageCached(key:String):FlxGraphic { var data = Caching.bitmapData.get(key); @@ -158,12 +158,12 @@ class Paths inline static public function getPackerAtlas(key:String, ?library:String, ?isCharacter:Bool = false) { var usecahce = FlxG.save.data.cacheImages; - #if !cpp + #if !FEATURE_FILESYSTEM usecahce = false; #end if (isCharacter) if (usecahce) - #if cpp + #if FEATURE_FILESYSTEM return FlxAtlasFrames.fromSpriteSheetPacker(imageCached(key), file('images/characters/$key.txt', library)); #else return null; diff --git a/source/PauseSubState.hx b/source/PauseSubState.hx index 563af69b85..b79feae3a6 100644 --- a/source/PauseSubState.hx +++ b/source/PauseSubState.hx @@ -2,7 +2,7 @@ package; import flixel.input.gamepad.FlxGamepad; import openfl.Lib; -#if desktop +#if FEATURE_LUAMODCHART import llua.Lua; #end import Controls.Control; @@ -82,7 +82,7 @@ class PauseSubState extends MusicBeatSubstate perSongOffset.scrollFactor.set(); perSongOffset.setFormat("VCR OSD Mono", 16, FlxColor.WHITE, LEFT, FlxTextBorderStyle.OUTLINE, FlxColor.BLACK); - #if cpp + #if FEATURE_FILESYSTEM add(perSongOffset); #end @@ -134,7 +134,7 @@ class PauseSubState extends MusicBeatSubstate } var songPath = 'assets/data/' + songLowercase + '/'; - #if sys + #if FEATURE_STEPMANIA if (PlayState.isSM && !PlayState.isStoryMode) songPath = PlayState.pathToSm; #end @@ -149,7 +149,7 @@ class PauseSubState extends MusicBeatSubstate changeSelection(1); } - #if cpp + #if FEATURE_FILESYSTEM else if (controls.LEFT_P || leftPcontroller) { oldOffset = PlayState.songOffset; @@ -242,7 +242,7 @@ class PauseSubState extends MusicBeatSubstate } PlayState.loadRep = false; PlayState.stageTesting = false; - #if desktop + #if FEATURE_LUAMODCHART if (PlayState.luaModchart != null) { PlayState.luaModchart.die(); diff --git a/source/PlayState.hx b/source/PlayState.hx index 405056ad98..fefcefd741 100644 --- a/source/PlayState.hx +++ b/source/PlayState.hx @@ -1,15 +1,21 @@ package; +#if FEATURE_LUAMODCHART import LuaClass.LuaCamera; import LuaClass.LuaCharacter; -import lime.media.openal.AL; import LuaClass.LuaNote; +#end +import lime.media.openal.AL; import Song.Event; import openfl.media.Sound; -#if sys -import sys.io.File; +#if FEATURE_STEPMANIA import smTools.SMFile; #end +#if FEATURE_FILESYSTEM +import sys.io.File; +import Sys; +import sys.FileSystem; +#end import openfl.ui.KeyLocation; import openfl.events.Event; import haxe.EnumTools; @@ -17,7 +23,7 @@ import openfl.ui.Keyboard; import openfl.events.KeyboardEvent; import Replay.Ana; import Replay.Analysis; -#if cpp +#if FEATURE_WEBM import webm.WebmPlayer; #end import flixel.input.keyboard.FlxKey; @@ -72,13 +78,9 @@ import lime.utils.Assets; import openfl.display.BlendMode; import openfl.display.StageQuality; import openfl.filters.ShaderFilter; -#if desktop +#if FEATURE_DISCORD import Discord.DiscordClient; #end -#if cpp -import Sys; -import sys.FileSystem; -#end using StringTools; @@ -115,7 +117,7 @@ class PlayState extends MusicBeatState var songLength:Float = 0; var kadeEngineWatermark:FlxText; - #if cpp + #if FEATURE_DISCORD // Discord RPC variables var storyDifficultyText:String = ""; var iconRPC:String = ""; @@ -126,7 +128,7 @@ class PlayState extends MusicBeatState private var vocals:FlxSound; public static var isSM:Bool = false; - #if sys + #if FEATURE_STEPMANIA public static var sm:SMFile; public static var pathToSm:String; #end @@ -339,7 +341,7 @@ class PlayState extends MusicBeatState removedVideo = false; - #if cpp + #if FEATURE_LUAMODCHART executeModchart = FileSystem.exists(Paths.lua(songLowercase + "/modchart")); if (isSM) executeModchart = FileSystem.exists(pathToSm + "/modchart.lua"); @@ -355,7 +357,7 @@ class PlayState extends MusicBeatState if (executeModchart) songMultiplier = 1; - #if desktop + #if FEATURE_DISCORD // Making difficulty text for Discord Rich Presence. storyDifficultyText = CoolUtil.difficultyFromInt(storyDifficulty); @@ -744,7 +746,7 @@ class PlayState extends MusicBeatState generateSong(SONG.song); - #if cpp + #if FEATURE_LUAMODCHART // pre lowercasing the song name (startCountdown) var songLowercase = StringTools.replace(PlayState.SONG.song, " ", "-").toLowerCase(); switch (songLowercase) @@ -763,6 +765,7 @@ class PlayState extends MusicBeatState } #end + #if FEATURE_LUAMODCHART if (executeModchart) { new LuaCamera(camGame, "camGame").Register(ModchartState.lua); @@ -773,6 +776,8 @@ class PlayState extends MusicBeatState new LuaCharacter(gf, "gf").Register(ModchartState.lua); new LuaCharacter(boyfriend, "boyfriend").Register(ModchartState.lua); } + #end + var index = 0; if (startTime != 0) @@ -1114,7 +1119,7 @@ class PlayState extends MusicBeatState var perfectMode:Bool = false; var luaWiggles:Array = []; - #if cpp + #if FEATURE_LUAMODCHART public static var luaModchart:ModchartState = null; #end @@ -1445,10 +1450,12 @@ class PlayState extends MusicBeatState if (useVideo) GlobalVideo.get().resume(); + #if FEATURE_LUAMODCHART if (executeModchart) luaModchart.executeState("songStart", [null]); - - #if desktop + #end + + #if FEATURE_DISCORD // Updating Discord Rich Presence (with Time Left) DiscordClient.changePresence(detailsText + " " @@ -1532,7 +1539,7 @@ class PlayState extends MusicBeatState curSong = songData.song; - #if sys + #if FEATURE_STEPMANIA if (SONG.needsVoices && !isSM) vocals = new FlxSound().loadEmbedded(Paths.voices(PlayState.SONG.song)); else @@ -1550,7 +1557,7 @@ class PlayState extends MusicBeatState if (!paused) { - #if sys + #if FEATURE_STEPMANIA if (!isStoryMode && isSM) { trace("Loading " + pathToSm + "/" + sm.header.MUSIC); @@ -1623,7 +1630,7 @@ class PlayState extends MusicBeatState var playerCounter:Int = 0; // Per song offset check - #if cpp + #if FEATURE_FILESYSTEM // pre lowercasing the song name (generateSong) var songLowercase = StringTools.replace(PlayState.SONG.song, " ", "-").toLowerCase(); switch (songLowercase) @@ -1638,7 +1645,7 @@ class PlayState extends MusicBeatState var songPath = 'assets/data/' + songLowercase + '/'; - #if sys + #if FEATURE_STEPMANIA if (isSM && !isStoryMode) songPath = pathToSm; #end @@ -1889,7 +1896,7 @@ class PlayState extends MusicBeatState vocals.pause(); } - #if desktop + #if FEATURE_DISCORD DiscordClient.changePresence("PAUSED on " + SONG.song + " (" @@ -1923,7 +1930,7 @@ class PlayState extends MusicBeatState startTimer.active = true; paused = false; - #if desktop + #if FEATURE_DISCORD if (startTimer.finished) { DiscordClient.changePresence(detailsText @@ -1963,12 +1970,15 @@ class PlayState extends MusicBeatState @:privateAccess { + #if desktop + // The __backend.handle attribute is only available on native. lime.media.openal.AL.sourcef(FlxG.sound.music._channel.__source.__backend.handle, lime.media.openal.AL.PITCH, songMultiplier); if (vocals.playing) lime.media.openal.AL.sourcef(vocals._channel.__source.__backend.handle, lime.media.openal.AL.PITCH, songMultiplier); + #end } - #if desktop + #if FEATURE_DISCORD DiscordClient.changePresence(detailsText + " " + SONG.song @@ -2019,18 +2029,22 @@ class PlayState extends MusicBeatState var dunceNote:Note = unspawnNotes[0]; notes.add(dunceNote); + #if FEATURE_LUAMODCHART if (executeModchart) { new LuaNote(dunceNote, currentLuaIndex); dunceNote.luaID = currentLuaIndex; } + #end if (executeModchart) { + #if FEATURE_LUAMODCHART if (!dunceNote.isSustainNote) dunceNote.cameras = [camNotes]; else dunceNote.cameras = [camSustains]; + #end } else { @@ -2158,7 +2172,7 @@ class PlayState extends MusicBeatState } } - #if cpp + #if FEATURE_LUAMODCHART if (executeModchart && luaModchart != null && songStarted) { luaModchart.setVar('songPos', Conductor.songPosition); @@ -2276,10 +2290,8 @@ class PlayState extends MusicBeatState { GlobalVideo.get().stop(); remove(videoSprite); - #if sys FlxG.stage.window.onFocusOut.remove(focusOut); FlxG.stage.window.onFocusIn.remove(focusIn); - #end removedVideo = true; } cannotDie = true; @@ -2289,7 +2301,7 @@ class PlayState extends MusicBeatState PlayState.stageTesting = false; FlxG.stage.removeEventListener(KeyboardEvent.KEY_DOWN, handleInput); FlxG.stage.removeEventListener(KeyboardEvent.KEY_UP, releaseInput); - #if cpp + #if FEATURE_LUAMODCHART if (luaModchart != null) { luaModchart.die(); @@ -2306,10 +2318,8 @@ class PlayState extends MusicBeatState { GlobalVideo.get().stop(); remove(videoSprite); - #if sys FlxG.stage.window.onFocusOut.remove(focusOut); FlxG.stage.window.onFocusIn.remove(focusIn); - #end removedVideo = true; } cannotDie = true; @@ -2319,7 +2329,7 @@ class PlayState extends MusicBeatState PlayState.stageTesting = false; FlxG.stage.removeEventListener(KeyboardEvent.KEY_DOWN, handleInput); FlxG.stage.removeEventListener(KeyboardEvent.KEY_UP, releaseInput); - #if cpp + #if FEATURE_LUAMODCHART if (luaModchart != null) { luaModchart.die(); @@ -2374,7 +2384,7 @@ class PlayState extends MusicBeatState PlayState.stageTesting = false; FlxG.stage.removeEventListener(KeyboardEvent.KEY_DOWN, handleInput); FlxG.stage.removeEventListener(KeyboardEvent.KEY_UP, releaseInput); - #if cpp + #if FEATURE_LUAMODCHART if (luaModchart != null) { luaModchart.die(); @@ -2418,7 +2428,7 @@ class PlayState extends MusicBeatState clean(); FlxG.stage.removeEventListener(KeyboardEvent.KEY_DOWN, handleInput); FlxG.stage.removeEventListener(KeyboardEvent.KEY_UP, releaseInput); - #if cpp + #if FEATURE_LUAMODCHART if (luaModchart != null) { luaModchart.die(); @@ -2434,7 +2444,7 @@ class PlayState extends MusicBeatState PlayState.stageTesting = false; FlxG.stage.removeEventListener(KeyboardEvent.KEY_DOWN, handleInput); FlxG.stage.removeEventListener(KeyboardEvent.KEY_UP, releaseInput); - #if cpp + #if FEATURE_LUAMODCHART if (luaModchart != null) { luaModchart.die(); @@ -2649,7 +2659,7 @@ class PlayState extends MusicBeatState } } - #if cpp + #if FEATURE_LUAMODCHART if (luaModchart != null) luaModchart.setVar("mustHit", currentSection.mustHitSection); #end @@ -2658,7 +2668,7 @@ class PlayState extends MusicBeatState { var offsetX = 0; var offsetY = 0; - #if cpp + #if FEATURE_LUAMODCHART if (luaModchart != null) { offsetX = luaModchart.getVar("followXOffset", "float"); @@ -2666,7 +2676,7 @@ class PlayState extends MusicBeatState } #end camFollow.setPosition(dad.getMidpoint().x + 150 + offsetX, dad.getMidpoint().y - 100 + offsetY); - #if cpp + #if FEATURE_LUAMODCHART if (luaModchart != null) luaModchart.executeState('playerTwoTurn', []); #end @@ -2686,7 +2696,7 @@ class PlayState extends MusicBeatState { var offsetX = 0; var offsetY = 0; - #if cpp + #if FEATURE_LUAMODCHART if (luaModchart != null) { offsetX = luaModchart.getVar("followXOffset", "float"); @@ -2695,7 +2705,7 @@ class PlayState extends MusicBeatState #end camFollow.setPosition(boyfriend.getMidpoint().x - 100 + offsetX, boyfriend.getMidpoint().y - 100 + offsetY); - #if cpp + #if FEATURE_LUAMODCHART if (luaModchart != null) luaModchart.executeState('playerOneTurn', []); #end @@ -2792,7 +2802,7 @@ class PlayState extends MusicBeatState openSubState(new GameOverSubstate(boyfriend.getScreenPosition().x, boyfriend.getScreenPosition().y)); } - #if desktop + #if FEATURE_DISCORD // Game Over doesn't get his own variable because it's only used here DiscordClient.changePresence("GAME OVER -- " + SONG.song @@ -2835,7 +2845,7 @@ class PlayState extends MusicBeatState openSubState(new GameOverSubstate(boyfriend.getScreenPosition().x, boyfriend.getScreenPosition().y)); } - #if desktop + #if FEATURE_DISCORD // Game Over doesn't get his own variable because it's only used here DiscordClient.changePresence("GAME OVER -- " + SONG.song @@ -2998,7 +3008,7 @@ class PlayState extends MusicBeatState }); } - #if cpp + #if FEATURE_LUAMODCHART if (luaModchart != null) luaModchart.executeState('playerTwoSing', [Math.abs(daNote.noteData), Conductor.songPosition]); #end @@ -3032,7 +3042,7 @@ class PlayState extends MusicBeatState }); } - #if cpp + #if FEATURE_LUAMODCHART if (luaModchart != null) luaModchart.executeState('playerTwoSing', [Math.abs(daNote.noteData), Conductor.songPosition]); #end @@ -3309,7 +3319,7 @@ class PlayState extends MusicBeatState if (FlxG.save.data.fpsCap > 290) (cast(Lib.current.getChildAt(0), Main)).setFPSCap(290); - #if cpp + #if FEATURE_LUAMODCHART if (luaModchart != null) { luaModchart.die(); @@ -3408,7 +3418,7 @@ class PlayState extends MusicBeatState clean(); } - #if cpp + #if FEATURE_LUAMODCHART if (luaModchart != null) { luaModchart.die(); @@ -3846,7 +3856,7 @@ class PlayState extends MusicBeatState var pressArray:Array = [controls.LEFT_P, controls.DOWN_P, controls.UP_P, controls.RIGHT_P]; var releaseArray:Array = [controls.LEFT_R, controls.DOWN_R, controls.UP_R, controls.RIGHT_R]; var keynameArray:Array = ['left', 'down', 'up', 'right']; - #if cpp + #if FEATURE_LUAMODCHART if (luaModchart != null) { for (i in 0...pressArray.length) @@ -4136,7 +4146,7 @@ class PlayState extends MusicBeatState public function backgroundVideo(source:String) // for background videos { - #if cpp + #if FEATURE_WEBM useVideo = true; FlxG.stage.window.onFocusOut.add(focusOut); @@ -4256,7 +4266,7 @@ class PlayState extends MusicBeatState // Hole switch statement replaced with a single line :) boyfriend.playAnim('sing' + dataSuffix[direction] + 'miss', true); - #if cpp + #if FEATURE_LUAMODCHART if (luaModchart != null) luaModchart.executeState('playerOneMiss', [direction, Conductor.songPosition]); #end @@ -4408,7 +4418,7 @@ class PlayState extends MusicBeatState boyfriend.playAnim('sing' + dataSuffix[note.noteData] + altAnim, true); - #if cpp + #if FEATURE_LUAMODCHART if (luaModchart != null) luaModchart.executeState('playerOneSing', [note.noteData, Conductor.songPosition]); #end @@ -4471,7 +4481,7 @@ class PlayState extends MusicBeatState resyncVocals(); } - #if cpp + #if FEATURE_LUAMODCHART if (executeModchart && luaModchart != null) { luaModchart.setVar('curStep', curStep); @@ -4489,7 +4499,7 @@ class PlayState extends MusicBeatState notes.sort(FlxSort.byY, (PlayStateChangeables.useDownscroll ? FlxSort.ASCENDING : FlxSort.DESCENDING)); } - #if cpp + #if FEATURE_LUAMODCHART if (executeModchart && luaModchart != null) { luaModchart.executeState('beatHit', [curBeat]); diff --git a/source/Replay.hx b/source/Replay.hx index 5d88f329a5..d9819e4d83 100644 --- a/source/Replay.hx +++ b/source/Replay.hx @@ -1,4 +1,4 @@ -#if sys +#if FEATURE_FILESYSTEM import sys.io.File; #end import Controls.Control; @@ -90,7 +90,7 @@ class Replay public function SaveReplay(notearray:Array, judge:Array, ana:Analysis) { - #if sys + #if FEATURE_STEPMANIA var chartPath = PlayState.isSM ? PlayState.pathToSm + "/converted.json" : ""; #else var chartPath = ""; @@ -115,7 +115,7 @@ class Replay var time = Date.now().getTime(); - #if sys + #if FEATURE_FILESYSTEM File.saveContent("assets/replays/replay-" + PlayState.SONG.song + "-time" + time + ".kadeReplay", data); path = "replay-" + PlayState.SONG.song + "-time" + time + ".kadeReplay"; // for score screen shit @@ -128,7 +128,7 @@ class Replay public function LoadFromJSON() { - #if sys + #if FEATURE_FILESYSTEM trace('loading ' + Sys.getCwd() + 'assets/replays/' + path + ' replay...'); try { diff --git a/source/ResultsScreen.hx b/source/ResultsScreen.hx index d286eb2ec1..116056ffea 100644 --- a/source/ResultsScreen.hx +++ b/source/ResultsScreen.hx @@ -1,7 +1,9 @@ package; import haxe.Exception; -#if sys +#if FEATURE_STEPMANIA import smTools.SMFile; +#end +#if FEATURE_FILESYSTEM import sys.FileSystem; import sys.io.File; #end @@ -23,7 +25,6 @@ import flixel.text.FlxText; import flixel.tweens.FlxEase; import flixel.tweens.FlxTween; import flixel.util.FlxColor; -import io.newgrounds.NG; import lime.app.Application; import lime.utils.Assets; import flixel.math.FlxMath; diff --git a/source/StoryMenuState.hx b/source/StoryMenuState.hx index 1ee5999de5..0f4c7225e4 100644 --- a/source/StoryMenuState.hx +++ b/source/StoryMenuState.hx @@ -14,7 +14,7 @@ import flixel.util.FlxColor; import flixel.util.FlxTimer; import lime.net.curl.CURLCode; -#if desktop +#if FEATURE_DISCORD import Discord.DiscordClient; #end @@ -90,7 +90,7 @@ class StoryMenuState extends MusicBeatState { weekUnlocked = unlockWeeks(); - #if desktop + #if FEATURE_DISCORD // Updating Discord Rich Presence DiscordClient.changePresence("In the Story Mode Menu", null); #end diff --git a/source/TitleState.hx b/source/TitleState.hx index de9512f876..f8a9d2ec2f 100644 --- a/source/TitleState.hx +++ b/source/TitleState.hx @@ -1,6 +1,6 @@ package; -#if sys +#if FEATURE_STEPMANIA import smTools.SMFile; #end import flixel.FlxG; @@ -26,14 +26,10 @@ import flixel.util.FlxTimer; import lime.app.Application; import openfl.Assets; -#if desktop +#if FEATURE_DISCORD import Discord.DiscordClient; #end -#if cpp -import sys.thread.Thread; -#end - using StringTools; class TitleState extends MusicBeatState @@ -56,7 +52,7 @@ class TitleState extends MusicBeatState polymod.Polymod.init({modRoot: "mods", dirs: ['introMod']}); #end - #if sys + #if FEATURE_FILESYSTEM if (!sys.FileSystem.exists(Sys.getCwd() + "/assets/replays")) sys.FileSystem.createDirectory(Sys.getCwd() + "/assets/replays"); #end diff --git a/source/Waveform.hx b/source/Waveform.hx index 816dd0d0ed..e2bbcbbebf 100644 --- a/source/Waveform.hx +++ b/source/Waveform.hx @@ -48,9 +48,6 @@ class Waveform extends FlxSprite public function drawWaveform() { - var currentTime:Float = Sys.time(); - var finishedTime:Float; - var index:Int = 0; var drawIndex:Int = 0; @@ -59,7 +56,6 @@ class Waveform extends FlxSprite var min:Float = 0; var max:Float = 0; - Sys.println("Interating over " + totalSamples); for(index in 0...Math.round(totalSamples)) { @@ -94,9 +90,5 @@ class Waveform extends FlxSprite min = 0; max = 0; } - - finishedTime = Sys.time(); - - Sys.println("Took " + (finishedTime - currentTime) + " seconds."); } } diff --git a/source/WaveformTestState.hx b/source/WaveformTestState.hx index 69d48b8d01..e3d100b3f4 100644 --- a/source/WaveformTestState.hx +++ b/source/WaveformTestState.hx @@ -10,7 +10,6 @@ import lime.media.AudioBuffer; import lime.media.vorbis.VorbisFile; import openfl.geom.Rectangle; import openfl.media.Sound; -import sys.thread.Thread; class WaveformTestState extends FlxState { @@ -23,7 +22,9 @@ class WaveformTestState extends FlxState // fuckin stupid ass bitch ass fucking waveform if (PlayState.isSM) { + #if FEATURE_FILESYSTEM waveform = new Waveform(0, 0, PlayState.pathToSm + "/" + PlayState.sm.header.MUSIC, 720); + #end } else { diff --git a/source/WebmHandler.hx b/source/WebmHandler.hx index 77b9391b3b..d23fad7b41 100644 --- a/source/WebmHandler.hx +++ b/source/WebmHandler.hx @@ -2,13 +2,13 @@ package; import flixel.FlxG; import openfl.display.Sprite; -#if desktop +#if FEATURE_WEBM import webm.*; #end class WebmHandler { - #if desktop + #if FEATURE_WEBM public var webm:WebmPlayer; public var vidPath:String = ""; public var io:WebmIo; diff --git a/source/smTools/SMFile.hx b/source/smTools/SMFile.hx index c653c7d3d9..96f176b6c7 100644 --- a/source/smTools/SMFile.hx +++ b/source/smTools/SMFile.hx @@ -1,4 +1,4 @@ -#if sys +#if FEATURE_STEPMANIA package smTools; import sys.io.File; diff --git a/source/smTools/SMHeader.hx b/source/smTools/SMHeader.hx index ed39e99475..e58c6ff27a 100644 --- a/source/smTools/SMHeader.hx +++ b/source/smTools/SMHeader.hx @@ -1,4 +1,4 @@ -#if sys +#if FEATURE_STEPMANIA package smTools; class SMHeader diff --git a/source/smTools/SMMeasure.hx b/source/smTools/SMMeasure.hx index 4519cbd876..3a0a2a115d 100644 --- a/source/smTools/SMMeasure.hx +++ b/source/smTools/SMMeasure.hx @@ -1,4 +1,4 @@ -#if sys +#if FEATURE_STEPMANIA package smTools; class SMMeasure diff --git a/source/smTools/SMNote.hx b/source/smTools/SMNote.hx index 0a97f637f5..687a34fe5e 100644 --- a/source/smTools/SMNote.hx +++ b/source/smTools/SMNote.hx @@ -1,4 +1,4 @@ -#if sys +#if FEATURE_STEPMANIA package smTools; class SMNote