Packaging pre-made worlds with minetest

User avatar
lordfingle
Member
 
Posts: 65
Joined: Sat Apr 04, 2015 09:21
GitHub: eidy
IRC: lordfingle
In-game: lordfingle

Packaging pre-made worlds with minetest

by lordfingle » Tue Oct 04, 2016 11:45

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

Attachments
minetestscreeny.PNG
minetestscreeny.PNG (827.92 KiB) Viewed 715 times
----------------------------------------------------------------------------------------------
Team Lead on "eidy- Love learning"
I like reading, walks on the beach and building edutech experiences in lua (Find out more in this post)
"Coming together is a beginning; keeping together is progress; working together is success." - Henry Ford
 

User avatar
MineYoshi
Member
 
Posts: 4267
Joined: Wed Jul 08, 2015 13:20
GitHub: MineYosh
IRC: MineYoshi
In-game: Kirby_Retro

Re: Packaging pre-made worlds with minetest

by MineYoshi » Fri Oct 07, 2016 22:11

So there is a pre-made world template, but if you want one totally new, you can use the random function?
Cool!
People talk about freedom of speech, so i'll say that God exists.
Open your eyes!! See The big unicorn conspiracy.!! :D The government has been lying to us about unicorns!!
"I've learned there are three things you don't discuss with people: religion, politics and the Great Pumpkin" - Linus Van Pelt
I'm the Officially 1st ABJist in the world ( ͡° ͜ʖ ͡°)
 

User avatar
lordfingle
Member
 
Posts: 65
Joined: Sat Apr 04, 2015 09:21
GitHub: eidy
IRC: lordfingle
In-game: lordfingle

Re: Packaging pre-made worlds with minetest

by lordfingle » Mon Oct 10, 2016 12:52

Yes that's right!
----------------------------------------------------------------------------------------------
Team Lead on "eidy- Love learning"
I like reading, walks on the beach and building edutech experiences in lua (Find out more in this post)
"Coming together is a beginning; keeping together is progress; working together is success." - Henry Ford
 

User avatar
TheReaperKing
Member
 
Posts: 493
Joined: Sun Nov 22, 2015 21:36

Re: Packaging pre-made worlds with minetest

by TheReaperKing » Mon Oct 10, 2016 13:24

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
Project Lead of the Doom 3 Mod Last Man Standing - http://Doom3Coop.com

Project Lead of Platinum Arts Sandbox Free 3D Game Maker - http://SandboxGameMaker.com

Youtube Channel - https://www.youtube.com/user/PlatinumArtsKids
 

User avatar
lordfingle
Member
 
Posts: 65
Joined: Sat Apr 04, 2015 09:21
GitHub: eidy
IRC: lordfingle
In-game: lordfingle

Re: Packaging pre-made worlds with minetest

by lordfingle » Mon Oct 10, 2016 13:45

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.
----------------------------------------------------------------------------------------------
Team Lead on "eidy- Love learning"
I like reading, walks on the beach and building edutech experiences in lua (Find out more in this post)
"Coming together is a beginning; keeping together is progress; working together is success." - Henry Ford
 


Return to Minetest-Related

Who is online

Users browsing this forum: No registered users and 28 guests

cron