0ad/binaries/data/mods/public/gui/session/developer_overlay/TimeWarp.js
elexis bc6da5e3f2 SessionMessageBox class, refs #5387.
Decouples events from event handling, removes implicit-pause duplication
per messagebox and allows mods to modify message box values.

Differential Revision: https://code.wildfiregames.com/D2398
Comments By: Stan, Freagarach
This was SVN commit r23114.
2019-10-30 11:14:55 +00:00

67 lines
1.5 KiB
JavaScript

/**
* This class manages the timewarp hotkeys that allow jumping back in time and fast forwarding the game.
*/
class TimeWarp
{
constructor()
{
this.enabled = false;
this.timewarpRewind = Engine.GetGUIObjectByName("timewarpRewind");
this.timewarpRewind.onPress = this.rewind.bind(this);
this.timewarpFastForward = Engine.GetGUIObjectByName("timewarpFastForward");
this.timewarpFastForward.onPress = this.fastForward.bind(this);
this.timewarpFastForward.onRelease = this.resetSpeed.bind(this);
}
setEnabled(enabled)
{
if (g_IsNetworked)
return;
this.enabled = enabled;
if (enabled)
(new TimeWarpMessageBox()).display();
Engine.EnableTimeWarpRecording(enabled ? this.NumberTurns : 0);
}
rewind()
{
if (this.enabled)
Engine.RewindTimeWarp();
}
fastForward()
{
if (this.enabled)
Engine.SetSimRate(this.FastForwardSpeed);
}
resetSpeed()
{
if (this.enabled)
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.");