Skip to content

Commit

Permalink
refactor: use blueprint instead of factory
Browse files Browse the repository at this point in the history
  • Loading branch information
Neosoulink committed Dec 11, 2023
1 parent 2c352cd commit df7fcdc
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,20 @@ export interface ExperienceProps {
onDestruct?: () => unknown;
}

export abstract class ExperienceFactory implements ExperienceBase {
export abstract class ExperienceBlueprint implements ExperienceBase {
/**
* Self class reference. Used for *singleton* pattern.
*
* @inheritdoc Logic should be implemented in the child constructor, passing the `this` to the `_self`
* */
protected static _self?: ExperienceFactory;
protected static _self?: ExperienceBlueprint;
protected _onConstruct?: () => unknown;
protected _onDestruct?: () => unknown;
/** [`quick-threejs`](https://www.npmjs.com/package/quick-threejs) instance. */
readonly app!: QuickThree;
/** To make the singleton logic, refer to the {@link ExperienceFactory._self `#_self`} declaration */
constructor(_?: ExperienceProps | ExperienceFactory) {
if (!(_ instanceof ExperienceFactory) && _) {
/** To make the singleton logic, refer to the {@link ExperienceBlueprint._self `#_self`} declaration */
constructor(_?: ExperienceProps | ExperienceBlueprint) {
if (!(_ instanceof ExperienceBlueprint) && _) {
this.app = new QuickThree(
{
enableDebug: true,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import { EventEmitter } from "events";

// BLUEPRINTS
import type { ExperienceFactory } from "./Experience.factory";
import type { ExperienceBlueprint } from "./Experience.blueprint";

// INTERFACES
import type { ExperienceBase } from "@/interfaces/experienceBase";

/** Represent a class that depend on {@link ExperienceFactory}. */
export abstract class ExperienceBasedFactory
/** Represent a class that depend on {@link ExperienceBlueprint}. */
export abstract class ExperienceBasedBlueprint
extends EventEmitter
implements ExperienceBase
{
protected abstract readonly _experience: ExperienceFactory;
protected abstract readonly _experience: ExperienceBlueprint;

public abstract construct(): unknown;
public abstract destruct(): unknown;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ export interface ModelChildrenTextures {
linkedTextureName: string;
}

export interface SceneFactoryProps {
export interface SceneBlueprintProps {
cameraPath: CatmullRomCurve3;
modelName: string;
modelChildrenTextures: ModelChildrenTextures[];
}

export abstract class SceneFactory
export abstract class SceneBlueprint
extends EventEmitter
implements ExperienceBase
{
Expand All @@ -37,7 +37,7 @@ export abstract class SceneFactory
destructed: "destructed",
};

constructor(_: SceneFactoryProps) {
constructor(_: SceneBlueprintProps) {
super();
this.cameraPath = _.cameraPath;
this._modelChildrenTextures = _.modelChildrenTextures;
Expand Down
4 changes: 2 additions & 2 deletions src/experiences/pages/Home/World/SceneBackground.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ import { CatmullRomCurve3, PerspectiveCamera, Vector3 } from "three";
import GSAP from "gsap";

// EXPERIENCES
import { SceneFactory } from "@/experiences/factories/SceneFactory";
import { SceneBlueprint } from "@/experiences/blueprints/Scene.blueprint";

// CONSTANTS
import { GSAP_DEFAULT_INTRO_PROPS } from "@/constants/ANIMATION";

export default class SceneBackground extends SceneFactory {
export default class SceneBackground extends SceneBlueprint {
constructor() {
try {
super({
Expand Down
6 changes: 3 additions & 3 deletions src/experiences/pages/Home/World/Scene_1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
import GSAP from "gsap";

// EXPERIENCES
import { SceneFactory } from "@/experiences/factories/SceneFactory";
import { SceneBlueprint } from "@/experiences/blueprints/Scene.blueprint";

// CONSTANTS
import { GSAP_DEFAULT_INTRO_PROPS } from "@/constants/ANIMATION";
Expand All @@ -24,7 +24,7 @@ import { GSAP_DEFAULT_INTRO_PROPS } from "@/constants/ANIMATION";
import fragment from "./shaders/scene1/fragment.frag";
import vertex from "./shaders/scene1/vertex.vert";

export default class Scene_1 extends SceneFactory {
export default class Scene_1 extends SceneBlueprint {
protected _renderer = this._experience.renderer;

public pcScreenWebglTexture?: WebGLRenderTarget;
Expand Down Expand Up @@ -62,7 +62,7 @@ export default class Scene_1 extends SceneFactory {
construct() {
if (!this._appCamera.instance) return;
this.modelScene = this._model?.scene.clone();
console.log(this.construct.name, this._model);

if (!this.modelScene) return;

try {
Expand Down
4 changes: 2 additions & 2 deletions src/experiences/pages/Home/World/Scene_2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ import { CatmullRomCurve3, PerspectiveCamera, Vector3 } from "three";
import GSAP from "gsap";

// EXPERIENCES
import { SceneFactory } from "@/experiences/factories/SceneFactory";
import { SceneBlueprint } from "@/experiences/blueprints/Scene.blueprint";

// CONSTANTS
import { GSAP_DEFAULT_INTRO_PROPS } from "@/constants/ANIMATION";

export default class Scene_2 extends SceneFactory {
export default class Scene_2 extends SceneBlueprint {
constructor() {
try {
super({
Expand Down
6 changes: 2 additions & 4 deletions src/experiences/pages/Home/World/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import Scene_3 from "./Scene_3";
import SceneBackground from "./SceneBackground";

// BLUEPRINTS
import { ExperienceBasedFactory } from "@/experiences/factories/ExperienceBased.factory";
import { ExperienceBasedBlueprint } from "@/experiences/blueprints/ExperienceBased.blueprint";

export default class World extends ExperienceBasedFactory {
export default class World extends ExperienceBasedBlueprint {
protected readonly _experience = new Experience();
protected readonly _appCamera = this._experience.app.camera;
protected readonly _renderer = this._experience.renderer;
Expand Down Expand Up @@ -81,8 +81,6 @@ export default class World extends ExperienceBasedFactory {
// this.scene3.construct();
this.sceneBackground?.construct();

console.log("Scene 1 ==>", this.scene1);

if (
this.scene1?.modelScene &&
this.scene1.pcScreen &&
Expand Down
6 changes: 3 additions & 3 deletions src/experiences/pages/Home/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ import Debug from "./Debug";

// FACTORIES
import {
ExperienceFactory,
ExperienceBlueprint,
type ExperienceProps,
} from "@/experiences/factories/Experience.factory";
} from "@/experiences/blueprints/Experience.blueprint";

export class HomeExperience extends ExperienceFactory {
export class HomeExperience extends ExperienceBlueprint {
renderer?: Renderer;
ui?: UI;
loader?: Loader;
Expand Down

0 comments on commit df7fcdc

Please sign in to comment.