mirror of
https://gitea.wildfiregames.com/0ad/0ad
synced 2026-06-16 05:13:58 -07:00
Add support for opening the most recent replay summary
Add getLastReplayMetadata() to get metadata of the most recent replay, or null if unavailable Add showLastGameSummary() to show the last game summary using metadata from getLastReplayMetadata() Add a default hotkey
This commit is contained in:
parent
32e5520507
commit
d4a9532ee6
5 changed files with 56 additions and 0 deletions
|
|
@ -229,6 +229,7 @@ mousegrabtoggle = F3 ; Toggle mouse grabbing mode
|
|||
|
||||
; > DIALOG HOTKEYS
|
||||
summary = "Ctrl+Tab" ; Toggle in-game summary
|
||||
lastsummary = "Alt+Shift+S" ; Show the last game summary
|
||||
lobby = "Alt+L" ; Show the multiplayer lobby in a dialog window.
|
||||
structree = "Alt+Shift+T" ; Show structure tree
|
||||
civinfo = "Alt+Shift+H" ; Show civilization info
|
||||
|
|
|
|||
|
|
@ -315,6 +315,7 @@ function formatXmppAnnouncement(subject, text)
|
|||
|
||||
return message;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts underscore-separated identifiers to PascalCase class names
|
||||
* for selecting entities by identity class.
|
||||
|
|
@ -326,6 +327,7 @@ function toPascalCase(str)
|
|||
.map(s => s.charAt(0).toUpperCase() + s.slice(1))
|
||||
.join('');
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers global hotkeys for opening GUI pages.
|
||||
*
|
||||
|
|
@ -344,4 +346,51 @@ function registerGlobalGuiPageHotkeys(hotkeys)
|
|||
}
|
||||
Engine.SetGlobalHotkey(key, "Press", () => Engine.OpenChildPage(`page_${key}.xml`));
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Get metadata of the most recent replay, or null if unavailable.
|
||||
*/
|
||||
function getLastReplayMetadata()
|
||||
{
|
||||
const replays = Engine.GetReplays(false);
|
||||
if (!replays.length)
|
||||
return null;
|
||||
|
||||
const lastReplay = replays.reduce((a, b) =>
|
||||
a.attribs.timestamp > b.attribs.timestamp ? a : b
|
||||
);
|
||||
|
||||
const simData = Engine.GetReplayMetadata(lastReplay.directory);
|
||||
if (!simData)
|
||||
return null;
|
||||
|
||||
return {
|
||||
"simData": simData,
|
||||
"directory": lastReplay.directory
|
||||
};
|
||||
}
|
||||
|
||||
/*
|
||||
* Show the last game summary using metadata from getLastReplayMetadata()
|
||||
*/
|
||||
function showLastGameSummary()
|
||||
{
|
||||
const data = getLastReplayMetadata();
|
||||
|
||||
if (!data)
|
||||
{
|
||||
messageBox(500, 200, translate("No summary data available."), translate("Error"));
|
||||
return;
|
||||
}
|
||||
|
||||
Engine.OpenChildPage("page_summary.xml", {
|
||||
"sim": data.simData,
|
||||
"gui": {
|
||||
"replayDirectory": data.directory,
|
||||
"isInLobby": true,
|
||||
"ingame": false,
|
||||
"dialog": true
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
@ -44,6 +44,7 @@ var g_SetupWindow;
|
|||
function init(initData, hotloadData)
|
||||
{
|
||||
registerGlobalGuiPageHotkeys(["options", "hotkeys", "civinfo", "structree", "catafalque", "manual", "tips"]);
|
||||
Engine.SetGlobalHotkey("lastsummary", "Press", () => showLastGameSummary());
|
||||
return Promise.race([new Promise(closePageCallback =>
|
||||
{
|
||||
g_SetupWindow = new SetupWindow(initData, hotloadData, closePageCallback);
|
||||
|
|
|
|||
|
|
@ -138,6 +138,10 @@
|
|||
"options": {
|
||||
"name": "Open Options window",
|
||||
"desc": "Open Options window."
|
||||
},
|
||||
"lastsummary": {
|
||||
"name": "Open last game summary",
|
||||
"desc": "Open last game summary."
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -37,6 +37,7 @@ async function init(attribs)
|
|||
return new Promise(closePageCallback =>
|
||||
{
|
||||
registerGlobalGuiPageHotkeys(["options", "hotkeys", "civinfo", "structree", "catafalque", "mapbrowser", "manual", "tips"]);
|
||||
Engine.SetGlobalHotkey("lastsummary", "Press", () => showLastGameSummary());
|
||||
g_LobbyHandler = new LobbyHandler(closePageCallback, attribs && attribs.dialog);
|
||||
});
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue