Page 1 of 1

Packaging pre-made worlds with minetest

PostPosted: Tue Oct 04, 2016 11:45
by lordfingle
In the educational game "eidy" we have pre-built a great deal of content. We want the default game experience to be using our pre-built world.

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.

Image

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


Re: Packaging pre-made worlds with minetest

PostPosted: Fri Oct 07, 2016 22:11
by MineYoshi
So there is a pre-made world template, but if you want one totally new, you can use the random function?
Cool!

Re: Packaging pre-made worlds with minetest

PostPosted: Mon Oct 10, 2016 12:52
by lordfingle
Yes that's right!

Re: Packaging pre-made worlds with minetest

PostPosted: Mon Oct 10, 2016 13:24
by TheReaperKing
I wonder if something like this would help. I haven't tested it but it clears the area around the spawn and rebuilds it:
viewtopic.php?f=9&t=10393

Re: Packaging pre-made worlds with minetest

PostPosted: Mon Oct 10, 2016 13:45
by lordfingle
Oh I get it, that's very cool. Perhaps later on I'll do something like this for the "Random" world (normal mapgen). generating the starter hut.