mirror of
https://github.com/sbrl/Nibriboard.git
synced 2018-01-10 21:33:49 +00:00
[client] Start creating chunk representation system
This commit is contained in:
parent
d582396f74
commit
4e2a27df94
3 changed files with 75 additions and 0 deletions
35
Nibriboard/ClientFiles/Chunk.js
Normal file
35
Nibriboard/ClientFiles/Chunk.js
Normal file
|
@ -0,0 +1,35 @@
|
|||
"use strict";
|
||||
|
||||
/**
|
||||
* Represents a single chunk on a plane.
|
||||
* Note that this is the client's representation of the chunk, so it's likely
|
||||
* to be a little different to the server's representation.
|
||||
*/
|
||||
class Chunk
|
||||
{
|
||||
/**
|
||||
* Creates a new chunk.
|
||||
* @param {ChunkReference} inChunkRef The location of the new chunk.
|
||||
*/
|
||||
constructor(inChunkRef)
|
||||
{
|
||||
this.chunkRef = inChunkRef;
|
||||
this.lines = [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether this chunk is located at the specified chunk reference.
|
||||
* @param {ChunkReference} otherChunkRef The chunk reference to check
|
||||
* ourselves against.
|
||||
* @return {bool} Whether this chunk is located at the
|
||||
* specified chunk reference.
|
||||
*/
|
||||
isAt(otherChunkRef)
|
||||
{
|
||||
if(this.chunkRef.toString() == otherChunkPos.toString())
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
export default Chunk;
|
23
Nibriboard/ClientFiles/ChunkCache.js
Normal file
23
Nibriboard/ClientFiles/ChunkCache.js
Normal file
|
@ -0,0 +1,23 @@
|
|||
"use strict";
|
||||
|
||||
class ChunkCache
|
||||
{
|
||||
constructor()
|
||||
{
|
||||
this.cache = new Map();
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the given chunk to the chunk cache.
|
||||
* @param {Chunk} chunkData The chunk to add to the cache.
|
||||
*/
|
||||
add(chunkData)
|
||||
{
|
||||
if(this.cache.contains(chunkData.chunkRef.toString()))
|
||||
throw new Error("Error: We already have a chunk at that location stored.");
|
||||
|
||||
this.cache.set(chunkData.toString(), chunkData);
|
||||
}
|
||||
}
|
||||
|
||||
export default ChunkCache;
|
17
Nibriboard/ClientFiles/ChunkReference.js
Normal file
17
Nibriboard/ClientFiles/ChunkReference.js
Normal file
|
@ -0,0 +1,17 @@
|
|||
"use strict";
|
||||
|
||||
import Vector from './Utilities/Vector.js';
|
||||
|
||||
class ChunkReference extends Vector
|
||||
{
|
||||
constructor(inPlaneName, inX, inY)
|
||||
{
|
||||
super(inX, inY);
|
||||
this.planeName = inPlaneName;
|
||||
}
|
||||
|
||||
toString()
|
||||
{
|
||||
return `ChunkReference: (${this.x}, ${this.y}, ${this.planeName})`;
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue