From bc2a091f95d19a6b15871d6d25fdaf95e2199e0d Mon Sep 17 00:00:00 2001 From: ac-stef Date: Sun, 4 Sep 2016 15:00:00 +0200 Subject: [PATCH] show map timestamp in map info menu also: more stuff in the map settings menu getmaptimestamp fmt Returns the "last written" timestamp of the current map in the requested format. If fmt starts with "U", the time is given as UTC, otherwise as local time. If fmt is empty, or not given or just the "U", the format defaults to "YYYYMMDD_hh.mm.ss". Use "%c" to get something nicer. DOCREF getmaptimestamp --- config/menus_edit.cfg | 22 ++++++++++++++++++---- config/menus_licenses.cfg | 3 ++- source/src/tools.cpp | 2 +- source/src/worldio.cpp | 1 + 4 files changed, 22 insertions(+), 6 deletions(-) diff --git a/config/menus_edit.cfg b/config/menus_edit.cfg index e7a1e90d..88498683 100644 --- a/config/menus_edit.cfg +++ b/config/menus_edit.cfg @@ -154,10 +154,6 @@ newmenu [Map operations] menuitem "Newmap (128x128 cubes - recommended)" [ newmap 7 ] menuitem "Newmap (256x256 cubes)" [ newmap 8 ] menuitem "Increase mapsize (2x)" [ mapenlarge; echo The map size has been increased by 2. However, the new space is solid. To utilize it, you will need to turn it into non-solid space, by selecting it and pressing G. ] -menuitem "Edit map message" editmapmsg -menuitem "Select map license" [ showmenu "Select map license" ] -menuitem "Edit map license comment" [ editsvar mapinfo_comment ] -menuitem "Show map info" [ showmenu "Show map info" ] // FIXME: move to more appropriate menu menuitem "Print entity stats" entstats menuitem "Select the next closest entity" nextclosestent menuitem "Copy the current closest entity" copyent @@ -189,9 +185,27 @@ menuinit [ if (! (strlen $n)) [n = ] menuitem (concatword "Notexture:\t\t\t\t" (pop n)) [showmenu "Set notexture"] menuitem (concatword "Skymap:\t\t\t\t\t" $loadsky) [showmenu skymaps] + menuitem "" -1 + if (strlen $mapmsg) [ + menuitem (concat "Map message:" $mapmsg) editmapmsg + ] [ + menuitem "Edit map message..." editmapmsg + ] + if (strlen $mapinfo_license) [ + menuitem (concatword "Map license tag: \"" $mapinfo_license "\"") [ showmenu "Select map license" ] + if (strlen $mapinfo_comment) [ + menuitem (concat "Map license comment:" $mapinfo_comment) [ editsvar mapinfo_comment ] + ] [ + menuitem "Edit map license comment..." [ editsvar mapinfo_comment ] + ] + ] [ + menuitem "Select map license..." [ showmenu "Select map license" ] + ] ] [ menuitem "menu only available in edit mode" -1 ] + menuitem "" -1 + menuitem "Show map info..." [ showmenu "Show map info" ] ] newmenu [Water colour] diff --git a/config/menus_licenses.cfg b/config/menus_licenses.cfg index fb3f2e77..727d7eec 100644 --- a/config/menus_licenses.cfg +++ b/config/menus_licenses.cfg @@ -126,8 +126,9 @@ newmenu "Show map info" menuinit [ resetcurmenu menuitem (concatword "Current map: \fs\f1" (curmap) "\fr rev " $curmaprevision) -1 + menuitem (concat "Last saved:" (getmaptimestamp %c) "(local time)") -1 if (strlen $mapmsg) [ - menuitem $mapmsg -1 + menuitem (concat "Map message:" $mapmsg) -1 ] if (< (findlist $__maplicense_list $mapinfo_license) 0) [ menuitem (concatword "map license tag: \"" $mapinfo_license "\"") -1 diff --git a/source/src/tools.cpp b/source/src/tools.cpp index 3f64fdae..a36069e4 100644 --- a/source/src/tools.cpp +++ b/source/src/tools.cpp @@ -26,7 +26,7 @@ const char *timestring(time_t t, bool local, const char *fmt, char *buf) struct tm *timeinfo, b; timeinfo = local ? localtime_r(&t, &b) : gmtime_r(&t, &b); #endif - strftime(buf, sizeof(string) - 1, fmt ? fmt : "%Y%m%d_%H.%M.%S", timeinfo); // sortable time for filenames + strftime(buf, sizeof(string) - 1, fmt && *fmt ? fmt : "%Y%m%d_%H.%M.%S", timeinfo); // sortable time for filenames return buf; } diff --git a/source/src/worldio.cpp b/source/src/worldio.cpp index 23212fcb..34e4e0b8 100644 --- a/source/src/worldio.cpp +++ b/source/src/worldio.cpp @@ -773,6 +773,7 @@ COMMAND(showmapdims, ""); extern void preparectf(bool cleanonly = false); int maploaded = 0; VAR(curmaprevision, 1, 0, 0); +COMMANDF(getmaptimestamp, "s", (char *fmt) { result(hdr.timestamp ? timestring((time_t)hdr.timestamp, *fmt != 'U', *fmt == 'U' ? fmt + 1 : fmt) : "no timestamp stored"); }); extern char *mlayout; extern int Mv, Ma, Hhits;