]> git.lizzy.rs Git - dragonblocks.git/blob - engine/world.js
Reset file permissions to defaults
[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 dragonblocks.getSavestring = function(){
24         dragonblocks.world.map = dragonblocks.map;
25         dragonblocks.world.mods = dragonblocks.mods;
26         dragonblocks.world.spawnedEntities = dblib.removeTmp(dragonblocks.spawnedEntities)
27         return JSON.stringify(dragonblocks.world);
28 }
29 dragonblocks.save = function(){
30         if(dragonblocks.loggedin)
31                 $.post({
32                         url: "api.php",
33                         data: {call: "saveWorld", name: dragonblocks.worldname, world: dragonblocks.getSavestring()}
34                 });
35 }
36 dragonblocks.checkWorldOwnership = function(name){
37         return $.get("worlds/" + name + "/owner.txt").responseText == dragonblocks.username;
38 }
39 dragonblocks.checkWorldExistance = function(name){
40         return $.get("worlds/" + name).status == 200;
41 }
42 dragonblocks.checkWorldSpelling = function(name){
43         return $.getJSON({
44                 url: "api.php",
45                 method: "POST",
46                 data: {call: "checkWorldname", name: name},
47         }).responseJSON;
48 }
49 dragonblocks.loadWorldlist = function(){
50         dragonblocks.worlds = [];
51         let allWorlds = $.getJSON({
52                 url: "api.php",
53                 method: "POST",
54                 data: {call: "getWorlds"}
55         }).responseJSON;
56         for(let world of allWorlds){
57                 if(dragonblocks.checkWorldOwnership(world))
58                         dragonblocks.worlds.push(world);
59         }
60 }
61 dragonblocks.getEmptyWorld = function(){
62         return {
63                 map:{
64                         content: Array(dragonblocks.settings.map.width).fill(Array(dragonblocks.settings.map.width).fill(new dragonblocks.MapNode("air"))),
65                         width: dragonblocks.settings.map.width,
66                         height: dragonblocks.settings.map.height,
67                         displayTop: dragonblocks.settings.map.height / 2,
68                         displayLeft: dragonblocks.settings.map.width / 2 - 5,
69                 },
70                 structures: {},
71         };
72 }