Comparing version 0.3.3 to 0.3.4
export type AssetLoader<T = any> = (key: string) => Promise<T>; | ||
type InferAsset<Loader extends AssetLoader<any>> = Loader extends AssetLoader<infer T> ? T : never; | ||
export declare class Assets<Loaders extends Record<string, AssetLoader>> { | ||
export declare class Assets<Loaders extends Record<string, any>> { | ||
private _loaders; | ||
@@ -8,6 +7,5 @@ private handlePool; | ||
constructor(_loaders: Loaders); | ||
load: <LoaderName extends keyof Loaders>(loader: LoaderName, key: string) => Promise<InferAsset<Loaders[LoaderName]>>; | ||
immediate: <LoaderName extends keyof Loaders>(loader: LoaderName, key: string) => InferAsset<Loaders[LoaderName]> | null; | ||
load: <LoaderName extends (string & {}) | keyof Loaders>(loader: LoaderName, key: string) => Promise<Loaders[LoaderName]>; | ||
immediate: <LoaderName extends (string & {}) | keyof Loaders>(loader: LoaderName, key: string) => Loaders[LoaderName] | null; | ||
private getKey; | ||
} | ||
export {}; |
@@ -6,3 +6,3 @@ import { ObjectPool } from './internal/objectPool.js'; | ||
this._loaders = _loaders; | ||
this.handlePool = new ObjectPool(() => new ResourceHandle(), h => h.reset()); | ||
this.handlePool = new ObjectPool(() => new ResourceHandle(), (h) => h.reset()); | ||
this.handles = new Map(); | ||
@@ -9,0 +9,0 @@ this.load = (loader, key) => { |
@@ -1,2 +0,1 @@ | ||
import { AssetLoader } from './Assets.js'; | ||
export * from './Game.js'; | ||
@@ -12,6 +11,4 @@ export * from './Query.js'; | ||
export interface Globals { | ||
[key: string]: any; | ||
} | ||
export interface AssetLoaders { | ||
[key: string]: AssetLoader; | ||
} |
@@ -19,3 +19,3 @@ export class Pointer { | ||
if (ev.type === 'pointerdown') { | ||
if (ev.button === 1) { | ||
if (ev.button === 0) { | ||
this._primaryDown = true; | ||
@@ -30,3 +30,3 @@ this._primaryPressed = true; | ||
else if (ev.type === 'pointerup') { | ||
if (ev.button === 1) { | ||
if (ev.button === 0) { | ||
this._primaryUp = true; | ||
@@ -33,0 +33,0 @@ this._primaryPressed = false; |
@@ -8,2 +8,3 @@ import { ArchetypeManager } from './ArchetypeManager.js'; | ||
import { EventSubscriber } from '@a-type/utils'; | ||
import { defaultLogger } from './logger.js'; | ||
const withA = 100; | ||
@@ -26,17 +27,8 @@ const withAB = 101; | ||
beforeEach(() => { | ||
const archetypeManager = new ArchetypeManager({ | ||
componentManager: { | ||
count: 10, | ||
getTypeName: () => 'TEST MOCK', | ||
}, | ||
entityPool: { | ||
acquire() { | ||
return new Entity(); | ||
}, | ||
release() { }, | ||
}, | ||
}); | ||
events = new EventSubscriber(); | ||
game = events; | ||
game.archetypeManager = archetypeManager; | ||
game.componentManager = { | ||
count: 10, | ||
getTypeName: () => 'TEST MOCK', | ||
}; | ||
game.entityPool = { | ||
@@ -48,2 +40,5 @@ acquire() { | ||
}; | ||
game.logger = defaultLogger; | ||
const archetypeManager = new ArchetypeManager(game); | ||
game.archetypeManager = archetypeManager; | ||
// bootstrap some testing archetypes | ||
@@ -50,0 +45,0 @@ addEntity(withA, [ComponentA.create()]); |
@@ -8,6 +8,6 @@ import { Game } from './index.js'; | ||
private getOrCreateGlobalHandle; | ||
load: <Key extends keyof ResourceMap>(key: Key) => Promise<ResourceMap[Key]>; | ||
resolve: <Key extends keyof ResourceMap>(key: Key, value: ResourceMap[Key]) => void; | ||
immediate: <Key extends keyof ResourceMap>(key: Key) => ResourceMap[Key] | null; | ||
remove: (key: keyof ResourceMap) => void; | ||
load: <Key extends (string & {}) | keyof ResourceMap>(key: Key) => Promise<Key extends keyof ResourceMap ? ResourceMap[Key] : any>; | ||
resolve: <Key extends (string & {}) | keyof ResourceMap>(key: Key, value: Key extends keyof ResourceMap ? ResourceMap[Key] : any) => void; | ||
immediate: <Key extends (string & {}) | keyof ResourceMap>(key: Key) => (Key extends keyof ResourceMap ? ResourceMap[Key] : any) | null; | ||
remove: (key: keyof ResourceMap | (string & {})) => void; | ||
} |
{ | ||
"name": "0g", | ||
"version": "0.3.3", | ||
"version": "0.3.4", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "type": "module", |
@@ -5,7 +5,8 @@ import { ObjectPool } from './internal/objectPool.js'; | ||
export type AssetLoader<T = any> = (key: string) => Promise<T>; | ||
type InferAsset<Loader extends AssetLoader<any>> = | ||
Loader extends AssetLoader<infer T> ? T : never; | ||
export class Assets<Loaders extends Record<string, AssetLoader>> { | ||
private handlePool = new ObjectPool(() => new ResourceHandle(), h => h.reset()); | ||
export class Assets<Loaders extends Record<string, any>> { | ||
private handlePool = new ObjectPool( | ||
() => new ResourceHandle(), | ||
(h) => h.reset(), | ||
); | ||
private handles = new Map<string, ResourceHandle>(); | ||
@@ -15,3 +16,3 @@ | ||
load = <LoaderName extends keyof Loaders>( | ||
load = <LoaderName extends keyof Loaders | (string & {})>( | ||
loader: LoaderName, | ||
@@ -24,8 +25,10 @@ key: string, | ||
this.handles.set(this.getKey(loader, key), handle); | ||
this._loaders[loader](key).then((value) => handle!.resolve(value)); | ||
this._loaders[loader](key).then((value: AssetLoader) => | ||
handle!.resolve(value), | ||
); | ||
} | ||
return handle!.promise as Promise<InferAsset<Loaders[LoaderName]>>; | ||
return handle!.promise as Promise<Loaders[LoaderName]>; | ||
}; | ||
immediate = <LoaderName extends keyof Loaders>( | ||
immediate = <LoaderName extends keyof Loaders | (string & {})>( | ||
loader: LoaderName, | ||
@@ -36,7 +39,7 @@ key: string, | ||
if (!handle) return null; | ||
return handle.value as InferAsset<Loaders[LoaderName]> | null; | ||
return handle.value as Loaders[LoaderName] | null; | ||
}; | ||
private getKey = (loader: keyof Loaders, key: string) => | ||
private getKey = (loader: keyof Loaders | (string & {}), key: string) => | ||
`${loader.toString()}:${key}`; | ||
} |
@@ -1,3 +0,1 @@ | ||
import { AssetLoader } from './Assets.js'; | ||
export * from './Game.js'; | ||
@@ -13,8 +11,4 @@ export * from './Query.js'; | ||
export interface Globals { | ||
[key: string]: any; | ||
} | ||
export interface Globals {} | ||
export interface AssetLoaders { | ||
[key: string]: AssetLoader; | ||
} | ||
export interface AssetLoaders {} |
@@ -25,3 +25,3 @@ export class Pointer { | ||
if (ev.type === 'pointerdown') { | ||
if (ev.button === 1) { | ||
if (ev.button === 0) { | ||
this._primaryDown = true; | ||
@@ -34,3 +34,3 @@ this._primaryPressed = true; | ||
} else if (ev.type === 'pointerup') { | ||
if (ev.button === 1) { | ||
if (ev.button === 0) { | ||
this._primaryUp = true; | ||
@@ -37,0 +37,0 @@ this._primaryPressed = false; |
@@ -15,2 +15,3 @@ import { ArchetypeManager } from './ArchetypeManager.js'; | ||
import { ComponentInstanceInternal } from './Component2.js'; | ||
import { defaultLogger } from './logger.js'; | ||
@@ -37,17 +38,8 @@ const withA = 100; | ||
beforeEach(() => { | ||
const archetypeManager = new ArchetypeManager({ | ||
componentManager: { | ||
count: 10, | ||
getTypeName: () => 'TEST MOCK', | ||
}, | ||
entityPool: { | ||
acquire() { | ||
return new Entity(); | ||
}, | ||
release() {}, | ||
}, | ||
} as any); | ||
events = new EventSubscriber(); | ||
game = events as any; | ||
(game as any).archetypeManager = archetypeManager; | ||
(game as any).componentManager = { | ||
count: 10, | ||
getTypeName: () => 'TEST MOCK', | ||
}; | ||
(game as any).entityPool = { | ||
@@ -59,2 +51,5 @@ acquire() { | ||
}; | ||
(game as any).logger = defaultLogger; | ||
const archetypeManager = new ArchetypeManager(game); | ||
(game as any).archetypeManager = archetypeManager; | ||
@@ -61,0 +56,0 @@ // bootstrap some testing archetypes |
@@ -23,11 +23,11 @@ import { Game } from './index.js'; | ||
load = <Key extends keyof ResourceMap>(key: Key) => { | ||
load = <Key extends keyof ResourceMap | (string & {})>(key: Key) => { | ||
return this.getOrCreateGlobalHandle(key).promise as Promise< | ||
ResourceMap[Key] | ||
Key extends keyof ResourceMap ? ResourceMap[Key] : any | ||
>; | ||
}; | ||
resolve = <Key extends keyof ResourceMap>( | ||
resolve = <Key extends keyof ResourceMap | (string & {})>( | ||
key: Key, | ||
value: ResourceMap[Key], | ||
value: Key extends keyof ResourceMap ? ResourceMap[Key] : any, | ||
) => { | ||
@@ -38,7 +38,9 @@ this.getOrCreateGlobalHandle(key).resolve(value); | ||
immediate = <Key extends keyof ResourceMap>(key: Key) => { | ||
return this.getOrCreateGlobalHandle(key).value as ResourceMap[Key] | null; | ||
immediate = <Key extends keyof ResourceMap | (string & {})>(key: Key) => { | ||
return this.getOrCreateGlobalHandle(key).value as | ||
| (Key extends keyof ResourceMap ? ResourceMap[Key] : any) | ||
| null; | ||
}; | ||
remove = (key: keyof ResourceMap) => { | ||
remove = (key: keyof ResourceMap | (string & {})) => { | ||
const value = this.handles.get(key); | ||
@@ -45,0 +47,0 @@ if (value) { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
262888
4919