Skip to content

Commit ce47d54

Browse files
Anthony BlountAnthony Blount
authored andcommitted
working on generic map data object
1 parent f65a8de commit ce47d54

File tree

4 files changed

+69
-7
lines changed

4 files changed

+69
-7
lines changed

public/js/server/testClient.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
const net = require('net');
22
const InventoryData = require('../shared/InventoryData');
3+
const InventoryData = require('../shared/MapData');
34

45
/**
56
* Used to make sure the server is working properly. Attempts to replicate
@@ -14,12 +15,13 @@ class testClient {
1415
constructor(testData) {
1516

1617
this.testData = testData;
17-
this.inventory = new InventoryData(this.testData.internalInventory);
18+
this.inventory = new InventoryData(this.testData.internalInventory.meta);
1819
for (let slot of this.testData.internalInventory.slots) {
1920
this.inventory.setSlot(slot);
2021
}
2122
this.equipped;
22-
this.map;
23+
this.map = new MapData();
24+
this.map.setFromGeolyzerScan(this.testData.geolyzerScan);
2325
this.position = this.testData.position;
2426
this.components = this.testData.components;
2527

@@ -35,7 +37,7 @@ class testClient {
3537
this.commandMap = {
3638

3739
scanArea: (scanLevel)=>{
38-
this.sendWithCost('map data', this.testData.scan);
40+
this.sendWithCost('map data', this.testData.geolyzerScan);
3941
},
4042

4143
viewInventory: ()=>{
@@ -176,10 +178,10 @@ class testClient {
176178

177179
/**
178180
* Used to make the test map data a little more like real geolyzer scans.
179-
* @param {object} scan
181+
* @param {object} geolyzerScan
180182
*/
181-
addNoise(scan) {
182-
let mapData = this.testData.scan.data;
183+
addNoise(geolyzerScan) {
184+
let mapData = this.testData.geolyzerScan.data;
183185
for (var key in mapData) {
184186
if (mapData[key] == 1) {
185187
mapData[key] = Math.random() * 6;

public/js/server/testData.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ module.exports = {
122122
],
123123
},
124124

125-
scan: {
125+
geolyzerScan: {
126126
x: 0,
127127
z: 0,
128128
y: 0,

public/js/shared/InventoryData.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
let validators = require('./fromRobotSchemas.js');
12
/**
23
* Used to simulate an in-game inventory for the test client
34
* and to represent the in-game inventory on the web client.
@@ -9,6 +10,7 @@ class InventoryData {
910
* @param {object} inventoryMeta
1011
*/
1112
constructor(inventoryMeta) {
13+
validators.inventoryMeta(inventoryMeta);
1214
this.size = inventoryMeta.meta.size;
1315
this.side = inventoryMeta.meta.side;
1416
this.selected = inventoryMeta.meta.selected;
@@ -20,6 +22,7 @@ class InventoryData {
2022
* @param {object} inventorySlot
2123
*/
2224
setSlot(inventorySlot) {
25+
validators.inventorySlot(inventorySlot);
2326
this.slots[inventorySlot.slotNum] = inventorySlot.contents;
2427
}
2528

public/js/shared/MapData.js

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
let validators = require('./fromRobotSchemas.js');
2+
/**
3+
* An organized way to store map data.
4+
*/
5+
class MapData {
6+
7+
/**
8+
* An organized way to store map data.
9+
*/
10+
constructor() {
11+
this.map = {};
12+
}
13+
14+
/**
15+
* Retrieve block data from the map if it exists.
16+
* @param {number} x
17+
* @param {number} y
18+
* @param {number} z
19+
* @returns {object | false}
20+
*/
21+
get(x, y, z) {
22+
let result;
23+
if (this.map[x] && this.map[x][y] && this.map[x][y][z]) {
24+
result = this.map[x][y][z];
25+
}
26+
else {result = false;}
27+
return result;
28+
}
29+
30+
/**
31+
* Store block data in or remove it from the map.
32+
* @param {number} x
33+
* @param {number} y
34+
* @param {number} z
35+
* @param {object} blockData
36+
* @returns {object}
37+
*/
38+
set(x, y, z, blockData) {
39+
if (!this.map[x]) {this.map[x] = {};}
40+
if (!this.map[x][y]) {this.map[x][y] = {};}
41+
this.map[x][y][z] = blockData;
42+
return blockData;
43+
}
44+
45+
/**
46+
* Store block data contained in the geolyzer scan format
47+
* @param {object} geolyzerScan
48+
*/
49+
setFromGeolyzerScan(geolyzerScan) {
50+
validators.geolyzerScan(geolyzerScan);
51+
52+
}
53+
54+
}
55+
56+
try {module.exports = InventoryData;}
57+
catch(e) {;}

0 commit comments

Comments
 (0)