From cfc16679cb91d4a580d98b549782ee2af7682361 Mon Sep 17 00:00:00 2001 From: MihailRis Date: Wed, 11 Dec 2024 14:49:52 +0300 Subject: [PATCH] add test.open_world --- dev/tests/example.lua | 12 ++++++++++++ res/scripts/stdlib.lua | 1 + src/world/World.cpp | 6 ++++-- 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/dev/tests/example.lua b/dev/tests/example.lua index 6262e369..a1a0c369 100644 --- a/dev/tests/example.lua +++ b/dev/tests/example.lua @@ -1,8 +1,20 @@ +-- Create/close/open/close world + +-- Open test.new_world("demo", "2019", "core:default") assert(world.is_open()) assert(world.get_generator() == "core:default") test.sleep(1) assert(world.get_total_time() > 0.0) print(world.get_total_time()) + +-- Close test.close_world(true) assert(not world.is_open()) + +-- Reopen +test.open_world("demo") +assert(world.is_open()) +assert(world.get_total_time() > 0.0) +test.tick() +test.close_world(true) diff --git a/res/scripts/stdlib.lua b/res/scripts/stdlib.lua index a732fde6..3d21def6 100644 --- a/res/scripts/stdlib.lua +++ b/res/scripts/stdlib.lua @@ -13,6 +13,7 @@ if test then test.sleep = sleep test.name = __VC_TEST_NAME test.new_world = core.new_world + test.open_world = core.open_world test.close_world = core.close_world test.reconfig_packs = core.reconfig_packs test.tick = coroutine.yield diff --git a/src/world/World.cpp b/src/world/World.cpp index bec61d3a..812f6d91 100644 --- a/src/world/World.cpp +++ b/src/world/World.cpp @@ -133,8 +133,10 @@ std::unique_ptr World::load( auto playerRoot = files::read_json(file); level->players->deserialize(playerRoot); - if (!playerRoot["players"][0].has("id")) { - level->getWorld()->getInfo().nextPlayerId++; + if (!playerRoot["players"].empty()) { + if (!playerRoot["players"][0].has("id")) { + level->getWorld()->getInfo().nextPlayerId++; + } } } return level;