fix(misskey-js): 型生成をOpenAPI Specification 3.1.0に対応

This commit is contained in:
zyoshoka 2024-01-13 11:55:19 +09:00
parent 7288851d5c
commit 788072cdda
No known key found for this signature in database
GPG key ID: 0C2CB8FBA309A5B8
10 changed files with 580 additions and 433 deletions

1
locales/index.d.ts vendored
View file

@ -1201,6 +1201,7 @@ export interface Locale {
"replaying": string; "replaying": string;
"ranking": string; "ranking": string;
"lastNDays": string; "lastNDays": string;
"backToTitle": string;
"_bubbleGame": { "_bubbleGame": {
"howToPlay": string; "howToPlay": string;
"_howToPlay": { "_howToPlay": {

View file

@ -1198,6 +1198,7 @@ replay: "リプレイ"
replaying: "リプレイ中" replaying: "リプレイ中"
ranking: "ランキング" ranking: "ランキング"
lastNDays: "直近{n}日" lastNDays: "直近{n}日"
backToTitle: "タイトルへ"
_bubbleGame: _bubbleGame:
howToPlay: "遊び方" howToPlay: "遊び方"

Binary file not shown.

Before

Width:  |  Height:  |  Size: 86 KiB

After

Width:  |  Height:  |  Size: 91 KiB

View file

@ -16,7 +16,7 @@ import * as os from '@/os.js';
const props = withDefaults(defineProps<{ const props = withDefaults(defineProps<{
x: number; x: number;
y: number; y: number;
value?: number; value?: number | string;
}>(), { }>(), {
value: 1, value: 1,
}); });

View file

@ -8,141 +8,135 @@ SPDX-License-Identifier: AGPL-3.0-only
<div v-if="!gameLoaded" :class="$style.loadingScreen"> <div v-if="!gameLoaded" :class="$style.loadingScreen">
Loading... Loading...
</div> </div>
<Transition <!-- に対してTransitionコンポーネントを使うと何故かkeyを指定していてもキャッシュが効かず様々なコンポーネントが都度再評価されてパフォーマンスが低下する -->
:enterActiveClass="$style.transition_zoom_enterActive" <div v-show="gameLoaded" class="_gaps_s">
:leaveActiveClass="$style.transition_zoom_leaveActive" <div :class="$style.header">
:enterFromClass="$style.transition_zoom_enterFrom" <div :class="[$style.frame, $style.headerTitle]">
:leaveToClass="$style.transition_zoom_leaveTo" <div :class="$style.frameInner">
:moveClass="$style.transition_zoom_move" <b>BUBBLE GAME</b>
mode="out-in" <div>- {{ gameMode }} -</div>
>
<div v-show="gameLoaded" class="_gaps_s">
<div :class="$style.header">
<div :class="[$style.frame, $style.headerTitle]">
<div :class="$style.frameInner">
<b>BUBBLE GAME</b>
<div>- {{ gameMode }} -</div>
</div>
</div>
<div :class="[$style.frame, $style.frameH]">
<div :class="$style.frameInner">
<MkButton inline small @click="hold">HOLD</MkButton>
<img v-if="holdingStock" :src="getTextureImageUrl(holdingStock.mono)" style="width: 32px; margin-left: 8px; vertical-align: bottom;"/>
</div>
<div :class="[$style.frameInner, $style.stock]" style="text-align: center;">
<TransitionGroup
:enterActiveClass="$style.transition_stock_enterActive"
:leaveActiveClass="$style.transition_stock_leaveActive"
:enterFromClass="$style.transition_stock_enterFrom"
:leaveToClass="$style.transition_stock_leaveTo"
:moveClass="$style.transition_stock_move"
>
<img v-for="x in stock" :key="x.id" :src="getTextureImageUrl(x.mono)" style="width: 32px; vertical-align: bottom;"/>
</TransitionGroup>
</div>
</div> </div>
</div> </div>
<div ref="containerEl" :class="[$style.gameContainer, { [$style.gameOver]: isGameOver && !replaying }]" @contextmenu.stop.prevent @click.stop.prevent="onClick" @touchmove.stop.prevent="onTouchmove" @touchend="onTouchend" @mousemove="onMousemove"> <div :class="[$style.frame, $style.frameH]">
<img v-if="defaultStore.state.darkMode" src="/client-assets/drop-and-fusion/frame-dark.svg" :class="$style.mainFrameImg"/> <div :class="$style.frameInner">
<img v-else src="/client-assets/drop-and-fusion/frame-light.svg" :class="$style.mainFrameImg"/> <MkButton inline small @click="hold">HOLD</MkButton>
<canvas ref="canvasEl" :class="$style.canvas"/> <img v-if="holdingStock" :src="getTextureImageUrl(holdingStock.mono)" style="width: 32px; margin-left: 8px; vertical-align: bottom;"/>
<Transition </div>
:enterActiveClass="$style.transition_combo_enterActive" <div :class="[$style.frameInner, $style.stock]" style="text-align: center;">
:leaveActiveClass="$style.transition_combo_leaveActive" <TransitionGroup
:enterFromClass="$style.transition_combo_enterFrom" :enterActiveClass="$style.transition_stock_enterActive"
:leaveToClass="$style.transition_combo_leaveTo" :leaveActiveClass="$style.transition_stock_leaveActive"
:moveClass="$style.transition_combo_move" :enterFromClass="$style.transition_stock_enterFrom"
> :leaveToClass="$style.transition_stock_leaveTo"
<div v-show="combo > 1" :class="$style.combo" :style="{ fontSize: `${100 + ((comboPrev - 2) * 15)}%` }">{{ comboPrev }} Chain!</div> :moveClass="$style.transition_stock_move"
</Transition>
<div v-if="!isGameOver && !replaying" :class="$style.dropperContainer" :style="{ left: dropperX + 'px' }">
<!--<img v-if="currentPick" src="/client-assets/drop-and-fusion/dropper.png" :class="$style.dropper" :style="{ left: dropperX + 'px' }"/>-->
<Transition
:enterActiveClass="$style.transition_picked_enterActive"
:leaveActiveClass="$style.transition_picked_leaveActive"
:enterFromClass="$style.transition_picked_enterFrom"
:leaveToClass="$style.transition_picked_leaveTo"
:moveClass="$style.transition_picked_move"
mode="out-in"
> >
<img v-if="currentPick" :key="currentPick.id" :src="getTextureImageUrl(currentPick.mono)" :class="$style.currentMono" :style="{ marginBottom: -((currentPick?.mono.sizeY * viewScale) / 2) + 'px', left: -((currentPick?.mono.sizeX * viewScale) / 2) + 'px', width: `${currentPick?.mono.sizeX * viewScale}px` }"/> <img v-for="x in stock" :key="x.id" :src="getTextureImageUrl(x.mono)" style="width: 32px; vertical-align: bottom;"/>
</Transition> </TransitionGroup>
<template v-if="dropReady && currentPick">
<img src="/client-assets/drop-and-fusion/drop-arrow.svg" :class="$style.currentMonoArrow"/>
<div :class="$style.dropGuide"/>
</template>
</div>
<div v-if="isGameOver && !replaying" :class="$style.gameOverLabel">
<div class="_gaps_s">
<img src="/client-assets/drop-and-fusion/gameover.png" style="width: 200px; max-width: 100%; display: block; margin: auto; margin-bottom: -5px;"/>
<div>SCORE: <MkNumber :value="score"/>{{ gameMode === 'yen' ? '円' : 'pt' }}</div>
<div>MAX CHAIN: <MkNumber :value="maxCombo"/></div>
</div>
</div>
<div v-if="replaying" :class="$style.replayIndicator"><span :class="$style.replayIndicatorText"><i class="ti ti-player-play"></i> {{ i18n.ts.replaying }}</span></div>
</div>
<div v-if="replaying" :class="$style.frame">
<div :class="$style.frameInner">
<div style="background: #0004;">
<div style="height: 10px; background: var(--accent); will-change: width;" :style="{ width: `${(currentFrame / endedAtFrame) * 100}%` }"></div>
</div>
</div>
<div :class="$style.frameInner">
<div class="_buttonsCenter">
<MkButton @click="endReplay"><i class="ti ti-player-stop"></i> END</MkButton>
<MkButton :primary="replayPlaybackRate === 4" @click="replayPlaybackRate = replayPlaybackRate === 4 ? 1 : 4"><i class="ti ti-player-track-next"></i> x4</MkButton>
<MkButton :primary="replayPlaybackRate === 16" @click="replayPlaybackRate = replayPlaybackRate === 16 ? 1 : 16"><i class="ti ti-player-track-next"></i> x16</MkButton>
</div>
</div>
</div>
<div v-if="isGameOver" :class="$style.frame">
<div :class="$style.frameInner">
<div class="_buttonsCenter">
<MkButton primary rounded @click="backToTitle">{{ i18n.ts.done }}</MkButton>
<MkButton primary rounded @click="replay">{{ i18n.ts.showReplay }}</MkButton>
<MkButton primary rounded @click="share">{{ i18n.ts.share }}</MkButton>
<MkButton rounded @click="exportLog">Copy replay data</MkButton>
</div>
</div>
</div>
<div style="display: flex;">
<div :class="$style.frame" style="flex: 1; margin-right: 10px;">
<div :class="$style.frameInner">
<div>SCORE: <b><MkNumber :value="score"/>{{ gameMode === 'yen' ? '円' : 'pt' }}</b></div>
<div>HIGH SCORE: <b v-if="highScore"><MkNumber :value="highScore"/>{{ gameMode === 'yen' ? '円' : 'pt' }}</b><b v-else>-</b></div>
</div>
</div>
<div :class="[$style.frame]" style="margin-left: auto;">
<div :class="$style.frameInner" style="text-align: center;">
<div @click="showConfig = !showConfig"><i class="ti ti-settings"></i></div>
</div>
</div>
</div>
<div v-if="showConfig" :class="$style.frame">
<div :class="$style.frameInner">
<div class="_gaps">
<MkRange v-model="bgmVolume" :min="0" :max="1" :step="0.01" :textConverter="(v) => `${Math.floor(v * 100)}%`" :continuousUpdate="true" @dragEnded="(v) => updateSettings('bgmVolume', v)">
<template #label>BGM {{ i18n.ts.volume }}</template>
</MkRange>
<MkRange v-model="sfxVolume" :min="0" :max="1" :step="0.01" :textConverter="(v) => `${Math.floor(v * 100)}%`" :continuousUpdate="true" @dragEnded="(v) => updateSettings('sfxVolume', v)">
<template #label>{{ i18n.ts.sfx }} {{ i18n.ts.volume }}</template>
</MkRange>
</div>
</div>
</div>
<div :class="$style.frame">
<div :class="$style.frameInner">
<MkButton v-if="!isGameOver && !replaying" full danger @click="surrender">Surrender</MkButton>
<MkButton v-else full @click="restart">Retry</MkButton>
</div> </div>
</div> </div>
</div> </div>
</Transition> <div ref="containerEl" :class="[$style.gameContainer, { [$style.gameOver]: isGameOver && !replaying }]" @contextmenu.stop.prevent @click.stop.prevent="onClick" @touchmove.stop.prevent="onTouchmove" @touchend="onTouchend" @mousemove="onMousemove">
<img v-if="defaultStore.state.darkMode" src="/client-assets/drop-and-fusion/frame-dark.svg" :class="$style.mainFrameImg"/>
<img v-else src="/client-assets/drop-and-fusion/frame-light.svg" :class="$style.mainFrameImg"/>
<canvas ref="canvasEl" :class="$style.canvas"/>
<Transition
:enterActiveClass="$style.transition_combo_enterActive"
:leaveActiveClass="$style.transition_combo_leaveActive"
:enterFromClass="$style.transition_combo_enterFrom"
:leaveToClass="$style.transition_combo_leaveTo"
:moveClass="$style.transition_combo_move"
>
<div v-show="combo > 1" :class="$style.combo" :style="{ fontSize: `${100 + ((comboPrev - 2) * 15)}%` }">{{ comboPrev }} Chain!</div>
</Transition>
<div v-if="!isGameOver && !replaying" :class="$style.dropperContainer" :style="{ left: dropperX + 'px' }">
<!--<img v-if="currentPick" src="/client-assets/drop-and-fusion/dropper.png" :class="$style.dropper" :style="{ left: dropperX + 'px' }"/>-->
<Transition
:enterActiveClass="$style.transition_picked_enterActive"
:leaveActiveClass="$style.transition_picked_leaveActive"
:enterFromClass="$style.transition_picked_enterFrom"
:leaveToClass="$style.transition_picked_leaveTo"
:moveClass="$style.transition_picked_move"
mode="out-in"
>
<img v-if="currentPick" :key="currentPick.id" :src="getTextureImageUrl(currentPick.mono)" :class="$style.currentMono" :style="{ marginBottom: -((currentPick?.mono.sizeY * viewScale) / 2) + 'px', left: -((currentPick?.mono.sizeX * viewScale) / 2) + 'px', width: `${currentPick?.mono.sizeX * viewScale}px` }"/>
</Transition>
<template v-if="dropReady && currentPick">
<img src="/client-assets/drop-and-fusion/drop-arrow.svg" :class="$style.currentMonoArrow"/>
<div :class="$style.dropGuide"/>
</template>
</div>
<div v-if="isGameOver && !replaying" :class="$style.gameOverLabel">
<div class="_gaps_s">
<img src="/client-assets/drop-and-fusion/gameover.png" style="width: 200px; max-width: 100%; display: block; margin: auto; margin-bottom: -5px;"/>
<div>SCORE: <MkNumber :value="score"/>{{ gameMode === 'yen' ? '円' : 'pt' }}</div>
<div>MAX CHAIN: <MkNumber :value="maxCombo"/></div>
<div v-if="gameMode === 'yen'">TOTAL EARNINGS: <b><MkNumber :value="yenTotal ?? score"/></b></div>
</div>
</div>
<div v-if="replaying" :class="$style.replayIndicator"><span :class="$style.replayIndicatorText"><i class="ti ti-player-play"></i> {{ i18n.ts.replaying }}</span></div>
</div>
<div v-if="replaying" :class="$style.frame">
<div :class="$style.frameInner">
<div style="background: #0004;">
<div style="height: 10px; background: var(--accent); will-change: width;" :style="{ width: `${(currentFrame / endedAtFrame) * 100}%` }"></div>
</div>
</div>
<div :class="$style.frameInner">
<div class="_buttonsCenter">
<MkButton @click="endReplay"><i class="ti ti-player-stop"></i> END</MkButton>
<MkButton :primary="replayPlaybackRate === 4" @click="replayPlaybackRate = replayPlaybackRate === 4 ? 1 : 4"><i class="ti ti-player-track-next"></i> x4</MkButton>
<MkButton :primary="replayPlaybackRate === 16" @click="replayPlaybackRate = replayPlaybackRate === 16 ? 1 : 16"><i class="ti ti-player-track-next"></i> x16</MkButton>
</div>
</div>
</div>
<div v-if="isGameOver" :class="$style.frame">
<div :class="$style.frameInner">
<div class="_buttonsCenter">
<MkButton primary rounded @click="backToTitle">{{ i18n.ts.backToTitle }}</MkButton>
<MkButton primary rounded @click="replay">{{ i18n.ts.showReplay }}</MkButton>
<MkButton primary rounded @click="share">{{ i18n.ts.share }}</MkButton>
<MkButton rounded @click="exportLog">Copy replay data</MkButton>
</div>
</div>
</div>
<div style="display: flex;">
<div :class="$style.frame" style="flex: 1; margin-right: 10px;">
<div :class="$style.frameInner">
<div>SCORE: <b><MkNumber :value="score"/>{{ gameMode === 'yen' ? '円' : 'pt' }}</b></div>
<div>HIGH SCORE: <b v-if="highScore"><MkNumber :value="highScore"/>{{ gameMode === 'yen' ? '円' : 'pt' }}</b><b v-else>-</b></div>
<div v-if="gameMode === 'yen'">TOTAL EARNINGS: <b v-if="yenTotal"><MkNumber :value="yenTotal"/></b><b v-else>-</b></div>
</div>
</div>
<div :class="[$style.frame]" style="margin-left: auto;">
<div :class="$style.frameInner" style="text-align: center;">
<div @click="showConfig = !showConfig"><i class="ti ti-settings"></i></div>
</div>
</div>
</div>
<div v-if="showConfig" :class="$style.frame">
<div :class="$style.frameInner">
<div class="_gaps">
<MkRange v-model="bgmVolume" :min="0" :max="1" :step="0.01" :textConverter="(v) => `${Math.floor(v * 100)}%`" :continuousUpdate="true" @dragEnded="(v) => updateSettings('bgmVolume', v)">
<template #label>BGM {{ i18n.ts.volume }}</template>
</MkRange>
<MkRange v-model="sfxVolume" :min="0" :max="1" :step="0.01" :textConverter="(v) => `${Math.floor(v * 100)}%`" :continuousUpdate="true" @dragEnded="(v) => updateSettings('sfxVolume', v)">
<template #label>{{ i18n.ts.sfx }} {{ i18n.ts.volume }}</template>
</MkRange>
</div>
</div>
</div>
<div :class="$style.frame">
<div :class="$style.frameInner">
<MkButton v-if="!isGameOver && !replaying" full danger @click="surrender">Surrender</MkButton>
<MkButton v-else full @click="restart">Retry</MkButton>
</div>
</div>
</div>
</div> </div>
</template> </template>
<script lang="ts" setup> <script lang="ts" setup>
import { onDeactivated, onMounted, onUnmounted, ref, shallowRef, watch } from 'vue'; import { computed, onDeactivated, onMounted, onUnmounted, ref, shallowRef, watch } from 'vue';
import * as Matter from 'matter-js'; import * as Matter from 'matter-js';
import * as Misskey from 'misskey-js'; import * as Misskey from 'misskey-js';
import { definePageMetadata } from '@/scripts/page-metadata.js'; import { definePageMetadata } from '@/scripts/page-metadata.js';
@ -163,15 +157,17 @@ import * as sound from '@/scripts/sound.js';
import MkRange from '@/components/MkRange.vue'; import MkRange from '@/components/MkRange.vue';
import copyToClipboard from '@/scripts/copy-to-clipboard.js'; import copyToClipboard from '@/scripts/copy-to-clipboard.js';
const NORMAL_BASE_SIZE = 30; type FrontendMonoDefinition = {
const NORAML_MONOS: Mono[] = [{ id: string;
img: string;
imgSizeX: number;
imgSizeY: number;
spriteScale: number;
sfxPitch: number;
};
const NORAML_MONOS: FrontendMonoDefinition[] = [{
id: '9377076d-c980-4d83-bdaf-175bc58275b7', id: '9377076d-c980-4d83-bdaf-175bc58275b7',
level: 10,
sizeX: NORMAL_BASE_SIZE * 1.25 * 1.25 * 1.25 * 1.25 * 1.25 * 1.25 * 1.25 * 1.25 * 1.25,
sizeY: NORMAL_BASE_SIZE * 1.25 * 1.25 * 1.25 * 1.25 * 1.25 * 1.25 * 1.25 * 1.25 * 1.25,
shape: 'circle',
score: 512,
dropCandidate: false,
sfxPitch: 0.25, sfxPitch: 0.25,
img: '/client-assets/drop-and-fusion/exploding_head.png', img: '/client-assets/drop-and-fusion/exploding_head.png',
imgSizeX: 256, imgSizeX: 256,
@ -179,12 +175,6 @@ const NORAML_MONOS: Mono[] = [{
spriteScale: 1.12, spriteScale: 1.12,
}, { }, {
id: 'be9f38d2-b267-4b1a-b420-904e22e80568', id: 'be9f38d2-b267-4b1a-b420-904e22e80568',
level: 9,
sizeX: NORMAL_BASE_SIZE * 1.25 * 1.25 * 1.25 * 1.25 * 1.25 * 1.25 * 1.25 * 1.25,
sizeY: NORMAL_BASE_SIZE * 1.25 * 1.25 * 1.25 * 1.25 * 1.25 * 1.25 * 1.25 * 1.25,
shape: 'circle',
score: 256,
dropCandidate: false,
sfxPitch: 0.5, sfxPitch: 0.5,
img: '/client-assets/drop-and-fusion/face_with_symbols_on_mouth.png', img: '/client-assets/drop-and-fusion/face_with_symbols_on_mouth.png',
imgSizeX: 256, imgSizeX: 256,
@ -192,12 +182,6 @@ const NORAML_MONOS: Mono[] = [{
spriteScale: 1.12, spriteScale: 1.12,
}, { }, {
id: 'beb30459-b064-4888-926b-f572e4e72e0c', id: 'beb30459-b064-4888-926b-f572e4e72e0c',
level: 8,
sizeX: NORMAL_BASE_SIZE * 1.25 * 1.25 * 1.25 * 1.25 * 1.25 * 1.25 * 1.25,
sizeY: NORMAL_BASE_SIZE * 1.25 * 1.25 * 1.25 * 1.25 * 1.25 * 1.25 * 1.25,
shape: 'circle',
score: 128,
dropCandidate: false,
sfxPitch: 0.75, sfxPitch: 0.75,
img: '/client-assets/drop-and-fusion/cold_face.png', img: '/client-assets/drop-and-fusion/cold_face.png',
imgSizeX: 256, imgSizeX: 256,
@ -205,12 +189,6 @@ const NORAML_MONOS: Mono[] = [{
spriteScale: 1.12, spriteScale: 1.12,
}, { }, {
id: 'feab6426-d9d8-49ae-849c-048cdbb6cdf0', id: 'feab6426-d9d8-49ae-849c-048cdbb6cdf0',
level: 7,
sizeX: NORMAL_BASE_SIZE * 1.25 * 1.25 * 1.25 * 1.25 * 1.25 * 1.25,
sizeY: NORMAL_BASE_SIZE * 1.25 * 1.25 * 1.25 * 1.25 * 1.25 * 1.25,
shape: 'circle',
score: 64,
dropCandidate: false,
sfxPitch: 1, sfxPitch: 1,
img: '/client-assets/drop-and-fusion/zany_face.png', img: '/client-assets/drop-and-fusion/zany_face.png',
imgSizeX: 256, imgSizeX: 256,
@ -218,12 +196,6 @@ const NORAML_MONOS: Mono[] = [{
spriteScale: 1.12, spriteScale: 1.12,
}, { }, {
id: 'd6d8fed6-6d18-4726-81a1-6cf2c974df8a', id: 'd6d8fed6-6d18-4726-81a1-6cf2c974df8a',
level: 6,
sizeX: NORMAL_BASE_SIZE * 1.25 * 1.25 * 1.25 * 1.25 * 1.25,
sizeY: NORMAL_BASE_SIZE * 1.25 * 1.25 * 1.25 * 1.25 * 1.25,
shape: 'circle',
score: 32,
dropCandidate: false,
sfxPitch: 1.5, sfxPitch: 1.5,
img: '/client-assets/drop-and-fusion/pleading_face.png', img: '/client-assets/drop-and-fusion/pleading_face.png',
imgSizeX: 256, imgSizeX: 256,
@ -231,12 +203,6 @@ const NORAML_MONOS: Mono[] = [{
spriteScale: 1.12, spriteScale: 1.12,
}, { }, {
id: '249c728e-230f-4332-bbbf-281c271c75b2', id: '249c728e-230f-4332-bbbf-281c271c75b2',
level: 5,
sizeX: NORMAL_BASE_SIZE * 1.25 * 1.25 * 1.25 * 1.25,
sizeY: NORMAL_BASE_SIZE * 1.25 * 1.25 * 1.25 * 1.25,
shape: 'circle',
score: 16,
dropCandidate: true,
sfxPitch: 2, sfxPitch: 2,
img: '/client-assets/drop-and-fusion/face_with_open_mouth.png', img: '/client-assets/drop-and-fusion/face_with_open_mouth.png',
imgSizeX: 256, imgSizeX: 256,
@ -244,12 +210,6 @@ const NORAML_MONOS: Mono[] = [{
spriteScale: 1.12, spriteScale: 1.12,
}, { }, {
id: '23d67613-d484-4a93-b71e-3e81b19d6186', id: '23d67613-d484-4a93-b71e-3e81b19d6186',
level: 4,
sizeX: NORMAL_BASE_SIZE * 1.25 * 1.25 * 1.25,
sizeY: NORMAL_BASE_SIZE * 1.25 * 1.25 * 1.25,
shape: 'circle',
score: 8,
dropCandidate: true,
sfxPitch: 2.5, sfxPitch: 2.5,
img: '/client-assets/drop-and-fusion/smiling_face_with_sunglasses.png', img: '/client-assets/drop-and-fusion/smiling_face_with_sunglasses.png',
imgSizeX: 256, imgSizeX: 256,
@ -257,12 +217,6 @@ const NORAML_MONOS: Mono[] = [{
spriteScale: 1.12, spriteScale: 1.12,
}, { }, {
id: '3cbd0add-ad7d-4685-bad0-29f6dddc0b99', id: '3cbd0add-ad7d-4685-bad0-29f6dddc0b99',
level: 3,
sizeX: NORMAL_BASE_SIZE * 1.25 * 1.25,
sizeY: NORMAL_BASE_SIZE * 1.25 * 1.25,
shape: 'circle',
score: 4,
dropCandidate: true,
sfxPitch: 3, sfxPitch: 3,
img: '/client-assets/drop-and-fusion/grinning_squinting_face.png', img: '/client-assets/drop-and-fusion/grinning_squinting_face.png',
imgSizeX: 256, imgSizeX: 256,
@ -270,12 +224,6 @@ const NORAML_MONOS: Mono[] = [{
spriteScale: 1.12, spriteScale: 1.12,
}, { }, {
id: '8f86d4f4-ee02-41bf-ad38-1ce0ae457fb5', id: '8f86d4f4-ee02-41bf-ad38-1ce0ae457fb5',
level: 2,
sizeX: NORMAL_BASE_SIZE * 1.25,
sizeY: NORMAL_BASE_SIZE * 1.25,
shape: 'circle',
score: 2,
dropCandidate: true,
sfxPitch: 3.5, sfxPitch: 3.5,
img: '/client-assets/drop-and-fusion/smiling_face_with_hearts.png', img: '/client-assets/drop-and-fusion/smiling_face_with_hearts.png',
imgSizeX: 256, imgSizeX: 256,
@ -283,12 +231,6 @@ const NORAML_MONOS: Mono[] = [{
spriteScale: 1.12, spriteScale: 1.12,
}, { }, {
id: '64ec4add-ce39-42b4-96cb-33908f3f118d', id: '64ec4add-ce39-42b4-96cb-33908f3f118d',
level: 1,
sizeX: NORMAL_BASE_SIZE,
sizeY: NORMAL_BASE_SIZE,
shape: 'circle',
score: 1,
dropCandidate: true,
sfxPitch: 4, sfxPitch: 4,
img: '/client-assets/drop-and-fusion/heart_suit.png', img: '/client-assets/drop-and-fusion/heart_suit.png',
imgSizeX: 256, imgSizeX: 256,
@ -296,16 +238,8 @@ const NORAML_MONOS: Mono[] = [{
spriteScale: 1.12, spriteScale: 1.12,
}]; }];
const YEN_BASE_SIZE = 30; const YEN_MONOS: FrontendMonoDefinition[] = [{
const YEN_SATSU_BASE_SIZE = 70;
const YEN_MONOS: Mono[] = [{
id: '880f9bd9-802f-4135-a7e1-fd0e0331f726', id: '880f9bd9-802f-4135-a7e1-fd0e0331f726',
level: 10,
sizeX: (YEN_SATSU_BASE_SIZE * 2) * 1.25 * 1.25 * 1.25,
sizeY: YEN_SATSU_BASE_SIZE * 1.25 * 1.25 * 1.25,
shape: 'rectangle',
score: 10000,
dropCandidate: false,
sfxPitch: 0.25, sfxPitch: 0.25,
img: '/client-assets/drop-and-fusion/10000yen.png', img: '/client-assets/drop-and-fusion/10000yen.png',
imgSizeX: 512, imgSizeX: 512,
@ -313,12 +247,6 @@ const YEN_MONOS: Mono[] = [{
spriteScale: 0.97, spriteScale: 0.97,
}, { }, {
id: 'e807beb6-374a-4314-9cc2-aa5f17d96b6b', id: 'e807beb6-374a-4314-9cc2-aa5f17d96b6b',
level: 9,
sizeX: (YEN_SATSU_BASE_SIZE * 2) * 1.25 * 1.25,
sizeY: YEN_SATSU_BASE_SIZE * 1.25 * 1.25,
shape: 'rectangle',
score: 5000,
dropCandidate: false,
sfxPitch: 0.5, sfxPitch: 0.5,
img: '/client-assets/drop-and-fusion/5000yen.png', img: '/client-assets/drop-and-fusion/5000yen.png',
imgSizeX: 512, imgSizeX: 512,
@ -326,12 +254,6 @@ const YEN_MONOS: Mono[] = [{
spriteScale: 0.97, spriteScale: 0.97,
}, { }, {
id: '033445b7-8f90-4fc9-beca-71a9e87cb530', id: '033445b7-8f90-4fc9-beca-71a9e87cb530',
level: 8,
sizeX: (YEN_SATSU_BASE_SIZE * 2) * 1.25,
sizeY: YEN_SATSU_BASE_SIZE * 1.25,
shape: 'rectangle',
score: 2000,
dropCandidate: false,
sfxPitch: 0.75, sfxPitch: 0.75,
img: '/client-assets/drop-and-fusion/2000yen.png', img: '/client-assets/drop-and-fusion/2000yen.png',
imgSizeX: 512, imgSizeX: 512,
@ -339,12 +261,6 @@ const YEN_MONOS: Mono[] = [{
spriteScale: 0.97, spriteScale: 0.97,
}, { }, {
id: '410a09ec-5f7f-46f6-b26f-cbca4ccbd091', id: '410a09ec-5f7f-46f6-b26f-cbca4ccbd091',
level: 7,
sizeX: YEN_SATSU_BASE_SIZE * 2,
sizeY: YEN_SATSU_BASE_SIZE,
shape: 'rectangle',
score: 1000,
dropCandidate: false,
sfxPitch: 1, sfxPitch: 1,
img: '/client-assets/drop-and-fusion/1000yen.png', img: '/client-assets/drop-and-fusion/1000yen.png',
imgSizeX: 512, imgSizeX: 512,
@ -352,12 +268,6 @@ const YEN_MONOS: Mono[] = [{
spriteScale: 0.97, spriteScale: 0.97,
}, { }, {
id: '2aae82bc-3fa4-49ad-a6b5-94d888e809f5', id: '2aae82bc-3fa4-49ad-a6b5-94d888e809f5',
level: 6,
sizeX: YEN_BASE_SIZE * 1.25 * 1.25 * 1.25 * 1.25 * 1.25,
sizeY: YEN_BASE_SIZE * 1.25 * 1.25 * 1.25 * 1.25 * 1.25,
shape: 'circle',
score: 500,
dropCandidate: false,
sfxPitch: 1.5, sfxPitch: 1.5,
img: '/client-assets/drop-and-fusion/500yen.png', img: '/client-assets/drop-and-fusion/500yen.png',
imgSizeX: 256, imgSizeX: 256,
@ -365,12 +275,6 @@ const YEN_MONOS: Mono[] = [{
spriteScale: 0.97, spriteScale: 0.97,
}, { }, {
id: 'a619bd67-d08f-4cc0-8c7e-c8072a4950cd', id: 'a619bd67-d08f-4cc0-8c7e-c8072a4950cd',
level: 5,
sizeX: YEN_BASE_SIZE * 1.25 * 1.25 * 1.25 * 1.25,
sizeY: YEN_BASE_SIZE * 1.25 * 1.25 * 1.25 * 1.25,
shape: 'circle',
score: 100,
dropCandidate: true,
sfxPitch: 2, sfxPitch: 2,
img: '/client-assets/drop-and-fusion/100yen.png', img: '/client-assets/drop-and-fusion/100yen.png',
imgSizeX: 256, imgSizeX: 256,
@ -378,12 +282,6 @@ const YEN_MONOS: Mono[] = [{
spriteScale: 0.97, spriteScale: 0.97,
}, { }, {
id: 'c1c5d8e4-17d6-4455-befd-12154d731faa', id: 'c1c5d8e4-17d6-4455-befd-12154d731faa',
level: 4,
sizeX: YEN_BASE_SIZE * 1.25 * 1.25 * 1.25,
sizeY: YEN_BASE_SIZE * 1.25 * 1.25 * 1.25,
shape: 'circle',
score: 50,
dropCandidate: true,
sfxPitch: 2.5, sfxPitch: 2.5,
img: '/client-assets/drop-and-fusion/50yen.png', img: '/client-assets/drop-and-fusion/50yen.png',
imgSizeX: 256, imgSizeX: 256,
@ -391,12 +289,6 @@ const YEN_MONOS: Mono[] = [{
spriteScale: 0.97, spriteScale: 0.97,
}, { }, {
id: '7082648c-e428-44c4-887a-25c07a8ebdd5', id: '7082648c-e428-44c4-887a-25c07a8ebdd5',
level: 3,
sizeX: YEN_BASE_SIZE * 1.25 * 1.25,
sizeY: YEN_BASE_SIZE * 1.25 * 1.25,
shape: 'circle',
score: 10,
dropCandidate: true,
sfxPitch: 3, sfxPitch: 3,
img: '/client-assets/drop-and-fusion/10yen.png', img: '/client-assets/drop-and-fusion/10yen.png',
imgSizeX: 256, imgSizeX: 256,
@ -404,12 +296,6 @@ const YEN_MONOS: Mono[] = [{
spriteScale: 0.97, spriteScale: 0.97,
}, { }, {
id: '0d8d40d5-e6e0-4d26-8a95-b8d842363379', id: '0d8d40d5-e6e0-4d26-8a95-b8d842363379',
level: 2,
sizeX: YEN_BASE_SIZE * 1.25,
sizeY: YEN_BASE_SIZE * 1.25,
shape: 'circle',
score: 5,
dropCandidate: true,
sfxPitch: 3.5, sfxPitch: 3.5,
img: '/client-assets/drop-and-fusion/5yen.png', img: '/client-assets/drop-and-fusion/5yen.png',
imgSizeX: 256, imgSizeX: 256,
@ -417,12 +303,6 @@ const YEN_MONOS: Mono[] = [{
spriteScale: 0.97, spriteScale: 0.97,
}, { }, {
id: '9dec1b38-d99d-40de-8288-37367b983d0d', id: '9dec1b38-d99d-40de-8288-37367b983d0d',
level: 1,
sizeX: YEN_BASE_SIZE,
sizeY: YEN_BASE_SIZE,
shape: 'circle',
score: 1,
dropCandidate: true,
sfxPitch: 4, sfxPitch: 4,
img: '/client-assets/drop-and-fusion/1yen.png', img: '/client-assets/drop-and-fusion/1yen.png',
imgSizeX: 256, imgSizeX: 256,
@ -430,15 +310,8 @@ const YEN_MONOS: Mono[] = [{
spriteScale: 0.97, spriteScale: 0.97,
}]; }];
const SQUARE_BASE_SIZE = 28; const SQUARE_MONOS: FrontendMonoDefinition[] = [{
const SQUARE_MONOS: Mono[] = [{
id: 'f75fd0ba-d3d4-40a4-9712-b470e45b0525', id: 'f75fd0ba-d3d4-40a4-9712-b470e45b0525',
level: 10,
sizeX: SQUARE_BASE_SIZE * 1.25 * 1.25 * 1.25 * 1.25 * 1.25 * 1.25 * 1.25 * 1.25 * 1.25,
sizeY: SQUARE_BASE_SIZE * 1.25 * 1.25 * 1.25 * 1.25 * 1.25 * 1.25 * 1.25 * 1.25 * 1.25,
shape: 'rectangle',
score: 512,
dropCandidate: false,
sfxPitch: 0.25, sfxPitch: 0.25,
img: '/client-assets/drop-and-fusion/keycap_10.png', img: '/client-assets/drop-and-fusion/keycap_10.png',
imgSizeX: 256, imgSizeX: 256,
@ -446,12 +319,6 @@ const SQUARE_MONOS: Mono[] = [{
spriteScale: 1.12, spriteScale: 1.12,
}, { }, {
id: '7b70f4af-1c01-45fd-af72-61b1f01e03d1', id: '7b70f4af-1c01-45fd-af72-61b1f01e03d1',
level: 9,
sizeX: SQUARE_BASE_SIZE * 1.25 * 1.25 * 1.25 * 1.25 * 1.25 * 1.25 * 1.25 * 1.25,
sizeY: SQUARE_BASE_SIZE * 1.25 * 1.25 * 1.25 * 1.25 * 1.25 * 1.25 * 1.25 * 1.25,
shape: 'rectangle',
score: 256,
dropCandidate: false,
sfxPitch: 0.5, sfxPitch: 0.5,
img: '/client-assets/drop-and-fusion/keycap_9.png', img: '/client-assets/drop-and-fusion/keycap_9.png',
imgSizeX: 256, imgSizeX: 256,
@ -459,12 +326,6 @@ const SQUARE_MONOS: Mono[] = [{
spriteScale: 1.12, spriteScale: 1.12,
}, { }, {
id: '41607ef3-b6d6-4829-95b6-3737bf8bb956', id: '41607ef3-b6d6-4829-95b6-3737bf8bb956',
level: 8,
sizeX: SQUARE_BASE_SIZE * 1.25 * 1.25 * 1.25 * 1.25 * 1.25 * 1.25 * 1.25,
sizeY: SQUARE_BASE_SIZE * 1.25 * 1.25 * 1.25 * 1.25 * 1.25 * 1.25 * 1.25,
shape: 'rectangle',
score: 128,
dropCandidate: false,
sfxPitch: 0.75, sfxPitch: 0.75,
img: '/client-assets/drop-and-fusion/keycap_8.png', img: '/client-assets/drop-and-fusion/keycap_8.png',
imgSizeX: 256, imgSizeX: 256,
@ -472,12 +333,6 @@ const SQUARE_MONOS: Mono[] = [{
spriteScale: 1.12, spriteScale: 1.12,
}, { }, {
id: '8a8310d2-0374-460f-bb50-ca9cd3ee3416', id: '8a8310d2-0374-460f-bb50-ca9cd3ee3416',
level: 7,
sizeX: SQUARE_BASE_SIZE * 1.25 * 1.25 * 1.25 * 1.25 * 1.25 * 1.25,
sizeY: SQUARE_BASE_SIZE * 1.25 * 1.25 * 1.25 * 1.25 * 1.25 * 1.25,
shape: 'rectangle',
score: 64,
dropCandidate: false,
sfxPitch: 1, sfxPitch: 1,
img: '/client-assets/drop-and-fusion/keycap_7.png', img: '/client-assets/drop-and-fusion/keycap_7.png',
imgSizeX: 256, imgSizeX: 256,
@ -485,12 +340,6 @@ const SQUARE_MONOS: Mono[] = [{
spriteScale: 1.12, spriteScale: 1.12,
}, { }, {
id: '1092e069-fe1a-450b-be97-b5d477ec398c', id: '1092e069-fe1a-450b-be97-b5d477ec398c',
level: 6,
sizeX: SQUARE_BASE_SIZE * 1.25 * 1.25 * 1.25 * 1.25 * 1.25,
sizeY: SQUARE_BASE_SIZE * 1.25 * 1.25 * 1.25 * 1.25 * 1.25,
shape: 'rectangle',
score: 32,
dropCandidate: false,
sfxPitch: 1.5, sfxPitch: 1.5,
img: '/client-assets/drop-and-fusion/keycap_6.png', img: '/client-assets/drop-and-fusion/keycap_6.png',
imgSizeX: 256, imgSizeX: 256,
@ -498,12 +347,6 @@ const SQUARE_MONOS: Mono[] = [{
spriteScale: 1.12, spriteScale: 1.12,
}, { }, {
id: '2294734d-7bb8-4781-bb7b-ef3820abf3d0', id: '2294734d-7bb8-4781-bb7b-ef3820abf3d0',
level: 5,
sizeX: SQUARE_BASE_SIZE * 1.25 * 1.25 * 1.25 * 1.25,
sizeY: SQUARE_BASE_SIZE * 1.25 * 1.25 * 1.25 * 1.25,
shape: 'rectangle',
score: 16,
dropCandidate: true,
sfxPitch: 2, sfxPitch: 2,
img: '/client-assets/drop-and-fusion/keycap_5.png', img: '/client-assets/drop-and-fusion/keycap_5.png',
imgSizeX: 256, imgSizeX: 256,
@ -511,12 +354,6 @@ const SQUARE_MONOS: Mono[] = [{
spriteScale: 1.12, spriteScale: 1.12,
}, { }, {
id: 'ea8a61af-e350-45f7-ba6a-366fcd65692a', id: 'ea8a61af-e350-45f7-ba6a-366fcd65692a',
level: 4,
sizeX: SQUARE_BASE_SIZE * 1.25 * 1.25 * 1.25,
sizeY: SQUARE_BASE_SIZE * 1.25 * 1.25 * 1.25,
shape: 'rectangle',
score: 8,
dropCandidate: true,
sfxPitch: 2.5, sfxPitch: 2.5,
img: '/client-assets/drop-and-fusion/keycap_4.png', img: '/client-assets/drop-and-fusion/keycap_4.png',
imgSizeX: 256, imgSizeX: 256,
@ -524,12 +361,6 @@ const SQUARE_MONOS: Mono[] = [{
spriteScale: 1.12, spriteScale: 1.12,
}, { }, {
id: 'd0c74815-fc1c-4fbe-9953-c92e4b20f919', id: 'd0c74815-fc1c-4fbe-9953-c92e4b20f919',
level: 3,
sizeX: SQUARE_BASE_SIZE * 1.25 * 1.25,
sizeY: SQUARE_BASE_SIZE * 1.25 * 1.25,
shape: 'rectangle',
score: 4,
dropCandidate: true,
sfxPitch: 3, sfxPitch: 3,
img: '/client-assets/drop-and-fusion/keycap_3.png', img: '/client-assets/drop-and-fusion/keycap_3.png',
imgSizeX: 256, imgSizeX: 256,
@ -537,12 +368,6 @@ const SQUARE_MONOS: Mono[] = [{
spriteScale: 1.12, spriteScale: 1.12,
}, { }, {
id: 'd8fbd70e-611d-402d-87da-1a7fd8cd2c8d', id: 'd8fbd70e-611d-402d-87da-1a7fd8cd2c8d',
level: 2,
sizeX: SQUARE_BASE_SIZE * 1.25,
sizeY: SQUARE_BASE_SIZE * 1.25,
shape: 'rectangle',
score: 2,
dropCandidate: true,
sfxPitch: 3.5, sfxPitch: 3.5,
img: '/client-assets/drop-and-fusion/keycap_2.png', img: '/client-assets/drop-and-fusion/keycap_2.png',
imgSizeX: 256, imgSizeX: 256,
@ -550,12 +375,6 @@ const SQUARE_MONOS: Mono[] = [{
spriteScale: 1.12, spriteScale: 1.12,
}, { }, {
id: '35e476ee-44bd-4711-ad42-87be245d3efd', id: '35e476ee-44bd-4711-ad42-87be245d3efd',
level: 1,
sizeX: SQUARE_BASE_SIZE,
sizeY: SQUARE_BASE_SIZE,
shape: 'rectangle',
score: 1,
dropCandidate: true,
sfxPitch: 4, sfxPitch: 4,
img: '/client-assets/drop-and-fusion/keycap_1.png', img: '/client-assets/drop-and-fusion/keycap_1.png',
imgSizeX: 256, imgSizeX: 256,
@ -572,11 +391,23 @@ const emit = defineEmits<{
(ev: 'end'): void; (ev: 'end'): void;
}>(); }>();
const monoDefinitions = const monoDefinitions = computed(() => {
props.gameMode === 'normal' ? NORAML_MONOS : return props.gameMode === 'normal' ? NORAML_MONOS :
props.gameMode === 'square' ? SQUARE_MONOS : props.gameMode === 'square' ? SQUARE_MONOS :
props.gameMode === 'yen' ? YEN_MONOS : props.gameMode === 'yen' ? YEN_MONOS :
[] as never; [] as never;
});
function getMonoRenderOptions(mono: Mono) {
const def = monoDefinitions.value.find(x => x.id === mono.id)!;
return {
sprite: {
texture: def.img,
xScale: (mono.sizeX / def.imgSizeX) * def.spriteScale,
yScale: (mono.sizeY / def.imgSizeY) * def.spriteScale,
},
};
}
let viewScale = 1; let viewScale = 1;
let seed: string = Date.now().toString(); let seed: string = Date.now().toString();
@ -590,8 +421,8 @@ let monoTextureUrls: Record<string, string> = {};
let tickRaf: number | null = null; let tickRaf: number | null = null;
let game = new DropAndFusionGame({ let game = new DropAndFusionGame({
seed: seed, seed: seed,
monoDefinitions, gameMode: props.gameMode,
hasComboBonus: props.gameMode !== 'yen', getMonoRenderOptions,
}); });
attachGameEvents(); attachGameEvents();
@ -609,6 +440,7 @@ const dropReady = ref(true);
const isGameOver = ref(false); const isGameOver = ref(false);
const gameLoaded = ref(false); const gameLoaded = ref(false);
const highScore = ref<number | null>(null); const highScore = ref<number | null>(null);
const yenTotal = ref<number | null>(null);
const showConfig = ref(false); const showConfig = ref(false);
const replaying = ref(false); const replaying = ref(false);
const replayPlaybackRate = ref(1); const replayPlaybackRate = ref(1);
@ -643,7 +475,7 @@ function createRendererInstance(game: DropAndFusionGame) {
} }
function loadMonoTextures() { function loadMonoTextures() {
async function loadSingleMonoTexture(mono: Mono) { async function loadSingleMonoTexture(mono: FrontendMonoDefinition) {
if (renderer == null) return; if (renderer == null) return;
// Matter-js // Matter-js
@ -670,22 +502,24 @@ function loadMonoTextures() {
renderer.textures[mono.img] = image; renderer.textures[mono.img] = image;
} }
return Promise.all(monoDefinitions.map(x => loadSingleMonoTexture(x))); return Promise.all(monoDefinitions.value.map(x => loadSingleMonoTexture(x)));
} }
function getTextureImageUrl(mono: Mono) { function getTextureImageUrl(mono: Mono) {
const def = monoDefinitions.value.find(x => x.id === mono.id)!;
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
if (monoTextureUrls[mono.img]) { if (monoTextureUrls[def.img]) {
return monoTextureUrls[mono.img]; return monoTextureUrls[def.img];
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
} else if (monoTextures[mono.img]) { } else if (monoTextures[def.img]) {
// Game使 // Game使
const out = URL.createObjectURL(monoTextures[mono.img]); const out = URL.createObjectURL(monoTextures[def.img]);
monoTextureUrls[mono.img] = out; monoTextureUrls[def.img] = out;
return out; return out;
} else { } else {
return mono.img; return def.img;
} }
} }
@ -734,8 +568,8 @@ function tickReplay() {
} }
async function start() { async function start() {
await loadMonoTextures();
renderer = createRendererInstance(game); renderer = createRendererInstance(game);
await loadMonoTextures();
Matter.Render.lookAt(renderer, { Matter.Render.lookAt(renderer, {
min: { x: 0, y: 0 }, min: { x: 0, y: 0 },
max: { x: game.GAME_WIDTH, y: game.GAME_HEIGHT }, max: { x: game.GAME_WIDTH, y: game.GAME_HEIGHT },
@ -794,8 +628,8 @@ async function restart() {
reset(); reset();
game = new DropAndFusionGame({ game = new DropAndFusionGame({
seed: seed, seed: seed,
monoDefinitions, gameMode: props.gameMode,
hasComboBonus: props.gameMode !== 'yen', getMonoRenderOptions,
}); });
attachGameEvents(); attachGameEvents();
await start(); await start();
@ -835,8 +669,8 @@ function replay() {
dispose(); dispose();
game = new DropAndFusionGame({ game = new DropAndFusionGame({
seed: seed, seed: seed,
monoDefinitions, gameMode: props.gameMode,
hasComboBonus: props.gameMode !== 'yen', getMonoRenderOptions,
replaying: true, replaying: true,
}); });
attachGameEvents(); attachGameEvents();
@ -913,7 +747,7 @@ function getGameImageDriveFile() {
ctx.fillStyle = '#000'; ctx.fillStyle = '#000';
ctx.font = '16px bold sans-serif'; ctx.font = '16px bold sans-serif';
ctx.textBaseline = 'top'; ctx.textBaseline = 'top';
ctx.fillText(`SCORE: ${score.value.toLocaleString()}`, 10, 10); ctx.fillText(`SCORE: ${score.value.toLocaleString()}${props.gameMode === 'yen' ? '円' : 'pt'}`, 10, 10);
ctx.globalAlpha = 0.7; ctx.globalAlpha = 0.7;
ctx.drawImage(logo, game.GAME_WIDTH * 0.55, 6, game.GAME_WIDTH * 0.45, game.GAME_WIDTH * 0.45 * (logo.height / logo.width)); ctx.drawImage(logo, game.GAME_WIDTH * 0.55, 6, game.GAME_WIDTH * 0.45, game.GAME_WIDTH * 0.45 * (logo.height / logo.width));
@ -953,9 +787,8 @@ async function share() {
const file = await uploading; const file = await uploading;
if (!file) return; if (!file) return;
os.post({ os.post({
initialText: `#BubbleGame initialText: `#BubbleGame (${props.gameMode})
MODE: ${props.gameMode} SCORE: ${score.value.toLocaleString()}${props.gameMode === 'yen' ? '円' : 'pt'}`,
SCORE: ${score.value.toLocaleString()} (MAX CHAIN: ${maxCombo.value})`,
initialFiles: [file], initialFiles: [file],
instant: true, instant: true,
}); });
@ -984,27 +817,32 @@ function attachGameEvents() {
game.addListener('changeHolding', value => { game.addListener('changeHolding', value => {
holdingStock.value = value; holdingStock.value = value;
sound.playUrl('/client-assets/drop-and-fusion/hold.mp3', { if (!props.mute) {
volume: 0.5 * sfxVolume.value, sound.playUrl('/client-assets/drop-and-fusion/hold.mp3', {
}); volume: 0.5 * sfxVolume.value,
playbackRate: replayPlaybackRate.value,
});
}
}); });
game.addListener('dropped', (x) => { game.addListener('dropped', (x) => {
const panV = x - game.PLAYAREA_MARGIN; if (!props.mute) {
const panW = game.GAME_WIDTH - game.PLAYAREA_MARGIN - game.PLAYAREA_MARGIN; const panV = x - game.PLAYAREA_MARGIN;
const pan = ((panV / panW) - 0.5) * 2; const panW = game.GAME_WIDTH - game.PLAYAREA_MARGIN - game.PLAYAREA_MARGIN;
if (props.gameMode === 'yen') { const pan = ((panV / panW) - 0.5) * 2;
sound.playUrl('/client-assets/drop-and-fusion/drop_yen.mp3', { if (props.gameMode === 'yen') {
volume: sfxVolume.value, sound.playUrl('/client-assets/drop-and-fusion/drop_yen.mp3', {
pan, volume: sfxVolume.value,
playbackRate: replayPlaybackRate.value, pan,
}); playbackRate: replayPlaybackRate.value,
} else { });
sound.playUrl('/client-assets/drop-and-fusion/drop.mp3', { } else {
volume: sfxVolume.value, sound.playUrl('/client-assets/drop-and-fusion/drop.mp3', {
pan, volume: sfxVolume.value,
playbackRate: replayPlaybackRate.value, pan,
}); playbackRate: replayPlaybackRate.value,
});
}
} }
if (replaying.value) return; if (replaying.value) return;
@ -1017,14 +855,73 @@ function attachGameEvents() {
}, game.DROP_INTERVAL); }, game.DROP_INTERVAL);
}); });
game.addListener('fusioned', (x, y, scoreDelta) => { game.addListener('fusioned', (x, y, nextMono, scoreDelta) => {
if (!canvasEl.value) return; if (!canvasEl.value) return;
const rect = canvasEl.value.getBoundingClientRect(); const rect = canvasEl.value.getBoundingClientRect();
const domX = rect.left + (x * viewScale); const domX = rect.left + (x * viewScale);
const domY = rect.top + (y * viewScale); const domY = rect.top + (y * viewScale);
os.popup(MkRippleEffect, { x: domX, y: domY }, {}, 'end'); os.popup(MkRippleEffect, { x: domX, y: domY }, {}, 'end');
os.popup(MkPlusOneEffect, { x: domX, y: domY, value: scoreDelta }, {}, 'end'); os.popup(MkPlusOneEffect, { x: domX, y: domY, value: scoreDelta + (props.gameMode === 'yen' ? '円' : '') }, {}, 'end');
if (nextMono) {
const def = monoDefinitions.value.find(x => x.id === nextMono.id)!;
if (!props.mute) {
const panV = x - game.PLAYAREA_MARGIN;
const panW = game.GAME_WIDTH - game.PLAYAREA_MARGIN - game.PLAYAREA_MARGIN;
const pan = ((panV / panW) - 0.5) * 2;
const pitch = def.sfxPitch;
if (props.gameMode === 'yen') {
sound.playUrl('/client-assets/drop-and-fusion/fusion_yen.mp3', {
volume: 0.25 * sfxVolume.value,
pan: pan,
playbackRate: (pitch / 4) * replayPlaybackRate.value,
});
} else {
sound.playUrl('/client-assets/drop-and-fusion/fusion.mp3', {
volume: sfxVolume.value,
pan: pan,
playbackRate: pitch * replayPlaybackRate.value,
});
}
}
} else {
if (!props.mute) {
// TODO:
}
}
});
const minCollisionEnergyForSound = 2.5;
const maxCollisionEnergyForSound = 9;
const soundPitchMax = 4;
const soundPitchMin = 0.5;
game.addListener('collision', (energy, bodyA, bodyB) => {
if (!props.mute && (energy > minCollisionEnergyForSound)) {
const volume = (Math.min(maxCollisionEnergyForSound, energy - minCollisionEnergyForSound) / maxCollisionEnergyForSound) / 4;
const panV =
bodyA.label === '_wall_' ? bodyB.position.x - game.PLAYAREA_MARGIN :
bodyB.label === '_wall_' ? bodyA.position.x - game.PLAYAREA_MARGIN :
((bodyA.position.x + bodyB.position.x) / 2) - game.PLAYAREA_MARGIN;
const panW = game.GAME_WIDTH - game.PLAYAREA_MARGIN - game.PLAYAREA_MARGIN;
const pan = ((panV / panW) - 0.5) * 2;
const pitch = soundPitchMin + ((soundPitchMax - soundPitchMin) * (1 - (Math.min(10, energy) / 10)));
if (props.gameMode === 'yen') {
sound.playUrl('/client-assets/drop-and-fusion/collision_yen.mp3', {
volume: volume * sfxVolume.value,
pan: pan,
playbackRate: Math.max(1, pitch) * replayPlaybackRate.value,
});
} else {
sound.playUrl('/client-assets/drop-and-fusion/collision.mp3', {
volume: volume * sfxVolume.value,
pan: pan,
playbackRate: pitch * replayPlaybackRate.value,
});
}
}
}); });
game.addListener('monoAdded', (mono) => { game.addListener('monoAdded', (mono) => {
@ -1042,14 +939,16 @@ function attachGameEvents() {
}); });
game.addListener('gameOver', () => { game.addListener('gameOver', () => {
if (props.gameMode === 'yen') { if (!props.mute) {
sound.playUrl('/client-assets/drop-and-fusion/gameover_yen.mp3', { if (props.gameMode === 'yen') {
volume: 0.5 * sfxVolume.value, sound.playUrl('/client-assets/drop-and-fusion/gameover_yen.mp3', {
}); volume: 0.5 * sfxVolume.value,
} else { });
sound.playUrl('/client-assets/drop-and-fusion/gameover.mp3', { } else {
volume: sfxVolume.value, sound.playUrl('/client-assets/drop-and-fusion/gameover.mp3', {
}); volume: sfxVolume.value,
});
}
} }
if (replaying.value) { if (replaying.value) {
@ -1071,6 +970,15 @@ function attachGameEvents() {
logs: DropAndFusionGame.serializeLogs(logs), logs: DropAndFusionGame.serializeLogs(logs),
}); });
if (props.gameMode === 'yen') {
yenTotal.value = (yenTotal.value ?? 0) + score.value;
misskeyApi('i/registry/set', {
scope: ['dropAndFusionGame'],
key: 'yenTotal',
value: yenTotal.value,
});
}
if (score.value > (highScore.value ?? 0)) { if (score.value > (highScore.value ?? 0)) {
highScore.value = score.value; highScore.value = score.value;
@ -1081,21 +989,6 @@ function attachGameEvents() {
}); });
} }
}); });
game.addListener('sfx', (type, params) => {
if (props.mute) return;
const soundUrl =
type === 'fusion' ? '/client-assets/drop-and-fusion/bubble2.mp3' :
type === 'collision' ? '/client-assets/drop-and-fusion/poi1.mp3' :
null as never;
sound.playUrl(soundUrl, {
volume: params.volume * sfxVolume.value,
pan: params.pan,
playbackRate: params.pitch * replayPlaybackRate.value,
});
});
} }
useInterval(() => { useInterval(() => {
@ -1116,6 +1009,25 @@ onMounted(async () => {
highScore.value = null; highScore.value = null;
} }
if (props.gameMode === 'yen') {
try {
yenTotal.value = await misskeyApi('i/registry/get', {
scope: ['dropAndFusionGame'],
key: 'yenTotal',
});
} catch (err: any) {
if (err.code === 'NO_SUCH_KEY') {
// nop
} else {
os.alert({
type: 'error',
text: i18n.ts.cannotLoad,
});
return;
}
}
}
await start(); await start();
const bgmBuffer = await sound.loadAudio('/client-assets/drop-and-fusion/bgm_1.mp3'); const bgmBuffer = await sound.loadAudio('/client-assets/drop-and-fusion/bgm_1.mp3');

View file

@ -15,11 +15,6 @@ export type Mono = {
shape: 'circle' | 'rectangle'; shape: 'circle' | 'rectangle';
score: number; score: number;
dropCandidate: boolean; dropCandidate: boolean;
sfxPitch: number;
img: string;
imgSizeX: number;
imgSizeY: number;
spriteScale: number;
}; };
type Log = { type Log = {
@ -34,16 +29,266 @@ type Log = {
operation: 'surrender'; operation: 'surrender';
}; };
const NORMAL_BASE_SIZE = 30;
const NORAML_MONOS: Mono[] = [{
id: '9377076d-c980-4d83-bdaf-175bc58275b7',
level: 10,
sizeX: NORMAL_BASE_SIZE * 1.25 * 1.25 * 1.25 * 1.25 * 1.25 * 1.25 * 1.25 * 1.25 * 1.25,
sizeY: NORMAL_BASE_SIZE * 1.25 * 1.25 * 1.25 * 1.25 * 1.25 * 1.25 * 1.25 * 1.25 * 1.25,
shape: 'circle',
score: 512,
dropCandidate: false,
}, {
id: 'be9f38d2-b267-4b1a-b420-904e22e80568',
level: 9,
sizeX: NORMAL_BASE_SIZE * 1.25 * 1.25 * 1.25 * 1.25 * 1.25 * 1.25 * 1.25 * 1.25,
sizeY: NORMAL_BASE_SIZE * 1.25 * 1.25 * 1.25 * 1.25 * 1.25 * 1.25 * 1.25 * 1.25,
shape: 'circle',
score: 256,
dropCandidate: false,
}, {
id: 'beb30459-b064-4888-926b-f572e4e72e0c',
level: 8,
sizeX: NORMAL_BASE_SIZE * 1.25 * 1.25 * 1.25 * 1.25 * 1.25 * 1.25 * 1.25,
sizeY: NORMAL_BASE_SIZE * 1.25 * 1.25 * 1.25 * 1.25 * 1.25 * 1.25 * 1.25,
shape: 'circle',
score: 128,
dropCandidate: false,
}, {
id: 'feab6426-d9d8-49ae-849c-048cdbb6cdf0',
level: 7,
sizeX: NORMAL_BASE_SIZE * 1.25 * 1.25 * 1.25 * 1.25 * 1.25 * 1.25,
sizeY: NORMAL_BASE_SIZE * 1.25 * 1.25 * 1.25 * 1.25 * 1.25 * 1.25,
shape: 'circle',
score: 64,
dropCandidate: false,
}, {
id: 'd6d8fed6-6d18-4726-81a1-6cf2c974df8a',
level: 6,
sizeX: NORMAL_BASE_SIZE * 1.25 * 1.25 * 1.25 * 1.25 * 1.25,
sizeY: NORMAL_BASE_SIZE * 1.25 * 1.25 * 1.25 * 1.25 * 1.25,
shape: 'circle',
score: 32,
dropCandidate: false,
}, {
id: '249c728e-230f-4332-bbbf-281c271c75b2',
level: 5,
sizeX: NORMAL_BASE_SIZE * 1.25 * 1.25 * 1.25 * 1.25,
sizeY: NORMAL_BASE_SIZE * 1.25 * 1.25 * 1.25 * 1.25,
shape: 'circle',
score: 16,
dropCandidate: true,
}, {
id: '23d67613-d484-4a93-b71e-3e81b19d6186',
level: 4,
sizeX: NORMAL_BASE_SIZE * 1.25 * 1.25 * 1.25,
sizeY: NORMAL_BASE_SIZE * 1.25 * 1.25 * 1.25,
shape: 'circle',
score: 8,
dropCandidate: true,
}, {
id: '3cbd0add-ad7d-4685-bad0-29f6dddc0b99',
level: 3,
sizeX: NORMAL_BASE_SIZE * 1.25 * 1.25,
sizeY: NORMAL_BASE_SIZE * 1.25 * 1.25,
shape: 'circle',
score: 4,
dropCandidate: true,
}, {
id: '8f86d4f4-ee02-41bf-ad38-1ce0ae457fb5',
level: 2,
sizeX: NORMAL_BASE_SIZE * 1.25,
sizeY: NORMAL_BASE_SIZE * 1.25,
shape: 'circle',
score: 2,
dropCandidate: true,
}, {
id: '64ec4add-ce39-42b4-96cb-33908f3f118d',
level: 1,
sizeX: NORMAL_BASE_SIZE,
sizeY: NORMAL_BASE_SIZE,
shape: 'circle',
score: 1,
dropCandidate: true,
}];
const YEN_BASE_SIZE = 30;
const YEN_SATSU_BASE_SIZE = 70;
const YEN_MONOS: Mono[] = [{
id: '880f9bd9-802f-4135-a7e1-fd0e0331f726',
level: 10,
sizeX: (YEN_SATSU_BASE_SIZE * 2) * 1.25 * 1.25 * 1.25,
sizeY: YEN_SATSU_BASE_SIZE * 1.25 * 1.25 * 1.25,
shape: 'rectangle',
score: 10000,
dropCandidate: false,
}, {
id: 'e807beb6-374a-4314-9cc2-aa5f17d96b6b',
level: 9,
sizeX: (YEN_SATSU_BASE_SIZE * 2) * 1.25 * 1.25,
sizeY: YEN_SATSU_BASE_SIZE * 1.25 * 1.25,
shape: 'rectangle',
score: 5000,
dropCandidate: false,
}, {
id: '033445b7-8f90-4fc9-beca-71a9e87cb530',
level: 8,
sizeX: (YEN_SATSU_BASE_SIZE * 2) * 1.25,
sizeY: YEN_SATSU_BASE_SIZE * 1.25,
shape: 'rectangle',
score: 2000,
dropCandidate: false,
}, {
id: '410a09ec-5f7f-46f6-b26f-cbca4ccbd091',
level: 7,
sizeX: YEN_SATSU_BASE_SIZE * 2,
sizeY: YEN_SATSU_BASE_SIZE,
shape: 'rectangle',
score: 1000,
dropCandidate: false,
}, {
id: '2aae82bc-3fa4-49ad-a6b5-94d888e809f5',
level: 6,
sizeX: YEN_BASE_SIZE * 1.25 * 1.25 * 1.25 * 1.25 * 1.25,
sizeY: YEN_BASE_SIZE * 1.25 * 1.25 * 1.25 * 1.25 * 1.25,
shape: 'circle',
score: 500,
dropCandidate: false,
}, {
id: 'a619bd67-d08f-4cc0-8c7e-c8072a4950cd',
level: 5,
sizeX: YEN_BASE_SIZE * 1.25 * 1.25 * 1.25 * 1.25,
sizeY: YEN_BASE_SIZE * 1.25 * 1.25 * 1.25 * 1.25,
shape: 'circle',
score: 100,
dropCandidate: true,
}, {
id: 'c1c5d8e4-17d6-4455-befd-12154d731faa',
level: 4,
sizeX: YEN_BASE_SIZE * 1.25 * 1.25 * 1.25,
sizeY: YEN_BASE_SIZE * 1.25 * 1.25 * 1.25,
shape: 'circle',
score: 50,
dropCandidate: true,
}, {
id: '7082648c-e428-44c4-887a-25c07a8ebdd5',
level: 3,
sizeX: YEN_BASE_SIZE * 1.25 * 1.25,
sizeY: YEN_BASE_SIZE * 1.25 * 1.25,
shape: 'circle',
score: 10,
dropCandidate: true,
}, {
id: '0d8d40d5-e6e0-4d26-8a95-b8d842363379',
level: 2,
sizeX: YEN_BASE_SIZE * 1.25,
sizeY: YEN_BASE_SIZE * 1.25,
shape: 'circle',
score: 5,
dropCandidate: true,
}, {
id: '9dec1b38-d99d-40de-8288-37367b983d0d',
level: 1,
sizeX: YEN_BASE_SIZE,
sizeY: YEN_BASE_SIZE,
shape: 'circle',
score: 1,
dropCandidate: true,
}];
const SQUARE_BASE_SIZE = 28;
const SQUARE_MONOS: Mono[] = [{
id: 'f75fd0ba-d3d4-40a4-9712-b470e45b0525',
level: 10,
sizeX: SQUARE_BASE_SIZE * 1.25 * 1.25 * 1.25 * 1.25 * 1.25 * 1.25 * 1.25 * 1.25 * 1.25,
sizeY: SQUARE_BASE_SIZE * 1.25 * 1.25 * 1.25 * 1.25 * 1.25 * 1.25 * 1.25 * 1.25 * 1.25,
shape: 'rectangle',
score: 512,
dropCandidate: false,
}, {
id: '7b70f4af-1c01-45fd-af72-61b1f01e03d1',
level: 9,
sizeX: SQUARE_BASE_SIZE * 1.25 * 1.25 * 1.25 * 1.25 * 1.25 * 1.25 * 1.25 * 1.25,
sizeY: SQUARE_BASE_SIZE * 1.25 * 1.25 * 1.25 * 1.25 * 1.25 * 1.25 * 1.25 * 1.25,
shape: 'rectangle',
score: 256,
dropCandidate: false,
}, {
id: '41607ef3-b6d6-4829-95b6-3737bf8bb956',
level: 8,
sizeX: SQUARE_BASE_SIZE * 1.25 * 1.25 * 1.25 * 1.25 * 1.25 * 1.25 * 1.25,
sizeY: SQUARE_BASE_SIZE * 1.25 * 1.25 * 1.25 * 1.25 * 1.25 * 1.25 * 1.25,
shape: 'rectangle',
score: 128,
dropCandidate: false,
}, {
id: '8a8310d2-0374-460f-bb50-ca9cd3ee3416',
level: 7,
sizeX: SQUARE_BASE_SIZE * 1.25 * 1.25 * 1.25 * 1.25 * 1.25 * 1.25,
sizeY: SQUARE_BASE_SIZE * 1.25 * 1.25 * 1.25 * 1.25 * 1.25 * 1.25,
shape: 'rectangle',
score: 64,
dropCandidate: false,
}, {
id: '1092e069-fe1a-450b-be97-b5d477ec398c',
level: 6,
sizeX: SQUARE_BASE_SIZE * 1.25 * 1.25 * 1.25 * 1.25 * 1.25,
sizeY: SQUARE_BASE_SIZE * 1.25 * 1.25 * 1.25 * 1.25 * 1.25,
shape: 'rectangle',
score: 32,
dropCandidate: false,
}, {
id: '2294734d-7bb8-4781-bb7b-ef3820abf3d0',
level: 5,
sizeX: SQUARE_BASE_SIZE * 1.25 * 1.25 * 1.25 * 1.25,
sizeY: SQUARE_BASE_SIZE * 1.25 * 1.25 * 1.25 * 1.25,
shape: 'rectangle',
score: 16,
dropCandidate: true,
}, {
id: 'ea8a61af-e350-45f7-ba6a-366fcd65692a',
level: 4,
sizeX: SQUARE_BASE_SIZE * 1.25 * 1.25 * 1.25,
sizeY: SQUARE_BASE_SIZE * 1.25 * 1.25 * 1.25,
shape: 'rectangle',
score: 8,
dropCandidate: true,
}, {
id: 'd0c74815-fc1c-4fbe-9953-c92e4b20f919',
level: 3,
sizeX: SQUARE_BASE_SIZE * 1.25 * 1.25,
sizeY: SQUARE_BASE_SIZE * 1.25 * 1.25,
shape: 'rectangle',
score: 4,
dropCandidate: true,
}, {
id: 'd8fbd70e-611d-402d-87da-1a7fd8cd2c8d',
level: 2,
sizeX: SQUARE_BASE_SIZE * 1.25,
sizeY: SQUARE_BASE_SIZE * 1.25,
shape: 'rectangle',
score: 2,
dropCandidate: true,
}, {
id: '35e476ee-44bd-4711-ad42-87be245d3efd',
level: 1,
sizeX: SQUARE_BASE_SIZE,
sizeY: SQUARE_BASE_SIZE,
shape: 'rectangle',
score: 1,
dropCandidate: true,
}];
export class DropAndFusionGame extends EventEmitter<{ export class DropAndFusionGame extends EventEmitter<{
changeScore: (newScore: number) => void; changeScore: (newScore: number) => void;
changeCombo: (newCombo: number) => void; changeCombo: (newCombo: number) => void;
changeStock: (newStock: { id: string; mono: Mono }[]) => void; changeStock: (newStock: { id: string; mono: Mono }[]) => void;
changeHolding: (newHolding: { id: string; mono: Mono } | null) => void; changeHolding: (newHolding: { id: string; mono: Mono } | null) => void;
dropped: (x: number) => void; dropped: (x: number) => void;
fusioned: (x: number, y: number, scoreDelta: number) => void; fusioned: (x: number, y: number, nextMono: Mono | null, scoreDelta: number) => void;
collision: (energy: number, bodyA: Matter.Body, bodyB: Matter.Body) => void;
monoAdded: (mono: Mono) => void; monoAdded: (mono: Mono) => void;
gameOver: () => void; gameOver: () => void;
sfx(type: string, params: { volume: number; pan: number; pitch: number; }): void;
}> { }> {
private PHYSICS_QUALITY_FACTOR = 16; // 低いほどパフォーマンスが高いがガタガタして安定しなくなる、逆に高すぎても何故か不安定になる private PHYSICS_QUALITY_FACTOR = 16; // 低いほどパフォーマンスが高いがガタガタして安定しなくなる、逆に高すぎても何故か不安定になる
private COMBO_INTERVAL = 60; // frame private COMBO_INTERVAL = 60; // frame
@ -60,8 +305,7 @@ export class DropAndFusionGame extends EventEmitter<{
private tickCallbackQueue: { frame: number; callback: () => void; }[] = []; private tickCallbackQueue: { frame: number; callback: () => void; }[] = [];
private overflowCollider: Matter.Body; private overflowCollider: Matter.Body;
private isGameOver = false; private isGameOver = false;
private monoDefinitions: Mono[] = []; private gameMode: 'normal' | 'yen' | 'square';
private hasComboBonus = true;
private rng: () => number; private rng: () => number;
private logs: Log[] = []; private logs: Log[] = [];
private replaying = false; private replaying = false;
@ -84,6 +328,17 @@ export class DropAndFusionGame extends EventEmitter<{
private stock: { id: string; mono: Mono }[] = []; private stock: { id: string; mono: Mono }[] = [];
private holding: { id: string; mono: Mono } | null = null; private holding: { id: string; mono: Mono } | null = null;
private get monoDefinitions() {
switch (this.gameMode) {
case 'normal':
return NORAML_MONOS;
case 'yen':
return YEN_MONOS;
case 'square':
return SQUARE_MONOS;
}
}
private _combo = 0; private _combo = 0;
private get combo() { private get combo() {
return this._combo; return this._combo;
@ -102,22 +357,26 @@ export class DropAndFusionGame extends EventEmitter<{
this.emit('changeScore', value); this.emit('changeScore', value);
} }
private getMonoRenderOptions: null | ((mono: Mono) => Partial<Matter.IBodyRenderOptions>) = null;
public replayPlaybackRate = 1; public replayPlaybackRate = 1;
constructor(env: { constructor(env: {
monoDefinitions: Mono[];
seed: string; seed: string;
hasComboBonus: boolean; gameMode: DropAndFusionGame['gameMode'];
replaying?: boolean; replaying?: boolean;
getMonoRenderOptions?: (mono: Mono) => Partial<Matter.IBodyRenderOptions>;
}) { }) {
super(); super();
this.replaying = !!env.replaying; //#region BIND
this.monoDefinitions = env.monoDefinitions;
this.hasComboBonus = env.hasComboBonus;
this.rng = seedrandom(env.seed);
this.tick = this.tick.bind(this); this.tick = this.tick.bind(this);
//#endregion
this.replaying = !!env.replaying;
this.gameMode = env.gameMode;
this.getMonoRenderOptions = env.getMonoRenderOptions ?? null;
this.rng = seedrandom(env.seed);
this.engine = Matter.Engine.create({ this.engine = Matter.Engine.create({
constraintIterations: 2 * this.PHYSICS_QUALITY_FACTOR, constraintIterations: 2 * this.PHYSICS_QUALITY_FACTOR,
@ -182,13 +441,7 @@ export class DropAndFusionGame extends EventEmitter<{
frictionStatic: 5, frictionStatic: 5,
slop: 1.0, slop: 1.0,
//mass: 0, //mass: 0,
render: { render: this.getMonoRenderOptions ? this.getMonoRenderOptions(mono) : undefined,
sprite: {
texture: mono.img,
xScale: (mono.sizeX / mono.imgSizeX) * mono.spriteScale,
yScale: (mono.sizeY / mono.imgSizeY) * mono.spriteScale,
},
},
}; };
if (mono.shape === 'circle') { if (mono.shape === 'circle') {
return Matter.Bodies.circle(x, y, mono.sizeX / 2, options); return Matter.Bodies.circle(x, y, mono.sizeX / 2, options);
@ -217,7 +470,7 @@ export class DropAndFusionGame extends EventEmitter<{
Matter.Composite.remove(this.engine.world, [bodyA, bodyB]); Matter.Composite.remove(this.engine.world, [bodyA, bodyB]);
const currentMono = this.monoDefinitions.find(y => y.id === bodyA.label)!; const currentMono = this.monoDefinitions.find(y => y.id === bodyA.label)!;
const nextMono = this.monoDefinitions.find(x => x.level === currentMono.level + 1); const nextMono = this.monoDefinitions.find(x => x.level === currentMono.level + 1) ?? null;
if (nextMono) { if (nextMono) {
const body = this.createBody(nextMono, newX, newY); const body = this.createBody(nextMono, newX, newY);
@ -231,28 +484,17 @@ export class DropAndFusionGame extends EventEmitter<{
}, },
}); });
const comboBonus = this.hasComboBonus ? 1 + ((this.combo - 1) / 5) : 1;
const additionalScore = Math.round(currentMono.score * comboBonus);
this.score += additionalScore;
this.emit('monoAdded', nextMono); this.emit('monoAdded', nextMono);
this.emit('fusioned', newX, newY, additionalScore);
const panV = newX - this.PLAYAREA_MARGIN;
const panW = this.GAME_WIDTH - this.PLAYAREA_MARGIN - this.PLAYAREA_MARGIN;
const pan = ((panV / panW) - 0.5) * 2;
this.emit('sfx', 'fusion', { volume: 1, pan, pitch: nextMono.sfxPitch });
} else {
// nop
} }
const comboBonus = this.gameMode === 'yen' ? 1 : 1 + ((this.combo - 1) / 5);
const additionalScore = Math.round(currentMono.score * comboBonus);
this.score += additionalScore;
this.emit('fusioned', newX, newY, nextMono, additionalScore);
} }
private onCollision(event: Matter.IEventCollision<Matter.Engine>) { private onCollision(event: Matter.IEventCollision<Matter.Engine>) {
const minCollisionEnergyForSound = 2.5;
const maxCollisionEnergyForSound = 9;
const soundPitchMax = 4;
const soundPitchMin = 0.5;
for (const pairs of event.pairs) { for (const pairs of event.pairs) {
const { bodyA, bodyB } = pairs; const { bodyA, bodyB } = pairs;
@ -277,6 +519,8 @@ export class DropAndFusionGame extends EventEmitter<{
}); });
} }
} else { } else {
const energy = pairs.collision.depth;
if (bodyA.label === '_overflow_' || bodyB.label === '_overflow_') continue; if (bodyA.label === '_overflow_' || bodyB.label === '_overflow_') continue;
if (bodyA.label !== '_wall_' && bodyB.label !== '_wall_') { if (bodyA.label !== '_wall_' && bodyB.label !== '_wall_') {
@ -284,18 +528,7 @@ export class DropAndFusionGame extends EventEmitter<{
if (!this.gameOverReadyBodyIds.includes(bodyB.id)) this.gameOverReadyBodyIds.push(bodyB.id); if (!this.gameOverReadyBodyIds.includes(bodyB.id)) this.gameOverReadyBodyIds.push(bodyB.id);
} }
const energy = pairs.collision.depth; this.emit('collision', energy, bodyA, bodyB);
if (energy > minCollisionEnergyForSound) {
const volume = (Math.min(maxCollisionEnergyForSound, energy - minCollisionEnergyForSound) / maxCollisionEnergyForSound) / 4;
const panV =
bodyA.label === '_wall_' ? bodyB.position.x - this.PLAYAREA_MARGIN :
bodyB.label === '_wall_' ? bodyA.position.x - this.PLAYAREA_MARGIN :
((bodyA.position.x + bodyB.position.x) / 2) - this.PLAYAREA_MARGIN;
const panW = this.GAME_WIDTH - this.PLAYAREA_MARGIN - this.PLAYAREA_MARGIN;
const pan = ((panV / panW) - 0.5) * 2;
const pitch = soundPitchMin + ((soundPitchMax - soundPitchMin) * (1 - (Math.min(10, energy) / 10)));
this.emit('sfx', 'collision', { volume, pan, pitch });
}
} }
} }
} }