a whole load of work in progress
This commit is contained in:
parent
caec0b8ac9
commit
26ba098183
63 changed files with 3234 additions and 321 deletions
36
static/wall.js
Normal file
36
static/wall.js
Normal file
|
@ -0,0 +1,36 @@
|
|||
import { OnlineUsers } from "./online-users.js";
|
||||
|
||||
export class Chunk {
|
||||
constructor(size) {
|
||||
this.canvas = new OffscreenCanvas(size, size);
|
||||
this.ctx = this.canvas.getContext("2d");
|
||||
}
|
||||
}
|
||||
|
||||
export class Wall {
|
||||
#chunks = new Map();
|
||||
onlineUsers = new OnlineUsers();
|
||||
|
||||
constructor(chunkSize) {
|
||||
this.chunkSize = chunkSize;
|
||||
}
|
||||
|
||||
static chunkKey(x, y) {
|
||||
return `(${x},${y})`;
|
||||
}
|
||||
|
||||
getChunk(x, y) {
|
||||
return this.#chunks.get(Wall.chunkKey(x, y));
|
||||
}
|
||||
|
||||
getOrCreateChunk(x, y) {
|
||||
let key = Wall.chunkKey(x, y);
|
||||
if (this.#chunks.has(key)) {
|
||||
return this.#chunks.get(key);
|
||||
} else {
|
||||
let chunk = new Chunk(this.chunkSize);
|
||||
this.#chunks.set(key, chunk);
|
||||
return chunk;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue