Smaler Save

This commit is contained in:
MasterGordon 2018-04-09 18:18:50 +02:00
parent d22facade7
commit f06c82ef72
3 changed files with 28 additions and 19 deletions

View File

@ -66,8 +66,8 @@ function save() {
for (var y = 0; y < 12; y++) { for (var y = 0; y < 12; y++) {
if (factorys[i].tiles[x][y] != 0) { if (factorys[i].tiles[x][y] != 0) {
game.factorys[i].tiles[x][y] = {} game.factorys[i].tiles[x][y] = {}
game.factorys[i].tiles[x][y].index = factorys[i].tiles[x][y].index game.factorys[i].tiles[x][y].i = factorys[i].tiles[x][y].i
game.factorys[i].tiles[x][y].direction = factorys[i].tiles[x][y].direction game.factorys[i].tiles[x][y].d = directions[factorys[i].tiles[x][y].direction].d
game.factorys[i].tiles[x][y].x = factorys[i].tiles[x][y].x game.factorys[i].tiles[x][y].x = factorys[i].tiles[x][y].x
game.factorys[i].tiles[x][y].y = factorys[i].tiles[x][y].y game.factorys[i].tiles[x][y].y = factorys[i].tiles[x][y].y
if (factorys[i].tiles[x][y].options != undefined) { if (factorys[i].tiles[x][y].options != undefined) {
@ -102,10 +102,13 @@ function loadGameData() {
for (var y = 0; y < 12; y++) { for (var y = 0; y < 12; y++) {
if (game.factorys[i].tiles[x][y] != 0) { if (game.factorys[i].tiles[x][y] != 0) {
var keys = Object.keys(game.factorys[i].tiles[x][y]) var keys = Object.keys(game.factorys[i].tiles[x][y])
factorys[i].tiles[x][y] = new tileClasses[game.factorys[i].tiles[x][y].index](game.factorys[i].tiles[x][y].x, game.factorys[i].tiles[x][y].y) factorys[i].tiles[x][y] = new tileClasses[game.factorys[i].tiles[x][y].i](game.factorys[i].tiles[x][y].x, game.factorys[i].tiles[x][y].y)
factorys[i].tiles[x][y].factory = factorys[i] factorys[i].tiles[x][y].factory = factorys[i]
for (var key = 0; key < keys.length; key++) { for (var key = 0; key < keys.length; key++) {
factorys[i].tiles[x][y][keys[key]] = game.factorys[i].tiles[x][y][keys[key]] if (keys[key] == "d")
factorys[i].tiles[x][y].direction = d[game.factorys[i].tiles[x][y]["d"]]
else
factorys[i].tiles[x][y][keys[key]] = game.factorys[i].tiles[x][y][keys[key]]
} }
} }
} }

View File

@ -7,7 +7,7 @@ class Conveyorbelt extends Tile {
super(x, y, factory) super(x, y, factory)
this.name = "conveyorbelt" this.name = "conveyorbelt"
this.hasNoInventory = true this.hasNoInventory = true
this.index = 0 this.i = 0
this.cost = [{ this.cost = [{
"id": 0, "id": 0,
"count": 20 "count": 20
@ -19,7 +19,6 @@ class Conveyorbelt extends Tile {
this.loadImages() this.loadImages()
} }
} }
tileClasses.push(Conveyorbelt)
class Treefarm extends Tile { class Treefarm extends Tile {
constructor(x, y, factory) { constructor(x, y, factory) {
@ -27,7 +26,7 @@ class Treefarm extends Tile {
this.maxwork = 96 * 5 this.maxwork = 96 * 5
this.currentwork = 0 this.currentwork = 0
this.name = "treefarm" this.name = "treefarm"
this.index = 1 this.i = 1
this.hasNoInventory = true this.hasNoInventory = true
this.cost = [{ this.cost = [{
"id": 0, "id": 0,
@ -49,7 +48,6 @@ class Treefarm extends Tile {
} }
} }
} }
tileClasses.push(Treefarm)
class Saw extends Tile { class Saw extends Tile {
constructor(x, y, factory) { constructor(x, y, factory) {
@ -57,7 +55,7 @@ class Saw extends Tile {
this.maxwork = 48 this.maxwork = 48
this.currentwork = 0 this.currentwork = 0
this.name = "saw" this.name = "saw"
this.index = 2 this.i = 2
this.cost = [{ this.cost = [{
"id": 0, "id": 0,
"count": 750 "count": 750
@ -94,7 +92,6 @@ class Saw extends Tile {
} }
} }
} }
tileClasses.push(Saw)
class Charcoalmeiler extends Tile { class Charcoalmeiler extends Tile {
constructor(x, y, factory) { constructor(x, y, factory) {
@ -102,7 +99,7 @@ class Charcoalmeiler extends Tile {
this.maxwork = 96 * 10 this.maxwork = 96 * 10
this.currentwork = 0 this.currentwork = 0
this.name = "charcoalmeiler" this.name = "charcoalmeiler"
this.index = 3 this.i = 3
this.cost = [{ this.cost = [{
"id": 0, "id": 0,
"count": 1000 "count": 1000
@ -146,13 +143,12 @@ class Charcoalmeiler extends Tile {
} }
} }
} }
tileClasses.push(Charcoalmeiler)
class Quarry extends Tile { class Quarry extends Tile {
constructor(x, y, factory) { constructor(x, y, factory) {
super(x, y, factory) super(x, y, factory)
this.maxwork = 96 * 3 this.maxwork = 96 * 3
this.index = 4 this.i = 4
this.currentwork = 0 this.currentwork = 0
this.name = "quarry" this.name = "quarry"
this.hasNoInventory = true this.hasNoInventory = true
@ -179,14 +175,13 @@ class Quarry extends Tile {
} }
} }
} }
tileClasses.push(Quarry)
class Collector extends Tile { class Collector extends Tile {
constructor(x, y, factory) { constructor(x, y, factory) {
super(x, y, factory) super(x, y, factory)
this.name = "collector" this.name = "collector"
this.hasNoInventory = true this.hasNoInventory = true
this.index = 5 this.i = 5
this.cost = [{ this.cost = [{
"id": 0, "id": 0,
"count": 50 "count": 50
@ -206,14 +201,13 @@ class Collector extends Tile {
} }
} }
} }
tileClasses.push(Collector)
class Spliter extends Tile { class Spliter extends Tile {
constructor(x, y, factory) { constructor(x, y, factory) {
super(x, y, factory) super(x, y, factory)
this.name = "spliter" this.name = "spliter"
this.hasNoInventory = true this.hasNoInventory = true
this.index = 6 this.i = 6
this.odd = true this.odd = true
this.cost = [{ this.cost = [{
"id": 0, "id": 0,
@ -266,7 +260,6 @@ class Spliter extends Tile {
} }
} }
} }
tileClasses.push(Spliter)
class Warehouse extends Tile { class Warehouse extends Tile {
constructor(x, y, factory) { constructor(x, y, factory) {
@ -275,7 +268,7 @@ class Warehouse extends Tile {
this.hasNoInventory = true this.hasNoInventory = true
this.maxwork = 48 * 10 this.maxwork = 48 * 10
this.sellPower = 500 this.sellPower = 500
this.index = 7 this.i = 7
this.cost = [{ this.cost = [{
"id": 0, "id": 0,
"count": 20000 "count": 20000
@ -310,4 +303,11 @@ class Warehouse extends Tile {
} }
} }
} }
tileClasses.push(Conveyorbelt)
tileClasses.push(Treefarm)
tileClasses.push(Saw)
tileClasses.push(Charcoalmeiler)
tileClasses.push(Quarry)
tileClasses.push(Collector)
tileClasses.push(Spliter)
tileClasses.push(Warehouse) tileClasses.push(Warehouse)

View File

@ -1,26 +1,32 @@
var directions = { var directions = {
"right": { "right": {
"d": 0,
"degree": 0, "degree": 0,
"dx": 1, "dx": 1,
"dy": 0 "dy": 0
}, },
"down": { "down": {
"d": 1,
"degree": 90, "degree": 90,
"dx": 0, "dx": 0,
"dy": 1 "dy": 1
}, },
"left": { "left": {
"d": 2,
"degree": 180, "degree": 180,
"dx": -1, "dx": -1,
"dy": 0 "dy": 0
}, },
"up": { "up": {
"d": 3,
"degree": 270, "degree": 270,
"dx": 0, "dx": 0,
"dy": -1 "dy": -1
} }
} }
var d = ["right","down","left","up"]
//Umrechnung von Grad zu Bogenmaß //Umrechnung von Grad zu Bogenmaß
var TO_RADIANS = Math.PI / 180; var TO_RADIANS = Math.PI / 180;