Changeset View
Changeset View
Standalone View
Standalone View
binaries/data/mods/public/gui/session/developer_overlay/TimeWarp.js
/** | class TimeWarp extends DeveloperOverlayCheckbox | ||||
* This class manages the timewarp hotkeys that allow jumping back in time and fast forwarding the game. | |||||
*/ | |||||
class TimeWarp | |||||
{ | { | ||||
constructor() | constructor(me, attrs) | ||||
{ | { | ||||
super(me, attrs); | |||||
this.enabled = false; | this.enabled = false; | ||||
this.timewarpRewind = Engine.GetGUIObjectByName("timewarpRewind"); | this.checkbox.onPress = () => this.setEnabled(this.checkbox.checked) && this.updateControl(); | ||||
this.timewarpRewind.onPress = this.rewind.bind(this); | |||||
this.timewarpFastForward = Engine.GetGUIObjectByName("timewarpFastForward"); | Engine.SetGlobalHotkey("session.timewarp.rewind", "Press", () => this.rewind()); | ||||
this.timewarpFastForward.onPress = this.fastForward.bind(this); | Engine.SetGlobalHotkey("session.timewarp.fastforward", "Press", () => this.fastForward()); | ||||
this.timewarpFastForward.onRelease = this.resetSpeed.bind(this); | Engine.SetGlobalHotkey("session.timewarp.fastforward", "Release", () => this.resetSpeed()); | ||||
// Number of turns between snapshots. | |||||
this.NumberTurns = 10; | |||||
// Gamespeed used while pressing the fast forward hotkey. | |||||
this.FastForwardSpeed = 20; | |||||
} | |||||
updateControl() | |||||
{ | |||||
this.checkbox.checked = this.enabled; | |||||
} | } | ||||
setEnabled(enabled) | setEnabled(enabled) | ||||
{ | { | ||||
if (g_IsNetworked) | if (g_IsNetworked) | ||||
return; | return; | ||||
this.enabled = enabled; | this.enabled = enabled; | ||||
if (!enabled) | |||||
return; | |||||
if (enabled) | let box = new SessionMessageBox(); | ||||
(new TimeWarpMessageBox()).display(); | box.Width = 500; | ||||
box.Height = 250; | |||||
box.Title = translate("Time warp mode"); | |||||
box.Caption = translate("Note: time warp mode is a developer option, and not intended for use over long periods of time. Using it incorrectly may cause the game to run out of memory or crash."); | |||||
box.Buttons = [ | |||||
{ "caption": "Cancel" }, | |||||
{ "caption": "OK", "onPress": () => { | |||||
Engine.EnableTimeWarpRecording(enabled ? this.NumberTurns : 0); | Engine.EnableTimeWarpRecording(enabled ? this.NumberTurns : 0); | ||||
} } | |||||
]; | |||||
box.display(); | |||||
} | } | ||||
rewind() | rewind() | ||||
{ | { | ||||
if (this.enabled) | if (this.enabled) | ||||
Engine.RewindTimeWarp(); | Engine.RewindTimeWarp(); | ||||
} | } | ||||
fastForward() | fastForward() | ||||
{ | { | ||||
if (this.enabled) | if (this.enabled) | ||||
Engine.SetSimRate(this.FastForwardSpeed); | Engine.SetSimRate(this.FastForwardSpeed); | ||||
} | } | ||||
resetSpeed() | resetSpeed() | ||||
{ | { | ||||
if (this.enabled) | if (this.enabled) | ||||
Engine.SetSimRate(1); | Engine.SetSimRate(1); | ||||
} | } | ||||
} | } | ||||
/** | |||||
* Number of turns between snapshots. | |||||
*/ | |||||
TimeWarp.prototype.NumberTurns = 10; | |||||
/** | |||||
* Gamespeed used while pressing the fast forward hotkey. | |||||
*/ | |||||
TimeWarp.prototype.FastForwardSpeed = 20; | |||||
class TimeWarpMessageBox extends SessionMessageBox | |||||
{ | |||||
} | |||||
TimeWarpMessageBox.prototype.Width = 500; | |||||
TimeWarpMessageBox.prototype.Height = 250; | |||||
TimeWarpMessageBox.prototype.Title = translate("Time warp mode"); | |||||
TimeWarpMessageBox.prototype.Caption = translate( | |||||
"Note: time warp mode is a developer option, and not intended for use over long periods of time. Using it incorrectly may cause the game to run out of memory or crash."); |
Wildfire Games · Phabricator