]> git.lizzy.rs Git - dragonblocks.git/blob - engine/world.js
Code style overhaul
[dragonblocks.git] / engine / world.js
1 /*
2  * world.js
3  *
4  * Copyright 2020 Elias Fleckenstein <eliasfleckenstein@web.de>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19  * MA 02110-1301, USA.
20  *
21  *
22  */
23
24 dragonblocks.getSavestring = _ => {
25         dragonblocks.world.map = dragonblocks.map;
26         dragonblocks.world.mods = dragonblocks.mods;
27         dragonblocks.world.spawnedEntities = dblib.removeTmp(dragonblocks.spawnedEntities);
28
29         return JSON.stringify(dragonblocks.world);
30 }
31
32 dragonblocks.save = _ => {
33         if (dragonblocks.loggedin)
34                 return dragonblocks.backendCall("saveWorld", true, {name: dragonblocks.worldname, world: dragonblocks.getSavestring()});
35 };
36
37 dragonblocks.checkWorldnameSpelling = name => {
38         return name.match(/^[a-zA-Z0-9]+$/);
39 };
40
41 dragonblocks.loadWorldList = _ => {
42         dragonblocks.worlds = dragonblocks.backendCall("getWorlds");
43 };
44
45 dragonblocks.getEmptyWorld = function(){
46         return {
47                 map:{
48                         data: Array(dragonblocks.settings.map.width).fill(Array(dragonblocks.settings.map.width).fill(new dragonblocks.MapNode("air"))),
49                         width: dragonblocks.settings.map.width,
50                         height: dragonblocks.settings.map.height,
51                         displayTop: dragonblocks.settings.map.height / 2,
52                         displayLeft: dragonblocks.settings.map.width / 2 - 5,
53                 },
54                 structures: {},
55         };
56 }