Skip to content

Commit

Permalink
use signal decorators
Browse files Browse the repository at this point in the history
  • Loading branch information
spearwolf committed Nov 16, 2023
1 parent 6c2a679 commit 4cf4d60
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 62 deletions.
14 changes: 14 additions & 0 deletions packages/twopoint5d-elements-e2e/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,19 @@
"tailwindcss": "^3.3.5",
"typescript": "^5.2.2",
"vite": "^4.4.5"
},
"nx": {
"targets": {
"dev": {
"dependsOn": [
"^build"
]
},
"test:ui": {
"dependsOn": [
"^build"
]
}
}
}
}
75 changes: 13 additions & 62 deletions packages/twopoint5d/src/texture/TextureResource.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {eventize, type Eventize} from '@spearwolf/eventize';
import {batch, createEffect, createSignal, value, type SignalFuncs, type SignalReader} from '@spearwolf/signalize';
import {signal, signalReader} from '@spearwolf/signalize/decorators';
import {ImageLoader, type Texture, type WebGLRenderer} from 'three';
import type {TextureAtlas} from './TextureAtlas.js';
import {TextureCoords} from './TextureCoords.js';
Expand Down Expand Up @@ -81,16 +82,11 @@ export class TextureResource {

// TODO static fromAtlas()

#renderer = createSignal<WebGLRenderer | undefined>();
#imageUrl: SignalFuncs<string | undefined> = createSignal();
#imageCoords: SignalFuncs<TextureCoords | undefined> = createSignal(undefined, {compareFn: cmpTexCoords});
#atlasUrl?: SignalFuncs<string | undefined>;
#atlas?: SignalFuncs<TextureAtlas | undefined>;
#tileSetOptions?: SignalFuncs<TileSetOptions | undefined>;
#tileSet?: SignalFuncs<TileSet | undefined>;
#textureClasses: SignalFuncs<TextureOptionClasses[] | undefined> = createSignal(undefined, {compareFn: cmpTexClasses});
#textureFactory: SignalFuncs<TextureFactory | undefined> = createSignal();
#texture: SignalFuncs<Texture | undefined> = createSignal();

#createTileSetOptionsSignal(tileSetOptions: TileSetOptions | undefined) {
if (this.#tileSetOptions == null) {
Expand All @@ -103,29 +99,11 @@ export class TextureResource {

refCount: number = 0;

get imageUrl(): string | undefined {
return value(this.#imageUrl[0]);
}

get imageUrl$(): SignalReader<string | undefined> {
return this.#imageUrl[0];
}
@signal({readAsValue: true}) accessor imageUrl: string | undefined;
@signalReader() accessor imageUrl$: SignalReader<string | undefined>;

set imageUrl(value: string | undefined) {
this.#imageUrl[1](value);
}

get imageCoords(): TextureCoords | undefined {
return value(this.#imageCoords[0]);
}

get imageCoords$(): SignalReader<TextureCoords | undefined> {
return this.#imageCoords[0];
}

set imageCoords(value: TextureCoords | undefined) {
this.#imageCoords[1](value);
}
@signal({readAsValue: true, compareFn: cmpTexCoords}) accessor imageCoords: TextureCoords | undefined;
@signalReader() accessor imageCoords$: SignalReader<TextureCoords | undefined>;

get atlasUrl(): string | undefined {
return this.#atlasUrl && value(this.#atlasUrl[0]);
Expand Down Expand Up @@ -198,41 +176,14 @@ export class TextureResource {
this.#textureClasses[1](value);
}

get textureFactory(): TextureFactory | undefined {
return value(this.#textureFactory[0]);
}
@signal({readAsValue: true}) accessor textureFactory: TextureFactory | undefined;
@signalReader() accessor textureFactory$: SignalReader<TextureFactory | undefined>;

get textureFactory$(): SignalReader<TextureFactory | undefined> {
return this.#textureFactory[0];
}
@signal({readAsValue: true}) accessor texture: Texture | undefined;
@signalReader() accessor texture$: SignalReader<Texture | undefined>;

set textureFactory(value: TextureFactory | undefined) {
this.#textureFactory[1](value);
}

get texture(): Texture | undefined {
return value(this.#texture[0]);
}

get texture$(): SignalReader<Texture | undefined> {
return this.#texture[0];
}

set texture(value: Texture | undefined) {
this.#texture[1](value);
}

get renderer(): WebGLRenderer | undefined {
return value(this.#renderer[0]);
}

get renderer$(): SignalReader<WebGLRenderer | undefined> {
return this.#renderer[0];
}

set renderer(value: WebGLRenderer | undefined) {
this.#renderer[1](value);
}
@signal({readAsValue: true}) accessor renderer: WebGLRenderer | undefined;
@signalReader() accessor renderer$: SignalReader<WebGLRenderer | undefined>;

#load = false;

Expand Down Expand Up @@ -294,9 +245,9 @@ export class TextureResource {
}
}, [this.textureFactory$, this.imageUrl$]);

if (this.#tileSetOptions) {
if (this.tileSetOptions) {
createEffect(async () => {
if (this.#imageCoords && this.#tileSetOptions) {
if (this.imageCoords && this.tileSetOptions) {
this.tileSet = new TileSet(this.imageCoords, this.tileSetOptions);
}
}, [this.imageCoords$, this.tileSetOptions$]);
Expand Down
3 changes: 3 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 4cf4d60

Please sign in to comment.