Skip to content

Commit

Permalink
cool lua stuff, small fixes and some removed leftovers
Browse files Browse the repository at this point in the history
  • Loading branch information
Ryiuu04 committed Sep 6, 2024
1 parent 81f7319 commit d53ecd4
Show file tree
Hide file tree
Showing 22 changed files with 420 additions and 318 deletions.
18 changes: 3 additions & 15 deletions source/Main.hx
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ class Main extends Sprite
// create() in there, which gets called when it's added to stage
// which is why it needs to be added before addChild(game) here
@:privateAccess
game._customSoundTray = options.FunkinSoundTray;
game._customSoundTray = objects.FunkinSoundTray;

addChild(game);

Expand All @@ -115,7 +115,7 @@ class Main extends Sprite
addChild(fpsCounter);
Lib.current.stage.align = "tl";
Lib.current.stage.scaleMode = StageScaleMode.NO_SCALE;
var daBool:Bool = FlxG.save.data.fps || FlxG.save.data.showFPS;
var daBool:Bool = FlxG.save.data.showFPS;
toggleFPS(daBool);
#end

Expand All @@ -139,7 +139,7 @@ class Main extends Sprite

static function resetSpriteCache(sprite:Sprite):Void {
@:privateAccess {
sprite.__cacheBitmap = null;
sprite.__cacheBitmap = null;
sprite.__cacheBitmapData = null;
}
}
Expand Down Expand Up @@ -174,18 +174,6 @@ class Main extends Sprite
fpsCounter.textColor = color;
}

public function setFPSCap(cap:Float)
{
openfl.Lib.current.stage.frameRate = cap;

curFPS = Std.int(cap);
}

public function getFPSCap():Float
{
return openfl.Lib.current.stage.frameRate;
}

public function getFPS():Float
{
return fpsCounter.currentFPS;
Expand Down
57 changes: 24 additions & 33 deletions source/backend/ClientPrefs.hx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import states.TitleState;
public var lowQuality:Bool = false;
public var shaders:Bool = true;
public var framerate:Int = 120;
public var fpsCap:Int = 120;
public var camZooms:Bool = true;
public var hideHud:Bool = false;
public var noteOffset:Int = 0;
Expand Down Expand Up @@ -74,7 +73,7 @@ import states.TitleState;
public var useGL:Bool = false;
public var poltatoPC:Bool = false;
public var controllerMode:Bool = false;
public var psychUI:Bool = false;
public var psychUI:Bool = true;//the option no longer exists, but I'll leave it here just to avoid breaking some scripts
public var noteSplashes:Bool = true;
public var fpsRain:Bool = false;
public var cursing:Bool = true;
Expand All @@ -84,7 +83,8 @@ import states.TitleState;
public var showNextSection:Bool = true;

public var botplay:Bool = false;
public var songPosition:Bool = false;
public var accType:String = 'Simple';
//public var songPosition:Bool = false;
}

