Skip to content
This repository has been archived by the owner on Feb 10, 2023. It is now read-only.

Commit

Permalink
feat(soba): adjust loaders
Browse files Browse the repository at this point in the history
  • Loading branch information
nartc committed Apr 15, 2022
1 parent 1a8fa0f commit 02dbfb7
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 14 deletions.
16 changes: 12 additions & 4 deletions libs/soba/loaders/src/lib/loader/loader.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { NgtStore, tapEffect } from '@angular-three/core';
import { NgtComponentStore, tapEffect } from '@angular-three/core';
import { CommonModule } from '@angular/common';
import {
AfterViewInit,
Expand All @@ -9,7 +9,7 @@ import {
NgZone,
ViewChild,
} from '@angular/core';
import { timer } from 'rxjs';
import { Observable, timer } from 'rxjs';
import { NgtSobaProgress } from '../progress/progress';

interface NgtSobaLoaderState {
Expand Down Expand Up @@ -103,10 +103,18 @@ interface NgtSobaLoaderState {
providers: [NgtSobaProgress],
})
export class NgtSobaLoader
extends NgtStore<NgtSobaLoaderState>
extends NgtComponentStore<NgtSobaLoaderState>
implements AfterViewInit
{
readonly vm$ = this.select(
readonly vm$: Observable<{
shown: boolean;
containerClass: string | undefined;
innerContainerClass: string | undefined;
dataClass: string | undefined;
barClass: string | undefined;
active: boolean;
progress: number;
}> = this.select(
this.select((s) => s.shown),
this.select((s) => s.loaderConfig),
this.sobaProgress.select((s) => s.active),
Expand Down
4 changes: 2 additions & 2 deletions libs/soba/loaders/src/lib/progress/progress.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { NgtStore } from '@angular-three/core';
import { NgtComponentStore } from '@angular-three/core';
import { Injectable } from '@angular/core';
import * as THREE from 'three';

Expand All @@ -12,7 +12,7 @@ interface NgtSobaProgressResult {
}

@Injectable()
export class NgtSobaProgress extends NgtStore<NgtSobaProgressResult> {
export class NgtSobaProgress extends NgtComponentStore<NgtSobaProgressResult> {
constructor() {
super();
let saveLastTotalLoaded = 0;
Expand Down
13 changes: 5 additions & 8 deletions libs/soba/loaders/src/lib/texture-loader/texture-loader.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { NgtCanvasStore, NgtLoader } from '@angular-three/core';
import { NgtLoader, NgtStore } from '@angular-three/core';
import { Injectable } from '@angular/core';
import { defer, map, Observable, tap } from 'rxjs';
import * as THREE from 'three';
Expand All @@ -8,10 +8,7 @@ export const IsObject = (url: any): url is Record<string, string> =>

@Injectable()
export class NgtTextureLoader {
constructor(
private canvasStore: NgtCanvasStore,
private loader: NgtLoader
) {}
constructor(private store: NgtStore, private loader: NgtLoader) {}

load<TInput extends string | string[] | Record<string, string>>(
input: TInput
Expand All @@ -29,10 +26,10 @@ export class NgtTextureLoader {
)
).pipe(
tap((textures: THREE.Texture | THREE.Texture[]) => {
const renderer = this.canvasStore.get((s) => s.renderer);
if (renderer) {
const gl = this.store.get((s) => s.gl);
if (gl) {
(Array.isArray(textures) ? textures : [textures]).forEach(
renderer.initTexture.bind(renderer)
gl.initTexture.bind(gl)
);
}
}),
Expand Down

0 comments on commit 02dbfb7

Please sign in to comment.