From 072a6d34fbb0309c141a8c7b1e8cb9ee1fecdfe8 Mon Sep 17 00:00:00 2001 From: ShadowMario <44785097+ShadowMario@users.noreply.github.com> Date: Sun, 29 Sep 2024 15:27:12 -0300 Subject: [PATCH] minor tweak on achievements and lua death counter --- source/backend/Achievements.hx | 23 +++++++++++++++-------- source/psychlua/FunkinLua.hx | 1 + 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/source/backend/Achievements.hx b/source/backend/Achievements.hx index 0279f35d6e2..aac0c787a25 100644 --- a/source/backend/Achievements.hx +++ b/source/backend/Achievements.hx @@ -22,6 +22,13 @@ typedef Achievement = @:optional var ID:Int; } +enum abstract AchievementOp(String) +{ + var GET = 'get'; + var SET = 'set'; + var ADD = 'add'; +} + class Achievements { public static function init() { @@ -87,16 +94,15 @@ class Achievements { } public static function getScore(name:String):Float - return _scoreFunc(name, 0); + return _scoreFunc(name, GET); public static function setScore(name:String, value:Float, saveIfNotUnlocked:Bool = true):Float - return _scoreFunc(name, 1, value, saveIfNotUnlocked); + return _scoreFunc(name, SET, value, saveIfNotUnlocked); public static function addScore(name:String, value:Float = 1, saveIfNotUnlocked:Bool = true):Float - return _scoreFunc(name, 2, value, saveIfNotUnlocked); + return _scoreFunc(name, ADD, value, saveIfNotUnlocked); - //mode 0 = get, 1 = set, 2 = add - static function _scoreFunc(name:String, mode:Int = 0, addOrSet:Float = 1, saveIfNotUnlocked:Bool = true):Float + static function _scoreFunc(name:String, mode:AchievementOp, addOrSet:Float = 1, saveIfNotUnlocked:Bool = true):Float { if(!variables.exists(name)) variables.set(name, 0); @@ -111,8 +117,9 @@ class Achievements { var val = addOrSet; switch(mode) { - case 0: return variables.get(name); //get - case 2: val += variables.get(name); //add + case GET: return variables.get(name); //get + case ADD: val += variables.get(name); //add + default: } if(val >= achievement.maxScore) @@ -279,7 +286,7 @@ class Achievements { } return getScore(name); }); - Lua_helper.add_callback(lua, "setAchievementScore", function(name:String, ?value:Float = 1, ?saveIfNotUnlocked:Bool = true):Float + Lua_helper.add_callback(lua, "setAchievementScore", function(name:String, ?value:Float = 0, ?saveIfNotUnlocked:Bool = true):Float { if(!achievements.exists(name)) { diff --git a/source/psychlua/FunkinLua.hx b/source/psychlua/FunkinLua.hx index e458e1d8c7f..b4c083a9e69 100644 --- a/source/psychlua/FunkinLua.hx +++ b/source/psychlua/FunkinLua.hx @@ -130,6 +130,7 @@ class FunkinLua { set('misses', 0); set('hits', 0); set('combo', 0); + set('deaths', PlayState.deathCounter); set('rating', 0); set('ratingName', '');