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 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";

View file

@ -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) {

View file

@ -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();

View file

@ -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);
}

View file

@ -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<String, Array<Score>> = [];
@ -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<String, PlayStatistics> = [];
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<Dynamic> = [];
@ -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<PlayStatistics> = json.levelStatistics;
for (key => value in levelStatData) {
levelStatistics.set(key, value);
}
}
highscoreName = json.highscoreName;
} else {
save();

View file

@ -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")

View file

@ -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"));