This commit is contained in:
syuilo 2026-05-27 17:28:32 +09:00
commit 2df145c458
8 changed files with 27 additions and 2 deletions

View file

@ -3717,7 +3717,7 @@ _miRoom:
height: "高さ"
width: "幅"
hangingTShirt: "吊り下げTシャツ"
icosahedron: "正二十面体"
icosahedron: "正二十面体のオブジェ"
_icosahedron:
mat: "素材"
ironFrameTable: "アイアンフレームテーブル"

View file

@ -65,6 +65,7 @@ export class RoomEngine extends EngineBase<{
'changeSittingState': (ctx: { isSitting: boolean }) => void;
'changeGridSnapping': (ctx: { gridSnapping: { enabled: boolean; scale: number } }) => void;
'changeRoomState': (ctx: { roomState: RoomState }) => void;
'changeMyPlayerState': (ctx: { playerState: PlayerState }) => void;
'playSfxUrl': (ctx: {
url: string;
options: {

View file

@ -91,6 +91,7 @@ import * as Misskey from 'misskey-js';
import { cm, getHex, getRgb, WORLD_SCALE } from 'misskey-world/src/utility.js';
import { GRAPHICS_QUALITY } from 'misskey-world-engine/src/room/utility.js';
import { OBJECT_SCHEMA_DEFS } from 'misskey-world/src/room/object-schema-defs.js';
import { useInterval } from '@@/js/use-interval.js';
import XObjectCustomizeForm from './room.object-customize-form.vue';
import XEnvOptions from './room.env-options.vue';
import type { RoomControllerOptions } from '@/world/room/controller.js';
@ -346,6 +347,10 @@ onMounted(async () => {
(window as any).disableGlobalHotkeys();
});
useInterval(() => {
multiplayer.updateState(controller.myPlayerState.value);
}, 1000, { immediate: false, afterMounted: true });
onDeactivated(() => {
controller.destroy();
multiplayer.dispose();

View file

@ -10,6 +10,7 @@ import type { ShallowRef } from 'vue';
import type { RoomStateObject } from 'misskey-world/src/room/object.js';
import type { RoomEngine } from 'misskey-world-engine/src/room/engine.js';
import type { RoomAttachments, RoomState } from 'misskey-world/src/room/type.js';
import type { PlayerState } from 'misskey-world-engine/src/PlayerContainer.js';
import * as sound from '@/utility/sound.js';
import { deepEqual } from '@/utility/deep-equal.js';
import { deepClone } from '@/utility/clone.js';
@ -40,6 +41,10 @@ export class RoomController extends EngineControllerBase<RoomEngine> {
}[];
} | null>(null);
public roomState: ShallowRef<RoomState>;
public myPlayerState = shallowRef<PlayerState>({
position: [0, 0, 0],
rotation: [0, 0, 0],
});
constructor(roomState: RoomState, options: RoomControllerOptions) {
super(options);
@ -103,6 +108,10 @@ export class RoomController extends EngineControllerBase<RoomEngine> {
}
});
engineEvents.on('changeMyPlayerState', ({ playerState }) => {
this.myPlayerState.value = playerState;
});
engineEvents.on('playSfxUrl', ({ url, options }) => {
sound.playUrl(url, options);
});
@ -117,6 +126,10 @@ export class RoomController extends EngineControllerBase<RoomEngine> {
this.isRoomLightOn.value = true;
this.grabbing.value = null;
this.selected.value = null;
this.myPlayerState.value = {
position: [0, 0, 0],
rotation: [0, 0, 0],
};
await this.init(canvas, attachments);
}

View file

@ -10,6 +10,7 @@ import type { PlayerState } from 'misskey-world-engine/src/PlayerContainer.js';
import { useStream } from '@/stream.js';
import * as os from '@/os.js';
import { withTimeout } from '@/utility/promise-timeout.js';
import { deepEqual } from '@/utility/deep-equal.js';
export class Multiplayer {
public isOnline = ref(false);
@ -48,9 +49,14 @@ export class Multiplayer {
this.isOnline.value = false;
}
private prevState: PlayerState | null = null;
public updateState(state: PlayerState) {
if (this.connection == null || !this.isOnline.value) return;
if (this.prevState != null && deepEqual(this.prevState, state)) return;
this.connection.send('update', state);
this.prevState = state;
}
private onSync(states: Record<string, PlayerState>) {

View file

@ -13854,7 +13854,7 @@ export interface Locale extends ILocale {
*/
"hangingTShirt": string;
/**
*
*
*/
"icosahedron": string;
"_icosahedron": {