add test.open_world

This commit is contained in:
MihailRis 2024-12-11 14:49:52 +03:00
parent b05c2fc911
commit cfc16679cb
3 changed files with 17 additions and 2 deletions

View File

@ -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)

View File

@ -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

View File

@ -133,8 +133,10 @@ std::unique_ptr<Level> 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;