Skip to content

Commit

Permalink
makes Color serializable for redraw, add db types
Browse files Browse the repository at this point in the history
  • Loading branch information
hiddenist committed Dec 31, 2023
1 parent a60b13f commit bc63fbd
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 12 deletions.
4 changes: 2 additions & 2 deletions libs/drawing-engine/src/engine/CanvasHistory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ export class CanvasHistory {
const current = await this.getCurrentIncompleteEntry()
current.entry.actions.push(toolInfo)

await this.db.actions.put(current.key, current.entry)
await this.db.actions.put(current.entry)
return current
}

Expand Down Expand Up @@ -194,7 +194,7 @@ export class CanvasHistory {
const nextKey = this.history[0]
drawEntry = await this.db.actions.get(nextKey)
} else {
this.db.actions.put(key, state)
this.db.actions.put(state)
drawEntry = state
}

Expand Down
8 changes: 4 additions & 4 deletions libs/drawing-engine/src/engine/Database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export class Database<SchemaStoreNames extends string, Schema extends Record<Sch
public getStore<StoreName extends SchemaStoreNames>(storeName: StoreName) {
return {
add: (state: Schema[StoreName]) => this.add(storeName, state),
put: (key: IDBValidKey, state: Schema[StoreName]) => this.put(storeName, key, state),
put: (state: Schema[StoreName], key?: IDBValidKey) => this.put(storeName, state, key),
count: () => this.count(storeName),
get: (key: IDBValidKey) => this.get(storeName, key),
getAll: () => this.getAll(storeName),
Expand All @@ -89,11 +89,11 @@ export class Database<SchemaStoreNames extends string, Schema extends Record<Sch
}
}

public get<StoreName extends SchemaStoreNames>(storeName: StoreName, key: IDBValidKey) {
public get<StoreName extends SchemaStoreNames>(storeName: StoreName, key: IDBValidKey): Promise<Schema[StoreName]> {
return this.promisifyRequest(this.getObjectStore(storeName, "readonly").get(key))
}

public getAll<StoreName extends SchemaStoreNames>(storeName: StoreName) {
public getAll<StoreName extends SchemaStoreNames>(storeName: StoreName): Promise<Schema[StoreName][]> {
return this.promisifyRequest(this.getObjectStore(storeName, "readonly").getAll())
}

Expand All @@ -109,7 +109,7 @@ export class Database<SchemaStoreNames extends string, Schema extends Record<Sch
return this.promisifyRequest(this.getObjectStore(storeName, "readwrite").add(state))
}

public put<StoreName extends SchemaStoreNames>(storeName: StoreName, key: IDBValidKey, state: Schema[StoreName]) {
public put<StoreName extends SchemaStoreNames>(storeName: StoreName, state: Schema[StoreName], key?: IDBValidKey) {
return this.promisifyRequest(this.getObjectStore(storeName, "readwrite").put(state, key))
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export abstract class PositionColorProgramBase extends BaseProgram<
}

protected setColor(color: Color): typeof this {
this.gl.uniform3fv(this.getUniformLocation("color"), color.vec3)
this.gl.uniform3fv(this.getUniformLocation("color"), color.vector)
return this
}

Expand Down
6 changes: 1 addition & 5 deletions libs/shared/src/lib/Color.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export type HsvArray = [
export class Color {
static readonly BLACK = new Color(0, 0, 0)
static readonly WHITE = new Color(255, 255, 255)
private vector: Uint8ClampedArray
public readonly vector: Uint8ClampedArray

public constructor(colorString: string, _?: never, __?: never, ___?: never)
public constructor(vector: Readonly<Uint8ClampedArray>, _?: never, __?: never, ___?: never)
Expand Down Expand Up @@ -79,10 +79,6 @@ export class Color {
throw new Error("Invalid color parameters")
}

get vec3(): Readonly<Uint8ClampedArray> {
return this.vector
}

public copy(): Color {
return new Color(this.vector)
}
Expand Down

0 comments on commit bc63fbd

Please sign in to comment.