Skip to content

Commit

Permalink
tabs
Browse files Browse the repository at this point in the history
  • Loading branch information
guiltygyoza committed Sep 19, 2024
1 parent 8e6331d commit 319934b
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions examples/grid/src/objects/grid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,24 @@ import {
export class Grid implements CRO {
operations: string[] = ["addUser", "moveUser"];
semanticsType: SemanticsType = SemanticsType.pair;
positions: Map<string, { x: number, y: number }>;
positions: Map<string, { x: number, y: number }>;

constructor() {
this.positions = new Map<string, { x: number, y: number }>();
}

addUser(userId: string, color: string): void {
this._addUser(userId, color);
}
addUser(userId: string, color: string): void {
this._addUser(userId, color);
}

private _addUser(userId: string, color: string): void {
const userColorString = `${userId}:${color}`;
this.positions.set(userColorString, {x: 0, y: 0});
}

moveUser(userId: string, direction: string): void {
this._moveUser(userId, direction);
}
moveUser(userId: string, direction: string): void {
this._moveUser(userId, direction);
}

private _moveUser(userId: string, direction: string): void {
const userColorString = [...this.positions.keys()].find(u => u.startsWith(`${userId}:`));
Expand Down Expand Up @@ -59,7 +59,7 @@ export class Grid implements CRO {
getUserPosition(userColorString: string): { x: number, y: number } | undefined {
const position = this.positions.get(userColorString);
if (position) {
return position
return position;
}
return undefined;
}
Expand All @@ -69,10 +69,10 @@ export class Grid implements CRO {
}

mergeCallback(operations: Operation[]): void {
// reset this.positions
this.positions = new Map<string, { x: number, y: number }>();
// reset this.positions
this.positions = new Map<string, { x: number, y: number }>();

// apply operations to this.positions
// apply operations to this.positions
for (const op of operations) {
if (!op.value) continue;
switch (op.type) {
Expand All @@ -88,7 +88,7 @@ export class Grid implements CRO {
}
}
}
}
}
}

export function createGrid(): Grid {
Expand Down

0 comments on commit 319934b

Please sign in to comment.