class ClientPrefs {
Expand Down Expand Up @@ -140,11 +140,8 @@ class ClientPrefs {
}

public static function saveSettings() {
FlxG.save.data.fps = data.showFPS;
FlxG.save.data.showFPS = data.showFPS;
FlxG.save.data.noteSplash = data.noteSplashes;
data.fpsCap = data.framerate;
FlxG.save.data.fpsCap = data.framerate;
FlxG.save.data.ghost = data.ghostTapping;

for (key in Reflect.fields(data)){
Expand All @@ -161,41 +158,35 @@ class ClientPrefs {
}

public static function loadPrefs() {
if(FlxG.save.data.fpsCap == null && FlxG.save.data.framerate == null) {
var framerate = 120;
FlxG.save.data.framerate = framerate;
FlxG.save.data.fpsCap = framerate;
FlxG.save.flush();
if(FlxG.save.data.psychUI != null || FlxG.save.data.psychUI == false){
data.psychUI == true;//forcing it to true so it doesn't break scripts
FlxG.save.data.psychUI == true;//forcing it to true so it doesn't break scripts
}

// values I couldn't add to the array since they have different save data names and var names
if(FlxG.save.data.fps != null) {
data.showFPS = FlxG.save.data.fps;
if(Main.fpsCounter != null) {
Main.fpsCounter.visible = data.showFPS;
}
if(FlxG.save.data.framerate == null) {
final refreshRate:Int = FlxG.stage.application.window.displayMode.refreshRate;
data.framerate = Std.int(FlxMath.bound(refreshRate, 60, 240));
} else data.framerate = FlxG.save.data.framerate;

if(Main.fpsCounter != null) {
Main.fpsCounter.visible = data.showFPS;
}

if(FlxG.save.data.noteSplash != null) {
data.noteSplashes = FlxG.save.data.noteSplash;
}

if(FlxG.save.data.fpsCap != null) {
var framerate = data.framerate;
framerate = FlxG.save.data.framerate;

openfl.Lib.current.stage.frameRate = framerate;
Main.curFPS = framerate;

FlxG.save.data.fpsCap = framerate;
if(framerate > FlxG.drawFramerate) {
FlxG.updateFramerate = framerate;
FlxG.drawFramerate = framerate;
} else {
FlxG.drawFramerate = framerate;
FlxG.updateFramerate = framerate;
}
if(data.framerate > FlxG.drawFramerate)
{
FlxG.updateFramerate = data.framerate;
FlxG.drawFramerate = data.framerate;
}

else
{
FlxG.drawFramerate = data.framerate;
FlxG.updateFramerate = data.framerate;
}

if(FlxG.save.data.ghost != null) {
data.ghostTapping = FlxG.save.data.ghost;
}
Expand Down
42 changes: 22 additions & 20 deletions source/backend/EtternaFunctions.hx
Original file line number Diff line number Diff line change
Expand Up @@ -62,25 +62,27 @@ class EtternaFunctions
return (getNotes() * 350);
}

public static function wife3(maxms:Float, ts:Float)
{
var max_points = 1.0;
var miss_weight = -5.5;
var ridic= 5 * ts;
var max_boo_weight = 180 * ts;
var ts_pow = 0.75;
var zero = 65 * (Math.pow(ts,ts_pow));
var power = 2.5;
var dev = 22.7 * (Math.pow(ts,ts_pow));

if (maxms <= ridic) // anything below this (judge scaled) threshold is counted as full pts
return max_points;
else if (maxms <= zero) // ma/pa region, exponential
return max_points * erf((zero - maxms) / dev);
else if (maxms <= max_boo_weight)// cb region, linear
return (maxms - zero) * miss_weight / (max_boo_weight - zero);
else
return miss_weight;
}
public static function wife3(maxms:Float, ts:Float)//code updated to kade 1.8 version, 𝘪 𝘥𝘰𝘯'𝘵 𝘳𝘦𝘢𝘭𝘭𝘺 𝘬𝘯𝘰𝘸 𝘪𝘧 𝘵𝘩𝘪𝘴 𝘸𝘪𝘭𝘭 𝘤𝘩𝘢𝘯𝘨𝘦 𝘢𝘯𝘺𝘵𝘩𝘪𝘯𝘨 𝘵𝘣𝘩
{
var playbackRate = PlayState.instance.playbackRate;

var max_points = 1.0;
var miss_weight = -5.5;
var ridic = 5 * ts;
var max_boo_weight = 166 * (ts / playbackRate);
var ts_pow = 0.75;
var zero = 65 * (Math.pow(ts, ts_pow));
var power = 2.5;
var dev = 22.7 * (Math.pow(ts, ts_pow));

if (maxms <= ridic) // anything below this (judge scaled) threshold is counted as full pts
return max_points;
else if (maxms <= zero) // ma/pa region, exponential
return max_points * erf((zero - maxms) / dev);
else if (maxms <= max_boo_weight) // cb region, linear
return (maxms - zero) * miss_weight / (max_boo_weight - zero);
else
return miss_weight;
}

}
10 changes: 0 additions & 10 deletions source/backend/KadeEngineData.hx
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@ class KadeEngineData
if (FlxG.save.data.songPosition == null)
FlxG.save.data.songPosition = false;

if (FlxG.save.data.fps == null)
FlxG.save.data.fps = false;

if (FlxG.save.data.changedHit == null)
{
FlxG.save.data.changedHitX = -1;
Expand All @@ -37,11 +34,6 @@ class KadeEngineData

if (FlxG.save.data.fpsRain == null)
FlxG.save.data.fpsRain = false;

/*if (FlxG.save.data.fpsCap == null)
FlxG.save.data.fpsCap = 120;
if (FlxG.save.data.fpsCap > 285 || FlxG.save.data.fpsCap < 60)
FlxG.save.data.fpsCap = 120; // baby proof so you can't hard lock ur copy of kade engine*/

if (FlxG.save.data.scrollSpeed == null)
FlxG.save.data.scrollSpeed = 1;
Expand Down Expand Up @@ -90,7 +82,5 @@ class KadeEngineData
options.KeyBinds.keyCheck();

Main.watermarks = FlxG.save.data.watermark;

//(cast (Lib.current.getChildAt(0), Main)).setFPSCap(FlxG.save.data.fpsCap);
}
}
5 changes: 0 additions & 5 deletions source/backend/MusicBeatState.hx
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@ class MusicBeatState extends FlxUIState

var skip:Bool = FlxTransitionableState.skipNextTransOut;

(cast (Lib.current.getChildAt(0), Main)).setFPSCap(FlxG.save.data.fpsCap);

if (transIn != null)
trace('reg ' + transIn.region);

Expand Down Expand Up @@ -103,9 +101,6 @@ class MusicBeatState extends FlxUIState
skippedFrames++;
}

//if ((cast (Lib.current.getChildAt(0), Main)).getFPSCap() != FlxG.save.data.fpsCap && FlxG.save.data.fpsCap <= 290)
// (cast (Lib.current.getChildAt(0), Main)).setFPSCap(FlxG.save.data.fpsCap);

super.update(elapsed);
}

Expand Down
5 changes: 3 additions & 2 deletions source/backend/Paths.hx
Original file line number Diff line number Diff line change
Expand Up @@ -206,9 +206,10 @@ class Paths
return sound(key + FlxG.random.int(min, max), library);
}

inline static public function music(key:String, ?library:String)
inline static public function music(key:String, ?library:String):Sound
{
return getPath('music/$key.$SOUND_EXT', MUSIC, library);
var file:Sound = returnSound('music', key, library);
return file;
}

inline static public function video(key:String, ?library:String)
Expand Down
6 changes: 3 additions & 3 deletions source/backend/Ratings.hx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import flixel.FlxG;

class Ratings
{
public static function GenerateLetterRank(accuracy:Float) // generate a letter ranking
/*public static function GenerateLetterRank(accuracy:Float) // generate a letter ranking
{
var ranking:String = "N/A";
Expand Down Expand Up @@ -88,9 +88,9 @@ class Ratings
ranking = "N/A";
return ranking;
}
}*/

public static function GenerateLetterRankPsych(accuracy:Float) // bcuz yes
public static function GenerateLetterRank(accuracy:Float) // bcuz yes
{
var ranking:String = "N/A";

Expand Down
66 changes: 38 additions & 28 deletions source/luafiles/ModchartState.hx
Original file line number Diff line number Diff line change
Expand Up @@ -972,7 +972,6 @@ class ModchartState

set("difficulty", PlayState.storyDifficulty);
set("curBpm", Conductor.bpm);
set("fpsCap", FlxG.save.data.fpsCap);
set("downscroll", FlxG.save.data.downscroll);
set("flashing", FlxG.save.data.flashing);
set("distractions", FlxG.save.data.distractions);
Expand Down Expand Up @@ -1348,31 +1347,6 @@ class ModchartState
}
return false;
});

// custom substate
Lua_helper.add_callback(lua, "openCustomSubstate", function(name:String, pauseGame:Bool = false) {
if(pauseGame)
{
PlayState.instance.persistentUpdate = false;
PlayState.instance.persistentDraw = true;
PlayState.instance.paused = true;
if(FlxG.sound.music != null) {
FlxG.sound.music.pause();
PlayState.instance.vocals.pause();
}
}
PlayState.instance.openSubState(new CustomSubstate(name));
});

Lua_helper.add_callback(lua, "closeCustomSubstate", function() {
if(CustomSubstate.instance != null)
{
PlayState.instance.closeSubState();
CustomSubstate.instance = null;
return true;
}
return false;
});

Lua_helper.add_callback(lua, "toggleCamFilter", function(bool:Bool, camera:String = '') {
LuaUtils.cameraFromString(camera).filtersEnabled = bool;
Expand Down Expand Up @@ -1597,6 +1571,15 @@ class ModchartState

return runningScripts;
});

Lua_helper.add_callback(lua, "getRunningHScripts", function(){
var runningScripts:Array<String> = [];
for (idx in 0...PlayState.instance.hscriptArray.length)
runningScripts.push(PlayState.instance.hscriptArray[idx].scriptFile);


return runningScripts;
});

Lua_helper.add_callback(lua, "callOnLuas", function(?funcName:String, ?args:Array<Dynamic>, ignoreStops=false, ignoreSelf=true, ?exclusions:Array<String>){
if(funcName==null){
Expand All @@ -1615,6 +1598,20 @@ class ModchartState
if(ignoreSelf && !exclusions.contains(daScriptName))exclusions.push(daScriptName);
PlayState.instance.callOnLuas(funcName, args, ignoreStops, exclusions);
});

Lua_helper.add_callback(lua, "callOnHScript", function(funcName:String, ?args:Array<Dynamic> = null, ?ignoreStops=false, ?ignoreSelf:Bool = true, ?excludeScripts:Array<String> = null, ?excludeValues:Array<Dynamic> = null) {
if(excludeScripts == null) excludeScripts = [];
if(ignoreSelf && !excludeScripts.contains(scriptName)) excludeScripts.push(scriptName);
PlayState.instance.callOnHScript(funcName, args, ignoreStops, excludeScripts, excludeValues);
return true;
});

Lua_helper.add_callback(lua, "callOnScripts", function(funcName:String, ?args:Array<Dynamic> = null, ?ignoreStops=false, ?ignoreSelf:Bool = true, ?excludeScripts:Array<String> = null, ?excludeValues:Array<Dynamic> = null) {
if(excludeScripts == null) excludeScripts = [];
if(ignoreSelf && !excludeScripts.contains(scriptName)) excludeScripts.push(scriptName);
PlayState.instance.callOnScripts(funcName, args, ignoreStops, excludeScripts, excludeValues);
return true;
});

Lua_helper.add_callback(lua, "callScript", function(?luaFile:String, ?funcName:String, ?args:Array<Dynamic>){
if(luaFile==null){
Expand Down Expand Up @@ -1774,7 +1771,19 @@ class ModchartState
if(ignoreSelf && !exclusions.contains(scriptName)) exclusions.push(scriptName);
PlayState.instance.setOnLuas(varName, arg, exclusions);
});


Lua_helper.add_callback(lua, "setOnHScript", function(varName:String, arg:Dynamic, ?ignoreSelf:Bool = false, ?exclusions:Array<String> = null) {
if(exclusions == null) exclusions = [];
if(ignoreSelf && !exclusions.contains(scriptName)) exclusions.push(scriptName);
PlayState.instance.setOnHScript(varName, arg, exclusions);
});

Lua_helper.add_callback(lua, "setOnScripts", function(varName:String, arg:Dynamic, ?ignoreSelf:Bool = false, ?exclusions:Array<String> = null) { //why not.
if(exclusions == null) exclusions = [];
if(ignoreSelf && !exclusions.contains(scriptName)) exclusions.push(scriptName);
PlayState.instance.setOnScripts(varName, arg, exclusions);
});

Lua_helper.add_callback(lua,"animationSwap", function(char:String, anim1:String, anim2:String) {
var shit = LuaUtils.getObjectDirectly(char);

Expand Down Expand Up @@ -2980,7 +2989,7 @@ class ModchartState
#end
});

Lua_helper.add_callback(lua, "makeVideoSprite", function(tag:String, videoFile:String, ?x:Float, ?y:Float, ?camera:String, ?shouldLoop:Bool, ?muted:Bool) {
Lua_helper.add_callback(lua, "makeVideoSprite", function(tag:String, videoFile:String, ?x:Float, ?y:Float, ?camera:String="camGame", ?shouldLoop:Bool=false, ?muted:Bool=true) {
// I hate you FlxVideoSprite....
#if VIDEOS_ALLOWED
tag = tag.replace('.', '');
Expand Down Expand Up @@ -3834,6 +3843,7 @@ class ModchartState
#if desktop DiscordClient.addLuaCallbacks(lua); #end
#if hscript HScript.implement(this); #end
#if flxanimate FlxAnimateFunctions.implement(this); #end
SpriteGroupFunctions.implement(this);
ReflectionFunctions.implement(this);
TweenFunctions.implement(this);
TextFunctions.implement(this);
Expand Down
Loading

0 comments on commit d53ecd4

Please sign in to comment.