This is a similar requirement to the minetest tutorial issue:
https://github.com/minetest/minetest/issues/3778 "Include Tutorial subgame with Minetest"
Shipping in the Worlds Folder
Previously we were shipping a "worlds" folder, but this means that once a player starts messing with the shipped world, it will change. It also means that deploying revisions will overwrite this world.
New Approach
Our solution is to place a template for our game world in a zip file. This zip file is then shipped in the worlds folder instead of the actual world.
We modified the builtin tab_singleplayer.lua to show a "New" button that enables this functionality. There's also a "Random" button that does the original "create_world" functionality.
We then modified tab_singleplayer.lua to do the unzipping.
Here's my changes to tab_singleplayer.lua. The code seems inefficient to me, but I couldn't work out a way of getting the value of the worlds folder.
Perhaps someone else can?
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
- Code: Select all
if fields["world_new"] ~= nil then
-- Get the name of the first game
local thisgame = current_game()
if thisgame == nil then
gamedata.errormessage =
fgettext("No world created or selected!")
return
end
local _, thisgameindex = gamemgr.find_by_gameid(thisgame.id)
local newworldname = thisgame.id
-- See if new world exists
local world_index
local world_list = core.get_worlds()
local found_singleplayerworld = false
for i, world in ipairs(world_list) do
if world.name == newworldname then
found_singleplayerworld = true
world_index = i
break
end
end
if found_singleplayerworld then
core.delete_world(world_index)
end
-- Create a world using the first game (will be overriden)
core.create_world(newworldname, thisgameindex)
-- Get the world path
local worldpath = nil
world_list = core.get_worlds()
local found_singleplayerworld = false
for i, world in ipairs(world_list) do
if world.name == newworldname then
worldpath = world.path
world_index = i
break
end
end
-- Extract to the world folder
local zippath = worldpath .. ".zip"
core.extract_zip(worldpath .. ".zip", worldpath)
gamedata.worldindex = world_index
-- Launch
gamedata.selected_world = world_index --menudata.worldlist:get_raw_index(selected)
if gamedata.selected_world ~= 0 then
gamedata.singleplayer = true
core.start()
else
gamedata.errormessage =
fgettext("No world created or selected!")
end