From 1f23f54ee4e2b4ae7820f8d6a38886c9b8f4dc6c Mon Sep 17 00:00:00 2001 From: orion Date: Fri, 3 Apr 2026 06:46:00 +0200 Subject: [PATCH] shimeji class rewriten as the base for the rest, physis next --- src/lib/stores/shimeji.ts | 70 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 67 insertions(+), 3 deletions(-) diff --git a/src/lib/stores/shimeji.ts b/src/lib/stores/shimeji.ts index dab0e69..3cbbac6 100644 --- a/src/lib/stores/shimeji.ts +++ b/src/lib/stores/shimeji.ts @@ -211,7 +211,71 @@ export class Shimejii { moveTo(pos: number) {} } -export class Shimeji { - private WebGEngine: WebG.Engine; - private PhysisEngine: Physis.Engine; +namespace Shimagic { + export class Shimeji { + private WebGEngine: WebG.Engine; + //private PhysisEngine: Physis.Engine; + private size!: number; + + private AnimID: number | null = null; + private pDeltaT: number = 0; + + constructor(webgengine: WebG.Engine /* physis: Physis.Engine */) { + this.WebGEngine = webgengine; + } + + /** + * Factory method: Initializes all sub-systems like WebG & Physis aswell as initializes the Shimeji and starts its animation + * @async + * @public + * @param {ShimejiConfig} config - Shimeji configuration + * @returns {Promise} that resolves when the Shimeji is done initializing + */ + public static async Initialize(config: ShimejiConfig): Promise { + const webg = await WebG.Engine.Initialize(config.webG); + //const physis = await Physis.Engine.Initialize(config.physis); + + const shimeji = new Shimeji(webg); + shimeji.size = config.size; + + const AFrame = (delta: number) => { + shimeji.pDeltaT = delta; + shimeji.AnimID = requestAnimationFrame(shimeji._anim); + }; + + shimeji.AnimID = requestAnimationFrame(AFrame); + + return shimeji; + } + + private _anim(delta: number) { + let dt = (delta - this.pDeltaT) / 1000; + dt = Math.min(dt, 0.05 /* * this.Physis.TIMESCALE */); + this.pDeltaT = delta; + + this.UpdatePhysics(dt); + this.UpdateFrame(dt); + + this.AnimID = requestAnimationFrame(this._anim); + } + + /** + * A function called automatically every "frame" where the code for calculating the next physics frame of the Shimeji is placed + * @param delta - Automatically passed in deltaT value; + */ + private UpdatePhysics(delta: number): void {} + + /** + * A function called automatically every "frame" where the code for drawing the next frame of the Shimeji is placed + * @param delta - Automatically passed in deltaT value; + */ + private UpdateFrame(delta: number): void {} + } + + interface ShimejiConfig { + sprite: string; //temp soultion to + size: number; + webG: WebG.EngineConfig; + //physis: Physis.EngineConfig; + } }