mirror of
https://github.com/misskey-dev/misskey.git
synced 2026-06-06 23:54:15 +02:00
refactor
This commit is contained in:
@@ -277,148 +277,94 @@ export class RoomController {
|
|||||||
await this.init(canvas ?? this.canvas!);
|
await this.init(canvas ?? this.canvas!);
|
||||||
}
|
}
|
||||||
|
|
||||||
public pauseRender() {
|
// TODO: いい感じに型付け
|
||||||
|
private call(fn, args = []) {
|
||||||
if (this.worker != null) {
|
if (this.worker != null) {
|
||||||
this.worker.postMessage({ type: 'call', fn: 'pauseRender' });
|
this.worker.postMessage({ type: 'call', fn, args });
|
||||||
} else if (this.engine != null) {
|
} else if (this.engine != null) {
|
||||||
this.engine.pauseRender();
|
this.engine[fn](...args);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: いい感じに型付け
|
||||||
|
private set(key, value) {
|
||||||
|
if (this.worker != null) {
|
||||||
|
this.worker.postMessage({ type: 'set', key, value });
|
||||||
|
} else if (this.engine != null) {
|
||||||
|
this.engine[key] = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public pauseRender() {
|
||||||
|
this.call('pauseRender');
|
||||||
|
}
|
||||||
|
|
||||||
public resumeRender() {
|
public resumeRender() {
|
||||||
if (this.worker != null) {
|
this.call('resumeRender');
|
||||||
this.worker.postMessage({ type: 'call', fn: 'resumeRender' });
|
|
||||||
} else if (this.engine != null) {
|
|
||||||
this.engine.resumeRender();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public setCameraMoveVector(vec: { x: number; y: number }, dash: boolean) {
|
public setCameraMoveVector(vec: { x: number; y: number }, dash: boolean) {
|
||||||
if (this.worker != null) {
|
this.call('cameraMove', [vec, dash]);
|
||||||
this.worker.postMessage({ type: 'call', fn: 'cameraMove', args: [vec, dash] });
|
|
||||||
} else if (this.engine != null) {
|
|
||||||
this.engine.cameraMove(vec, dash);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public setCameraRotateVector(vec: { x: number; y: number }) {
|
public setCameraRotateVector(vec: { x: number; y: number }) {
|
||||||
if (this.worker != null) {
|
this.call('cameraRotate', [vec]);
|
||||||
this.worker.postMessage({ type: 'call', fn: 'cameraRotate', args: [vec] });
|
|
||||||
} else if (this.engine != null) {
|
|
||||||
this.engine.cameraRotate(vec);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public setCameraJoystickMoveVector(vec: { x: number; y: number }) {
|
public setCameraJoystickMoveVector(vec: { x: number; y: number }) {
|
||||||
if (this.worker != null) {
|
this.call('cameraJoystickMove', [vec]);
|
||||||
this.worker.postMessage({ type: 'call', fn: 'cameraJoystickMove', args: [vec] });
|
|
||||||
} else if (this.engine != null) {
|
|
||||||
this.engine.cameraJoystickMove(vec);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public enterEditMode() {
|
public enterEditMode() {
|
||||||
if (this.worker != null) {
|
this.call('enterEditMode');
|
||||||
this.worker.postMessage({ type: 'call', fn: 'enterEditMode' });
|
|
||||||
} else if (this.engine != null) {
|
|
||||||
this.engine.enterEditMode();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public exitEditMode() {
|
public exitEditMode() {
|
||||||
if (this.worker != null) {
|
this.call('exitEditMode');
|
||||||
this.worker.postMessage({ type: 'call', fn: 'exitEditMode' });
|
|
||||||
} else if (this.engine != null) {
|
|
||||||
this.engine.exitEditMode();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public setGridSnapping(gridSnapping: { enabled: boolean; scale: number }) {
|
public setGridSnapping(gridSnapping: { enabled: boolean; scale: number }) {
|
||||||
if (this.worker != null) {
|
this.set('gridSnapping', gridSnapping);
|
||||||
this.worker.postMessage({ type: 'setGridSnapping', gridSnapping });
|
|
||||||
} else if (this.engine != null) {
|
|
||||||
this.engine.gridSnapping = gridSnapping;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public updateObjectOption(objectId: string, key: string, value: any) {
|
public updateObjectOption(objectId: string, key: string, value: any) {
|
||||||
if (this.worker != null) {
|
this.call('updateObjectOption', [objectId, key, value]);
|
||||||
this.worker.postMessage({ type: 'call', fn: 'updateObjectOption', args: [objectId, key, value] });
|
|
||||||
} else if (this.engine != null) {
|
|
||||||
this.engine.updateObjectOption(objectId, key, value);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public changeHeyaType(type: RoomState['heya']['type']) {
|
public changeHeyaType(type: RoomState['heya']['type']) {
|
||||||
if (this.worker != null) {
|
this.call('changeHeyaType', [type]);
|
||||||
this.worker.postMessage({ type: 'call', fn: 'changeHeyaType', args: [type] });
|
|
||||||
} else if (this.engine != null) {
|
|
||||||
this.engine.changeHeyaType(type);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public updateHeyaOptions(options: RoomState['heya']['options']) {
|
public updateHeyaOptions(options: RoomState['heya']['options']) {
|
||||||
if (this.worker != null) {
|
this.call('updateHeyaOptions', [options]);
|
||||||
this.worker.postMessage({ type: 'call', fn: 'updateHeyaOptions', args: [options] });
|
|
||||||
} else if (this.engine != null) {
|
|
||||||
this.engine.updateHeyaOptions(options);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public updateRoomLightColor(color: [number, number, number]) {
|
public updateRoomLightColor(color: [number, number, number]) {
|
||||||
if (this.worker != null) {
|
this.call('updateRoomLightColor', [color]);
|
||||||
this.worker.postMessage({ type: 'call', fn: 'updateRoomLightColor', args: [color] });
|
|
||||||
} else if (this.engine != null) {
|
|
||||||
this.engine.updateRoomLightColor(color);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public beginSelectedInstalledObjectGrabbing() {
|
public beginSelectedInstalledObjectGrabbing() {
|
||||||
if (this.worker != null) {
|
this.call('beginSelectedInstalledObjectGrabbing');
|
||||||
this.worker.postMessage({ type: 'call', fn: 'beginSelectedInstalledObjectGrabbing' });
|
|
||||||
} else if (this.engine != null) {
|
|
||||||
this.engine.beginSelectedInstalledObjectGrabbing();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public removeSelectedObject() {
|
public removeSelectedObject() {
|
||||||
if (this.worker != null) {
|
this.call('removeSelectedObject');
|
||||||
this.worker.postMessage({ type: 'call', fn: 'removeSelectedObject' });
|
|
||||||
} else if (this.engine != null) {
|
|
||||||
this.engine.removeSelectedObject();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public addObject(type: string, options: any) {
|
public addObject(type: string, options: any) {
|
||||||
if (this.worker != null) {
|
this.call('addObject', [type, options]);
|
||||||
this.worker.postMessage({ type: 'call', fn: 'addObject', args: [type, options] });
|
|
||||||
} else if (this.engine != null) {
|
|
||||||
this.engine.addObject(type, options);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public endGrabbing() {
|
public endGrabbing() {
|
||||||
if (this.worker != null) {
|
this.call('endGrabbing');
|
||||||
this.worker.postMessage({ type: 'call', fn: 'endGrabbing' });
|
|
||||||
} else if (this.engine != null) {
|
|
||||||
this.engine.endGrabbing();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public cancelGrabbing() {
|
public cancelGrabbing() {
|
||||||
if (this.worker != null) {
|
this.call('endGrabbing', [true]);
|
||||||
this.worker.postMessage({ type: 'call', fn: 'endGrabbing', args: [true] });
|
|
||||||
} else if (this.engine != null) {
|
|
||||||
this.engine.endGrabbing(true);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public toggleRoomLight() {
|
public toggleRoomLight() {
|
||||||
if (this.worker != null) {
|
this.call('toggleRoomLight');
|
||||||
this.worker.postMessage({ type: 'call', fn: 'toggleRoomLight' });
|
|
||||||
} else if (this.engine != null) {
|
|
||||||
this.engine.toggleRoomLight();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public resize() {
|
public resize() {
|
||||||
|
|||||||
@@ -75,6 +75,10 @@ onmessage = async (event) => {
|
|||||||
if (engine != null) engine[event.data.fn](...(event.data.args ?? []));
|
if (engine != null) engine[event.data.fn](...(event.data.args ?? []));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case 'set': {
|
||||||
|
if (engine != null) engine[event.data.key] = event.data.value;
|
||||||
|
break;
|
||||||
|
}
|
||||||
default: {
|
default: {
|
||||||
console.warn('Unrecognized message type:', event.data?.type);
|
console.warn('Unrecognized message type:', event.data?.type);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user