Skip to content

Commit

Permalink
feat: Adds more typesafe options to the store.
Browse files Browse the repository at this point in the history
  • Loading branch information
Bjeaurn committed Sep 29, 2019
1 parent f18b58a commit 8ceb5a9
Showing 1 changed file with 37 additions and 29 deletions.
66 changes: 37 additions & 29 deletions src/gine/store.ts
Original file line number Diff line number Diff line change
@@ -1,32 +1,40 @@
import { ImageAsset, ImageOptions, SpriteOptions, SpriteAsset } from './image'
import { ImageAsset, ImageOptions, SpriteAsset, SpriteOptions } from './image'

export class Store {
private database: { [key: string]: any } = []

constructor() {}

public store(key: string, val: any): void {
this.database[key] = val
}

public get(key: string): any | undefined {
return this.database[key]
}

public image(key: string, src: string, options?: ImageOptions): void {
const img = new ImageAsset(key, src, options)
this.store(key, img)
}

public sprite(key: string, src: string, options?: SpriteOptions): void {
const img = new SpriteAsset(key, src, options)
this.store(key, img)
}

// This function does not work yet!
public select(key: string, val: string): any[] {
return this.database.filter((obj: any) => {
return obj[key] === val
})
}
private database: { [key: string]: any } = []

constructor() {}

public store(key: string, val: any): void {
this.database[key] = val
}

public image(key: string, src: string, options?: ImageOptions): void {
const img = new ImageAsset(key, src, options)
this.store(key, img)
}

public sprite(key: string, src: string, options?: SpriteOptions): void {
const img = new SpriteAsset(key, src, options)
this.store(key, img)
}

public get<T = any>(key: string): T | undefined {
return this.database[key]
}

public getImage(key: string): ImageAsset | undefined {
return this.get<ImageAsset>(key)
}

public getSprite(key: string): SpriteAsset | undefined {
return this.get<SpriteAsset>(key)
}

// This function does not work yet!
public select(key: string, val: string): any[] {
return this.database.filter((obj: any) => {
return obj[key] === val
})
}
}

0 comments on commit 8ceb5a9

Please sign in to comment.