-
Notifications
You must be signed in to change notification settings - Fork 207
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
RSamaium
committed
Apr 8, 2024
1 parent
0dba1bf
commit bbc1d27
Showing
14 changed files
with
8,567 additions
and
30,051 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,57 +1,125 @@ | ||
import { RpgPlugin, HookClient, Utils, InjectContext } from '@rpgjs/common' | ||
import { Canvas, computed, cond, h, signal } from 'canvasengine'; | ||
import { SceneMap } from './Scenes/Map'; | ||
import { InjectContext, Utils } from "@rpgjs/common"; | ||
import { Canvas, computed, cond, h, signal } from "canvasengine"; | ||
import { SceneMap } from "./Scenes/Map"; | ||
|
||
const { elementToPositionAbsolute } = Utils | ||
const { elementToPositionAbsolute } = Utils; | ||
|
||
export enum TransitionMode { | ||
None, | ||
Fading | ||
None, | ||
Fading, | ||
} | ||
|
||
export type Scenes = { | ||
[key: string]: (...props) => any; | ||
}; | ||
|
||
enum ContainerName { | ||
Map = 'map' | ||
Map = "map", | ||
} | ||
|
||
export const EVENTS_MAP = { | ||
MouseEvent: ['click', 'dblclick', 'mousedown', 'mouseup', 'mousemove', 'mouseenter', 'mouseleave', 'mouseover', 'mouseout', 'contextmenu', 'wheel'], | ||
KeyboardEvent: ['keydown', 'keyup', 'keypress', 'keydownoutside', 'keyupoutside', 'keypressoutside'], | ||
PointerEvent: ['pointerdown', 'pointerup', 'pointermove', 'pointerover', 'pointerout', 'pointerenter', 'pointerleave', 'pointercancel'], | ||
TouchEvent: ['touchstart', 'touchend', 'touchmove', 'touchcancel'] | ||
MouseEvent: [ | ||
"click", | ||
"dblclick", | ||
"mousedown", | ||
"mouseup", | ||
"mousemove", | ||
"mouseenter", | ||
"mouseleave", | ||
"mouseover", | ||
"mouseout", | ||
"contextmenu", | ||
"wheel", | ||
], | ||
KeyboardEvent: [ | ||
"keydown", | ||
"keyup", | ||
"keypress", | ||
"keydownoutside", | ||
"keyupoutside", | ||
"keypressoutside", | ||
], | ||
PointerEvent: [ | ||
"pointerdown", | ||
"pointerup", | ||
"pointermove", | ||
"pointerover", | ||
"pointerout", | ||
"pointerenter", | ||
"pointerleave", | ||
"pointercancel", | ||
], | ||
TouchEvent: ["touchstart", "touchend", "touchmove", "touchcancel"], | ||
}; | ||
|
||
export class RpgRenderer { | ||
private canvasEl: HTMLElement | ||
private selector: HTMLElement | ||
public guiEl: HTMLDivElement | ||
private canvasEl: HTMLElement; | ||
private selector: HTMLElement; | ||
private currentSceneName = signal(""); | ||
private currentSceneData = signal({}); | ||
private scenes = {}; | ||
|
||
/** @internal */ | ||
init(): Promise<void> { | ||
return this.onDOMLoaded() | ||
} | ||
width = signal(800); | ||
height = signal(600); | ||
|
||
public guiEl: HTMLDivElement; | ||
|
||
constructor(private context: InjectContext, private options) {} | ||
|
||
/** @internal */ | ||
init(scenes: Scenes): Promise<void> { | ||
this.scenes = { | ||
map: SceneMap, | ||
...scenes, | ||
}; | ||
return this.onDOMLoaded(); | ||
} | ||
|
||
/** @internal */ | ||
async onDOMLoaded(): Promise<void> { | ||
const currentSceneName = signal('') | ||
await h(Canvas, {}, cond( | ||
computed(() => currentSceneName() == 'map'), | ||
SceneMap({}) | ||
)) | ||
|
||
if (!this.guiEl) { | ||
this.guiEl = document.createElement('div') | ||
//this.guiEl = this.selector.appendChild(this.guiEl) | ||
/** @internal */ | ||
async onDOMLoaded(): Promise<void> { | ||
this.selector = document.body.querySelector(this.options.selector); | ||
this.canvasEl = this.selector.querySelector(this.options.selectorCanvas); | ||
|
||
await h( | ||
Canvas, | ||
{ | ||
canvasEl: this.canvasEl, | ||
selector: this.options.selector, | ||
width: this.width, | ||
height: this.height | ||
}, | ||
cond( | ||
computed(() => this.currentSceneName()), | ||
() => { | ||
const name = this.currentSceneName(); | ||
const sceneFn = this.scenes[name]; | ||
if (!sceneFn) { | ||
throw new Error(`Scene ${name} not found`); | ||
} | ||
return sceneFn(this.currentSceneData); | ||
} | ||
) | ||
); | ||
|
||
if (!this.guiEl) { | ||
this.guiEl = document.createElement("div"); | ||
//this.guiEl = this.selector.appendChild(this.guiEl) | ||
} | ||
|
||
//elementToPositionAbsolute(this.guiEl) | ||
//elementToPositionAbsolute(this.guiEl) | ||
|
||
/*if (!this.canvasEl) { | ||
/*if (!this.canvasEl) { | ||
this.selector.insertBefore(this.renderer.view as HTMLCanvasElement, this.selector.firstChild) | ||
const [canvas] = document.querySelector(this.options.selector).children | ||
canvas.style.position = 'absolute' | ||
} | ||
else { | ||
this.canvasEl.appendChild(this.renderer.view as HTMLCanvasElement) | ||
}*/ | ||
} | ||
} | ||
} | ||
|
||
loadScene(sceneName: string, data: any) { | ||
this.currentSceneData.set(data); | ||
this.currentSceneName.set(sceneName); | ||
} | ||
} |
Oops, something went wrong.