add version to world info
This commit is contained in:
parent
f2e7a54180
commit
7f41f95013
@ -10,6 +10,8 @@ world.get_list() -> tables array {
|
|||||||
name: str,
|
name: str,
|
||||||
-- world icon/preview (loading automatically)
|
-- world icon/preview (loading automatically)
|
||||||
icon: str
|
icon: str
|
||||||
|
-- engine version the world was saved on
|
||||||
|
version: {int, int}
|
||||||
}
|
}
|
||||||
|
|
||||||
-- Returns current day time in range \[0.0-1.0\]
|
-- Returns current day time in range \[0.0-1.0\]
|
||||||
|
|||||||
@ -9,7 +9,9 @@ world.get_list() -> массив таблиц {
|
|||||||
-- название мира
|
-- название мира
|
||||||
name: str,
|
name: str,
|
||||||
-- предпросмотр (автоматически загружаемая текстура)
|
-- предпросмотр (автоматически загружаемая текстура)
|
||||||
icon: str
|
icon: str,
|
||||||
|
-- версия движка, на которой был сохранен мир
|
||||||
|
version: {int, int}
|
||||||
}
|
}
|
||||||
|
|
||||||
-- Возвращает текущее игровое время от 0.0 до 1.0, где 0.0 и 1.0 - полночь, 0.5 - полдень.
|
-- Возвращает текущее игровое время от 0.0 до 1.0, где 0.0 и 1.0 - полночь, 0.5 - полдень.
|
||||||
|
|||||||
@ -1,6 +1,13 @@
|
|||||||
function on_open()
|
function on_open()
|
||||||
local worlds = world.get_list()
|
local worlds = world.get_list()
|
||||||
for _, info in ipairs(worlds) do
|
for _, info in ipairs(worlds) do
|
||||||
|
local major, minor = core.get_version()
|
||||||
|
if info.version[1] > major or info.version[2] > minor then
|
||||||
|
info.versionColor = "#A02010"
|
||||||
|
else
|
||||||
|
info.versionColor = "#808080"
|
||||||
|
end
|
||||||
|
info.versionString = string.format("%s.%s", unpack(info.version))
|
||||||
document.worlds:add(gui.template("world", info))
|
document.worlds:add(gui.template("world", info))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -14,4 +14,5 @@
|
|||||||
onclick='core.delete_world("%{name}")'>
|
onclick='core.delete_world("%{name}")'>
|
||||||
<image src='gui/delete_icon' size='32,32' color='#FFFFFF50'/>
|
<image src='gui/delete_icon' size='32,32' color='#FFFFFF50'/>
|
||||||
</button>
|
</button>
|
||||||
|
<label color='%{versionColor}' pos='317,44'>%{versionString}</label>
|
||||||
</container>
|
</container>
|
||||||
|
|||||||
@ -20,6 +20,12 @@
|
|||||||
|
|
||||||
using namespace scripting;
|
using namespace scripting;
|
||||||
|
|
||||||
|
static int l_get_version(lua::State* L) {
|
||||||
|
return lua::pushvec_stack(
|
||||||
|
L, glm::vec2(ENGINE_VERSION_MAJOR, ENGINE_VERSION_MINOR)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
/// @brief Creating new world
|
/// @brief Creating new world
|
||||||
/// @param name Name world
|
/// @param name Name world
|
||||||
/// @param seed Seed world
|
/// @param seed Seed world
|
||||||
@ -239,6 +245,7 @@ static int l_quit(lua::State*) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const luaL_Reg corelib[] = {
|
const luaL_Reg corelib[] = {
|
||||||
|
{"get_version", lua::wrap<l_get_version>},
|
||||||
{"new_world", lua::wrap<l_new_world>},
|
{"new_world", lua::wrap<l_new_world>},
|
||||||
{"open_world", lua::wrap<l_open_world>},
|
{"open_world", lua::wrap<l_open_world>},
|
||||||
{"reopen_world", lua::wrap<l_reopen_world>},
|
{"reopen_world", lua::wrap<l_reopen_world>},
|
||||||
|
|||||||
@ -4,7 +4,9 @@
|
|||||||
|
|
||||||
#include "assets/Assets.hpp"
|
#include "assets/Assets.hpp"
|
||||||
#include "assets/AssetsLoader.hpp"
|
#include "assets/AssetsLoader.hpp"
|
||||||
|
#include "coders/json.hpp"
|
||||||
#include "engine.hpp"
|
#include "engine.hpp"
|
||||||
|
#include "files/files.hpp"
|
||||||
#include "files/engine_paths.hpp"
|
#include "files/engine_paths.hpp"
|
||||||
#include "world/Level.hpp"
|
#include "world/Level.hpp"
|
||||||
#include "world/World.hpp"
|
#include "world/World.hpp"
|
||||||
@ -32,7 +34,15 @@ static int l_get_list(lua::State* L) {
|
|||||||
for (size_t i = 0; i < worlds.size(); i++) {
|
for (size_t i = 0; i < worlds.size(); i++) {
|
||||||
lua::createtable(L, 0, 1);
|
lua::createtable(L, 0, 1);
|
||||||
|
|
||||||
auto name = worlds[i].filename().u8string();
|
const auto& folder = worlds[i];
|
||||||
|
|
||||||
|
auto root = json::parse(files::read_string(folder/fs::u8path("world.json")));
|
||||||
|
const auto& versionMap = root["version"];
|
||||||
|
int versionMajor = versionMap["major"].asInteger();
|
||||||
|
int versionMinor = versionMap["minor"].asInteger();
|
||||||
|
|
||||||
|
|
||||||
|
auto name = folder.filename().u8string();
|
||||||
lua::pushstring(L, name);
|
lua::pushstring(L, name);
|
||||||
lua::setfield(L, "name");
|
lua::setfield(L, "name");
|
||||||
|
|
||||||
@ -48,6 +58,10 @@ static int l_get_list(lua::State* L) {
|
|||||||
}
|
}
|
||||||
lua::pushstring(L, icon);
|
lua::pushstring(L, icon);
|
||||||
lua::setfield(L, "icon");
|
lua::setfield(L, "icon");
|
||||||
|
|
||||||
|
lua::pushvec2(L, {versionMajor, versionMinor});
|
||||||
|
lua::setfield(L, "version");
|
||||||
|
|
||||||
lua::rawseti(L, i + 1);
|
lua::rawseti(L, i + 1);
|
||||||
}
|
}
|
||||||
return 1;
|
return 1;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user