This commit is contained in:
RandomityGuy 2022-11-21 21:18:58 +05:30
parent f1e4b44ce1
commit a1b9164b45
7 changed files with 105 additions and 8 deletions

View file

@ -3,11 +3,11 @@
new SimGroup(MissionGroup) { new SimGroup(MissionGroup) {
new ScriptObject(MissionInfo) { new ScriptObject(MissionInfo) {
name = "N\x91onTech"; name = "NeonTech";
artist = "Phil and Matan"; artist = "Phil and Matan";
startHelpText = "A small course to test your skills."; startHelpText = "A small course to test your skills.";
type = "Advanced"; type = "Advanced";
desc = "Progress along the \xFCber-styled, technical floors!"; desc = "Progress along the Uber-styled, technical floors!";
level = "15"; level = "15";
music = "Seaside Revisited.ogg"; music = "Seaside Revisited.ogg";
time = "60000"; time = "60000";

View file

@ -16,6 +16,7 @@ import src.JSPlatform;
import gui.Canvas; import gui.Canvas;
import src.Util; import src.Util;
import src.ProfilerUI; import src.ProfilerUI;
import src.Settings;
@:publicFields @:publicFields
class MarbleGame { class MarbleGame {
@ -220,6 +221,8 @@ class MarbleGame {
world.dispose(); world.dispose();
world = null; world = null;
canvas.setContent(pmg); canvas.setContent(pmg);
Settings.save();
} }
public function playMission(mission:Mission) { public function playMission(mission:Mission) {

View file

@ -987,6 +987,16 @@ class MarbleWorld extends Scheduler {
if (Key.isPressed(Settings.controlsSettings.respawn)) { if (Key.isPressed(Settings.controlsSettings.respawn)) {
this.respawnPressedTime = timeState.timeSinceLoad; this.respawnPressedTime = timeState.timeSinceLoad;
this.restart(); 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; return;
} }
@ -1480,6 +1490,16 @@ class MarbleWorld extends Scheduler {
this.outOfBounds = true; this.outOfBounds = true;
this.outOfBoundsTime = this.timeState.clone(); this.outOfBoundsTime = this.timeState.clone();
this.marble.camera.oob = true; 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; // sky.follow = null;
// this.oobCameraPosition = camera.position.clone(); // this.oobCameraPosition = camera.position.clone();
playGui.setCenterText('outofbounds'); playGui.setCenterText('outofbounds');
@ -1636,6 +1656,18 @@ class MarbleWorld extends Scheduler {
} }
public function dispose() { 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(); this.playGui.dispose();
scene.removeChildren(); scene.removeChildren();

View file

@ -52,12 +52,10 @@ class Mission {
for (element in simGroup.elements) { for (element in simGroup.elements) {
if (this.hasEgg) if (this.hasEgg)
break; break;
if ([MissionElementType.Item].contains(element._type)) { if (element._type == MissionElementType.Item) {
if (element._type == MissionElementType.Item) { var so:MissionElementItem = cast element;
var so:MissionElementItem = cast element; if (so.datablock.toLowerCase() == 'easteregg')
if (so.datablock.toLowerCase() == 'easteregg') this.hasEgg = true;
this.hasEgg = true;
}
} else if (element._type == MissionElementType.SimGroup && !this.hasEgg) { } else if (element._type == MissionElementType.SimGroup && !this.hasEgg) {
scanMission(cast element); scanMission(cast element);
} }

View file

@ -64,6 +64,12 @@ typedef TouchSettings = {
var buttonJoystickMultiplier:Float; var buttonJoystickMultiplier:Float;
} }
typedef PlayStatistics = {
var oobs:Int;
var respawns:Int;
var totalTime:Float;
}
class Settings { class Settings {
public static var highScores:Map<String, Array<Score>> = []; public static var highScores:Map<String, Array<Score>> = [];
@ -115,6 +121,15 @@ class Settings {
powerupButtonSize: 60, powerupButtonSize: 60,
buttonJoystickMultiplier: 2.5 buttonJoystickMultiplier: 2.5
} }
public static var playStatistics:PlayStatistics = {
oobs: 0,
respawns: 0,
totalTime: 0,
}
public static var levelStatistics:Map<String, PlayStatistics> = [];
public static var highscoreName = ""; public static var highscoreName = "";
public static var uiScale = 1.0; public static var uiScale = 1.0;
@ -159,16 +174,21 @@ class Settings {
options: optionsSettings, options: optionsSettings,
controls: controlsSettings, controls: controlsSettings,
touch: touchSettings, touch: touchSettings,
stats: playStatistics,
highscoreName: highscoreName highscoreName: highscoreName
}; };
var scoreCount = 0; var scoreCount = 0;
var eggCount = 0; var eggCount = 0;
var statCount = 0;
for (key => value in highScores) { for (key => value in highScores) {
scoreCount++; scoreCount++;
} }
for (key => value in easterEggs) { for (key => value in easterEggs) {
eggCount++; eggCount++;
} }
for (key => value in levelStatistics) {
statCount++;
}
#if hl #if hl
if (scoreCount != 0) if (scoreCount != 0)
outputData.highScores = highScores; outputData.highScores = highScores;
@ -179,6 +199,11 @@ class Settings {
} else { } else {
outputData.easterEggs = {}; outputData.easterEggs = {};
} }
if (statCount != 0) {
outputData.levelStatistics = levelStatistics;
} else {
outputData.levelStatistics = {};
}
#end #end
#if js #if js
var kvps:Array<Dynamic> = []; var kvps:Array<Dynamic> = [];
@ -191,6 +216,11 @@ class Settings {
kvps.push([key, value]); kvps.push([key, value]);
jobj = js.lib.Object.fromEntries(kvps); jobj = js.lib.Object.fromEntries(kvps);
outputData.easterEggs = jobj; outputData.easterEggs = jobj;
kvps = [];
for (key => value in levelStatistics)
kvps.push([key, value]);
jobj = js.lib.Object.fromEntries(kvps);
outputData.levelStatistics = jobj;
#end #end
var json = Json.stringify(outputData); var json = Json.stringify(outputData);
#if (hl && !android) #if (hl && !android)
@ -240,6 +270,15 @@ class Settings {
if (json.touch != null) { if (json.touch != null) {
touchSettings = json.touch; touchSettings = json.touch;
} }
if (json.stats != null) {
playStatistics = json.stats;
}
if (json.levelStatistics != null) {
var levelStatData:DynamicAccess<PlayStatistics> = json.levelStatistics;
for (key => value in levelStatData) {
levelStatistics.set(key, value);
}
}
highscoreName = json.highscoreName; highscoreName = json.highscoreName;
} else { } else {
save(); save();

View file

@ -284,6 +284,28 @@ class Util {
return '${minutesTen}${minutesOne}:${secondsTen}${secondsOne}.${hundredthTen}${hundredthOne}${thousandth}'; 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) { public static function getKeyForButton(button:Int) {
var keyName = Key.getKeyName(button); var keyName = Key.getKeyName(button);
if (keyName == "MouseLeft") if (keyName == "MouseLeft")

View file

@ -614,6 +614,9 @@ class PlayMissionGui extends GuiImage {
var pmStats = new GuiButton(loadButtonImages("data/ui/play/statistics")); var pmStats = new GuiButton(loadButtonImages("data/ui/play/statistics"));
pmStats.position = new Vector(101, 46); pmStats.position = new Vector(101, 46);
pmStats.extent = new Vector(43, 43); pmStats.extent = new Vector(43, 43);
pmStats.pressedAction = (e) -> {
MarbleGame.canvas.pushDialog(new StatisticsGui(this.currentGame));
}
pmMorePopDlg.addChild(pmStats); pmMorePopDlg.addChild(pmStats);
var pmAchievements = new GuiButton(loadButtonImages("data/ui/play/achiev")); var pmAchievements = new GuiButton(loadButtonImages("data/ui/play/achiev"));