From a1b9164b4592f2cba3b23cb0cf51cbc7f4ac047e Mon Sep 17 00:00:00 2001 From: RandomityGuy <31925790+RandomityGuy@users.noreply.github.com> Date: Mon, 21 Nov 2022 21:18:58 +0530 Subject: [PATCH] stats --- data/missions_mbp/advanced/NeonTech.mis | 4 +-- src/MarbleGame.hx | 3 ++ src/MarbleWorld.hx | 32 ++++++++++++++++++++ src/Mission.hx | 10 +++---- src/Settings.hx | 39 +++++++++++++++++++++++++ src/Util.hx | 22 ++++++++++++++ src/gui/PlayMissionGui.hx | 3 ++ 7 files changed, 105 insertions(+), 8 deletions(-) diff --git a/data/missions_mbp/advanced/NeonTech.mis b/data/missions_mbp/advanced/NeonTech.mis index a7d8cd41..f7c955c8 100644 --- a/data/missions_mbp/advanced/NeonTech.mis +++ b/data/missions_mbp/advanced/NeonTech.mis @@ -3,11 +3,11 @@ new SimGroup(MissionGroup) { new ScriptObject(MissionInfo) { - name = "N\x91onTech"; + name = "NeonTech"; artist = "Phil and Matan"; startHelpText = "A small course to test your skills."; type = "Advanced"; - desc = "Progress along the \xFCber-styled, technical floors!"; + desc = "Progress along the Uber-styled, technical floors!"; level = "15"; music = "Seaside Revisited.ogg"; time = "60000"; diff --git a/src/MarbleGame.hx b/src/MarbleGame.hx index 24fca115..7102a109 100644 --- a/src/MarbleGame.hx +++ b/src/MarbleGame.hx @@ -16,6 +16,7 @@ import src.JSPlatform; import gui.Canvas; import src.Util; import src.ProfilerUI; +import src.Settings; @:publicFields class MarbleGame { @@ -220,6 +221,8 @@ class MarbleGame { world.dispose(); world = null; canvas.setContent(pmg); + + Settings.save(); } public function playMission(mission:Mission) { diff --git a/src/MarbleWorld.hx b/src/MarbleWorld.hx index c7372ac1..2fda0597 100644 --- a/src/MarbleWorld.hx +++ b/src/MarbleWorld.hx @@ -987,6 +987,16 @@ class MarbleWorld extends Scheduler { if (Key.isPressed(Settings.controlsSettings.respawn)) { this.respawnPressedTime = timeState.timeSinceLoad; this.restart(); + Settings.playStatistics.respawns++; + if (!Settings.levelStatistics.exists(mission.path)) { + Settings.levelStatistics.set(mission.path, { + oobs: 0, + respawns: 1, + totalTime: 0, + }); + } else { + Settings.levelStatistics[mission.path].respawns++; + } return; } @@ -1480,6 +1490,16 @@ class MarbleWorld extends Scheduler { this.outOfBounds = true; this.outOfBoundsTime = this.timeState.clone(); this.marble.camera.oob = true; + Settings.playStatistics.oobs++; + if (!Settings.levelStatistics.exists(mission.path)) { + Settings.levelStatistics.set(mission.path, { + oobs: 1, + respawns: 0, + totalTime: 0, + }); + } else { + Settings.levelStatistics[mission.path].oobs++; + } // sky.follow = null; // this.oobCameraPosition = camera.position.clone(); playGui.setCenterText('outofbounds'); @@ -1636,6 +1656,18 @@ class MarbleWorld extends Scheduler { } public function dispose() { + // Gotta add the timesinceload to our stats + Settings.playStatistics.totalTime += this.timeState.timeSinceLoad; + if (!Settings.levelStatistics.exists(mission.path)) { + Settings.levelStatistics.set(mission.path, { + oobs: 0, + respawns: 0, + totalTime: this.timeState.timeSinceLoad, + }); + } else { + Settings.levelStatistics[mission.path].totalTime += this.timeState.timeSinceLoad; + } + this.playGui.dispose(); scene.removeChildren(); diff --git a/src/Mission.hx b/src/Mission.hx index 18169b93..0c553581 100644 --- a/src/Mission.hx +++ b/src/Mission.hx @@ -52,12 +52,10 @@ class Mission { for (element in simGroup.elements) { if (this.hasEgg) break; - if ([MissionElementType.Item].contains(element._type)) { - if (element._type == MissionElementType.Item) { - var so:MissionElementItem = cast element; - if (so.datablock.toLowerCase() == 'easteregg') - this.hasEgg = true; - } + if (element._type == MissionElementType.Item) { + var so:MissionElementItem = cast element; + if (so.datablock.toLowerCase() == 'easteregg') + this.hasEgg = true; } else if (element._type == MissionElementType.SimGroup && !this.hasEgg) { scanMission(cast element); } diff --git a/src/Settings.hx b/src/Settings.hx index 1863692e..6e90ab79 100644 --- a/src/Settings.hx +++ b/src/Settings.hx @@ -64,6 +64,12 @@ typedef TouchSettings = { var buttonJoystickMultiplier:Float; } +typedef PlayStatistics = { + var oobs:Int; + var respawns:Int; + var totalTime:Float; +} + class Settings { public static var highScores:Map> = []; @@ -115,6 +121,15 @@ class Settings { powerupButtonSize: 60, buttonJoystickMultiplier: 2.5 } + + public static var playStatistics:PlayStatistics = { + oobs: 0, + respawns: 0, + totalTime: 0, + } + + public static var levelStatistics:Map = []; + public static var highscoreName = ""; public static var uiScale = 1.0; @@ -159,16 +174,21 @@ class Settings { options: optionsSettings, controls: controlsSettings, touch: touchSettings, + stats: playStatistics, highscoreName: highscoreName }; var scoreCount = 0; var eggCount = 0; + var statCount = 0; for (key => value in highScores) { scoreCount++; } for (key => value in easterEggs) { eggCount++; } + for (key => value in levelStatistics) { + statCount++; + } #if hl if (scoreCount != 0) outputData.highScores = highScores; @@ -179,6 +199,11 @@ class Settings { } else { outputData.easterEggs = {}; } + if (statCount != 0) { + outputData.levelStatistics = levelStatistics; + } else { + outputData.levelStatistics = {}; + } #end #if js var kvps:Array = []; @@ -191,6 +216,11 @@ class Settings { kvps.push([key, value]); jobj = js.lib.Object.fromEntries(kvps); outputData.easterEggs = jobj; + kvps = []; + for (key => value in levelStatistics) + kvps.push([key, value]); + jobj = js.lib.Object.fromEntries(kvps); + outputData.levelStatistics = jobj; #end var json = Json.stringify(outputData); #if (hl && !android) @@ -240,6 +270,15 @@ class Settings { if (json.touch != null) { touchSettings = json.touch; } + if (json.stats != null) { + playStatistics = json.stats; + } + if (json.levelStatistics != null) { + var levelStatData:DynamicAccess = json.levelStatistics; + for (key => value in levelStatData) { + levelStatistics.set(key, value); + } + } highscoreName = json.highscoreName; } else { save(); diff --git a/src/Util.hx b/src/Util.hx index 0aa3c3f7..4fe9a970 100644 --- a/src/Util.hx +++ b/src/Util.hx @@ -284,6 +284,28 @@ class Util { return '${minutesTen}${minutesOne}:${secondsTen}${secondsOne}.${hundredthTen}${hundredthOne}${thousandth}'; } + public static function formatTimeHours(time:Float) { + var et = time * 1000; + + var hours = Math.floor(Math.floor(et / 1000) / 3600); + var minutes = Math.floor(Math.floor(et / 1000) / 60) - (hours * 60); + var seconds = Math.floor(et / 1000) - (minutes * 60) - (hours * 3600); + var hundredth = Math.floor((et % 1000) / 10); + + var secondsOne = seconds % 10; + var secondsTen = Math.floor(seconds / 10); + var minutesOne = minutes % 10; + var minutesTen = Math.floor(minutes / 10); + var hoursOne = hours % 10; + var hoursTen = Math.floor(hours / 10); + var hundredthOne = hundredth % 10; + var hundredthTen = (hundredth - hundredthOne) / 10; + var thousandth = Math.floor(et % 10); + + return + '${(hours > 0 ? (hoursTen > 0 ? '${hoursTen}' : '') +'${hoursOne}' + ':' : '')}${minutesTen}${minutesOne}:${secondsTen}${secondsOne}.${hundredthTen}${hundredthOne}${thousandth}'; + } + public static function getKeyForButton(button:Int) { var keyName = Key.getKeyName(button); if (keyName == "MouseLeft") diff --git a/src/gui/PlayMissionGui.hx b/src/gui/PlayMissionGui.hx index 0b3651c7..e9f66c60 100644 --- a/src/gui/PlayMissionGui.hx +++ b/src/gui/PlayMissionGui.hx @@ -614,6 +614,9 @@ class PlayMissionGui extends GuiImage { var pmStats = new GuiButton(loadButtonImages("data/ui/play/statistics")); pmStats.position = new Vector(101, 46); pmStats.extent = new Vector(43, 43); + pmStats.pressedAction = (e) -> { + MarbleGame.canvas.pushDialog(new StatisticsGui(this.currentGame)); + } pmMorePopDlg.addChild(pmStats); var pmAchievements = new GuiButton(loadButtonImages("data/ui/play/achiev"));