-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathworld.js
More file actions
59 lines (48 loc) · 1.03 KB
/
world.js
File metadata and controls
59 lines (48 loc) · 1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
var db = require('./db')
module.exports = {
get: get,
clone: clone,
set: set,
getParsed: getParsed
}
var _world = [[]]
var _parsedWorld = [[]]
function _loadWorld () {
// db to-do
}
function clone () {
return get().slice(0)
}
function save () {
// db to-do
}
function get () {
return _world
}
function getParsed () {
return _parsedWorld
}
function set (newWorld) {
_world = newWorld
_parsedWorld = parseWorld(newWorld)
}
// from 170kb to 20kb on 100x100 world
function parseWorld (world) {
var parsedWorld = [[]]
for(var x=0; x<world.length; x++) {
parsedWorld[x] = []
for(var y=0; y<world.length; y++) {
var tile = world[x][y]
parsedWorld[x][y] = {
vegetation: {
density: ~~tile.vegetation.density
},
entity: !!tile.entity,
eventData : {
rain : tile.eventData.rain.active
}
}
}
}
return parsedWorld
}