Merge branch 'develop' into feat-12909
							
								
								
									
										22
									
								
								packages/backend/migration/1704373210054-support-mcaptcha.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						| @@ -0,0 +1,22 @@ | ||||
| /* | ||||
|  * SPDX-FileCopyrightText: syuilo and other misskey contributors | ||||
|  * SPDX-License-Identifier: AGPL-3.0-only | ||||
|  */ | ||||
|  | ||||
| export class SupportMcaptcha1704373210054 { | ||||
|     name = 'SupportMcaptcha1704373210054' | ||||
|  | ||||
|     async up(queryRunner) { | ||||
|         await queryRunner.query(`ALTER TABLE "meta" ADD "enableMcaptcha" boolean NOT NULL DEFAULT false`); | ||||
|         await queryRunner.query(`ALTER TABLE "meta" ADD "mcaptchaSitekey" character varying(1024)`); | ||||
|         await queryRunner.query(`ALTER TABLE "meta" ADD "mcaptchaSecretKey" character varying(1024)`); | ||||
|         await queryRunner.query(`ALTER TABLE "meta" ADD "mcaptchaInstanceUrl" character varying(1024)`); | ||||
|     } | ||||
|  | ||||
|     async down(queryRunner) { | ||||
|         await queryRunner.query(`ALTER TABLE "meta" DROP COLUMN "mcaptchaInstanceUrl"`); | ||||
|         await queryRunner.query(`ALTER TABLE "meta" DROP COLUMN "mcaptchaSecretKey"`); | ||||
|         await queryRunner.query(`ALTER TABLE "meta" DROP COLUMN "mcaptchaSitekey"`); | ||||
|         await queryRunner.query(`ALTER TABLE "meta" DROP COLUMN "enableMcaptcha"`); | ||||
|     } | ||||
| } | ||||
| @@ -73,6 +73,37 @@ export class CaptchaService { | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	// https://codeberg.org/Gusted/mCaptcha/src/branch/main/mcaptcha.go | ||||
| 	@bindThis | ||||
| 	public async verifyMcaptcha(secret: string, siteKey: string, instanceHost: string, response: string | null | undefined): Promise<void> { | ||||
| 		if (response == null) { | ||||
| 			throw new Error('mcaptcha-failed: no response provided'); | ||||
| 		} | ||||
|  | ||||
| 		const endpointUrl = new URL('/api/v1/pow/siteverify', instanceHost); | ||||
| 		const result = await this.httpRequestService.send(endpointUrl.toString(), { | ||||
| 			method: 'POST', | ||||
| 			body: JSON.stringify({ | ||||
| 				key: siteKey, | ||||
| 				secret: secret, | ||||
| 				token: response, | ||||
| 			}), | ||||
| 			headers: { | ||||
| 				'Content-Type': 'application/json', | ||||
| 			}, | ||||
| 		}); | ||||
|  | ||||
| 		if (result.status !== 200) { | ||||
| 			throw new Error('mcaptcha-failed: mcaptcha didn\'t return 200 OK'); | ||||
| 		} | ||||
|  | ||||
| 		const resp = (await result.json()) as { valid: boolean }; | ||||
|  | ||||
| 		if (!resp.valid) { | ||||
| 			throw new Error('mcaptcha-request-failed'); | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	@bindThis | ||||
| 	public async verifyTurnstile(secret: string, response: string | null | undefined): Promise<void> { | ||||
| 		if (response == null) { | ||||
|   | ||||
| @@ -191,6 +191,29 @@ export class MiMeta { | ||||
| 	}) | ||||
| 	public hcaptchaSecretKey: string | null; | ||||
|  | ||||
| 	@Column('boolean', { | ||||
| 		default: false, | ||||
| 	}) | ||||
| 	public enableMcaptcha: boolean; | ||||
|  | ||||
| 	@Column('varchar', { | ||||
| 		length: 1024, | ||||
| 		nullable: true, | ||||
| 	}) | ||||
| 	public mcaptchaSitekey: string | null; | ||||
|  | ||||
| 	@Column('varchar', { | ||||
| 		length: 1024, | ||||
| 		nullable: true, | ||||
| 	}) | ||||
| 	public mcaptchaSecretKey: string | null; | ||||
|  | ||||
| 	@Column('varchar', { | ||||
| 		length: 1024, | ||||
| 		nullable: true, | ||||
| 	}) | ||||
| 	public mcaptchaInstanceUrl: string | null; | ||||
|  | ||||
| 	@Column('boolean', { | ||||
| 		default: false, | ||||
| 	}) | ||||
| @@ -467,7 +490,7 @@ export class MiMeta { | ||||
| 		nullable: true, | ||||
| 	}) | ||||
| 	public truemailInstance: string | null; | ||||
| 	 | ||||
|  | ||||
| 	@Column('varchar', { | ||||
| 		length: 1024, | ||||
| 		nullable: true, | ||||
|   | ||||
| @@ -65,6 +65,7 @@ export class SignupApiService { | ||||
| 				'hcaptcha-response'?: string; | ||||
| 				'g-recaptcha-response'?: string; | ||||
| 				'turnstile-response'?: string; | ||||
| 				'm-captcha-response'?: string; | ||||
| 			} | ||||
| 		}>, | ||||
| 		reply: FastifyReply, | ||||
| @@ -82,6 +83,12 @@ export class SignupApiService { | ||||
| 				}); | ||||
| 			} | ||||
|  | ||||
| 			if (instance.enableMcaptcha && instance.mcaptchaSecretKey && instance.mcaptchaSitekey && instance.mcaptchaInstanceUrl) { | ||||
| 				await this.captchaService.verifyMcaptcha(instance.mcaptchaSecretKey, instance.mcaptchaSitekey, instance.mcaptchaInstanceUrl, body['m-captcha-response']).catch(err => { | ||||
| 					throw new FastifyReplyError(400, err); | ||||
| 				}); | ||||
| 			} | ||||
|  | ||||
| 			if (instance.enableRecaptcha && instance.recaptchaSecretKey) { | ||||
| 				await this.captchaService.verifyRecaptcha(instance.recaptchaSecretKey, body['g-recaptcha-response']).catch(err => { | ||||
| 					throw new FastifyReplyError(400, err); | ||||
|   | ||||
| @@ -41,6 +41,18 @@ export const meta = { | ||||
| 				type: 'string', | ||||
| 				optional: false, nullable: true, | ||||
| 			}, | ||||
| 			enableMcaptcha: { | ||||
| 				type: 'boolean', | ||||
| 				optional: false, nullable: false, | ||||
| 			}, | ||||
| 			mcaptchaSiteKey: { | ||||
| 				type: 'string', | ||||
| 				optional: false, nullable: true, | ||||
| 			}, | ||||
| 			mcaptchaInstanceUrl: { | ||||
| 				type: 'string', | ||||
| 				optional: false, nullable: true, | ||||
| 			}, | ||||
| 			enableRecaptcha: { | ||||
| 				type: 'boolean', | ||||
| 				optional: false, nullable: false, | ||||
| @@ -163,6 +175,10 @@ export const meta = { | ||||
| 				type: 'string', | ||||
| 				optional: false, nullable: true, | ||||
| 			}, | ||||
| 			mcaptchaSecretKey: { | ||||
| 				type: 'string', | ||||
| 				optional: false, nullable: true, | ||||
| 			}, | ||||
| 			recaptchaSecretKey: { | ||||
| 				type: 'string', | ||||
| 				optional: false, nullable: true, | ||||
| @@ -468,6 +484,9 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint- | ||||
| 				emailRequiredForSignup: instance.emailRequiredForSignup, | ||||
| 				enableHcaptcha: instance.enableHcaptcha, | ||||
| 				hcaptchaSiteKey: instance.hcaptchaSiteKey, | ||||
| 				enableMcaptcha: instance.enableMcaptcha, | ||||
| 				mcaptchaSiteKey: instance.mcaptchaSitekey, | ||||
| 				mcaptchaInstanceUrl: instance.mcaptchaInstanceUrl, | ||||
| 				enableRecaptcha: instance.enableRecaptcha, | ||||
| 				recaptchaSiteKey: instance.recaptchaSiteKey, | ||||
| 				enableTurnstile: instance.enableTurnstile, | ||||
| @@ -498,6 +517,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint- | ||||
| 				sensitiveWords: instance.sensitiveWords, | ||||
| 				preservedUsernames: instance.preservedUsernames, | ||||
| 				hcaptchaSecretKey: instance.hcaptchaSecretKey, | ||||
| 				mcaptchaSecretKey: instance.mcaptchaSecretKey, | ||||
| 				recaptchaSecretKey: instance.recaptchaSecretKey, | ||||
| 				turnstileSecretKey: instance.turnstileSecretKey, | ||||
| 				sensitiveMediaDetection: instance.sensitiveMediaDetection, | ||||
|   | ||||
| @@ -63,6 +63,10 @@ export const paramDef = { | ||||
| 		enableHcaptcha: { type: 'boolean' }, | ||||
| 		hcaptchaSiteKey: { type: 'string', nullable: true }, | ||||
| 		hcaptchaSecretKey: { type: 'string', nullable: true }, | ||||
| 		enableMcaptcha: { type: 'boolean' }, | ||||
| 		mcaptchaSiteKey: { type: 'string', nullable: true }, | ||||
| 		mcaptchaInstanceUrl: { type: 'string', nullable: true }, | ||||
| 		mcaptchaSecretKey: { type: 'string', nullable: true }, | ||||
| 		enableRecaptcha: { type: 'boolean' }, | ||||
| 		recaptchaSiteKey: { type: 'string', nullable: true }, | ||||
| 		recaptchaSecretKey: { type: 'string', nullable: true }, | ||||
| @@ -269,6 +273,22 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint- | ||||
| 				set.hcaptchaSecretKey = ps.hcaptchaSecretKey; | ||||
| 			} | ||||
|  | ||||
| 			if (ps.enableMcaptcha !== undefined) { | ||||
| 				set.enableMcaptcha = ps.enableMcaptcha; | ||||
| 			} | ||||
|  | ||||
| 			if (ps.mcaptchaSiteKey !== undefined) { | ||||
| 				set.mcaptchaSitekey = ps.mcaptchaSiteKey; | ||||
| 			} | ||||
|  | ||||
| 			if (ps.mcaptchaInstanceUrl !== undefined) { | ||||
| 				set.mcaptchaInstanceUrl = ps.mcaptchaInstanceUrl; | ||||
| 			} | ||||
|  | ||||
| 			if (ps.mcaptchaSecretKey !== undefined) { | ||||
| 				set.mcaptchaSecretKey = ps.mcaptchaSecretKey; | ||||
| 			} | ||||
|  | ||||
| 			if (ps.enableRecaptcha !== undefined) { | ||||
| 				set.enableRecaptcha = ps.enableRecaptcha; | ||||
| 			} | ||||
| @@ -472,7 +492,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint- | ||||
| 					set.verifymailAuthKey = ps.verifymailAuthKey; | ||||
| 				} | ||||
| 			} | ||||
| 			 | ||||
|  | ||||
| 			if (ps.enableTruemailApi !== undefined) { | ||||
| 				set.enableTruemailApi = ps.enableTruemailApi; | ||||
| 			} | ||||
|   | ||||
| @@ -108,6 +108,18 @@ export const meta = { | ||||
| 				type: 'string', | ||||
| 				optional: false, nullable: true, | ||||
| 			}, | ||||
| 			enableMcaptcha: { | ||||
| 				type: 'boolean', | ||||
| 				optional: false, nullable: false, | ||||
| 			}, | ||||
| 			mcaptchaSiteKey: { | ||||
| 				type: 'string', | ||||
| 				optional: false, nullable: true, | ||||
| 			}, | ||||
| 			mcaptchaInstanceUrl: { | ||||
| 				type: 'string', | ||||
| 				optional: false, nullable: true, | ||||
| 			}, | ||||
| 			enableRecaptcha: { | ||||
| 				type: 'boolean', | ||||
| 				optional: false, nullable: false, | ||||
| @@ -351,6 +363,9 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint- | ||||
| 				emailRequiredForSignup: instance.emailRequiredForSignup, | ||||
| 				enableHcaptcha: instance.enableHcaptcha, | ||||
| 				hcaptchaSiteKey: instance.hcaptchaSiteKey, | ||||
| 				enableMcaptcha: instance.enableMcaptcha, | ||||
| 				mcaptchaSiteKey: instance.mcaptchaSitekey, | ||||
| 				mcaptchaInstanceUrl: instance.mcaptchaInstanceUrl, | ||||
| 				enableRecaptcha: instance.enableRecaptcha, | ||||
| 				recaptchaSiteKey: instance.recaptchaSiteKey, | ||||
| 				enableTurnstile: instance.enableTurnstile, | ||||
|   | ||||
							
								
								
									
										
											BIN
										
									
								
								packages/frontend/assets/drop-and-fusion/cold_face.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						| After Width: | Height: | Size: 40 KiB | 
							
								
								
									
										6
									
								
								packages/frontend/assets/drop-and-fusion/drop-arrow.svg
									
									
									
									
									
										Normal file
									
								
							
							
						
						| @@ -0,0 +1,6 @@ | ||||
| <?xml version="1.0" encoding="UTF-8" standalone="no"?> | ||||
| <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"> | ||||
| <svg width="100%" height="100%" viewBox="0 0 128 128" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xml:space="preserve" xmlns:serif="http://www.serif.com/" style="fill-rule:evenodd;clip-rule:evenodd;stroke-linejoin:round;stroke-miterlimit:2;"> | ||||
|     <path d="M0,0L128,0L64,64L0,0Z" style="fill:rgb(255,61,0);"/> | ||||
|     <path d="M0,0L128,0L64,64L0,0ZM28.971,12L64,47.029C64,47.029 99.029,12 99.029,12L28.971,12Z" style="fill:rgb(255,122,0);"/> | ||||
| </svg> | ||||
| After Width: | Height: | Size: 646 B | 
							
								
								
									
										
											BIN
										
									
								
								packages/frontend/assets/drop-and-fusion/exploding_head.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						| After Width: | Height: | Size: 46 KiB | 
| After Width: | Height: | Size: 36 KiB | 
| After Width: | Height: | Size: 39 KiB | 
							
								
								
									
										25
									
								
								packages/frontend/assets/drop-and-fusion/frame.svg
									
									
									
									
									
										Normal file
									
								
							
							
						
						| After Width: | Height: | Size: 68 KiB | 
| After Width: | Height: | Size: 40 KiB | 
							
								
								
									
										
											BIN
										
									
								
								packages/frontend/assets/drop-and-fusion/heart_suit.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						| After Width: | Height: | Size: 22 KiB | 
							
								
								
									
										
											BIN
										
									
								
								packages/frontend/assets/drop-and-fusion/pleading_face.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						| After Width: | Height: | Size: 43 KiB | 
| After Width: | Height: | Size: 51 KiB | 
| After Width: | Height: | Size: 47 KiB | 
							
								
								
									
										
											BIN
										
									
								
								packages/frontend/assets/drop-and-fusion/zany_face.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						| After Width: | Height: | Size: 44 KiB | 
| @@ -19,6 +19,7 @@ | ||||
| 	"dependencies": { | ||||
| 		"@discordapp/twemoji": "15.0.2", | ||||
| 		"@github/webauthn-json": "2.1.1", | ||||
| 		"@mcaptcha/vanilla-glue": "0.1.0-alpha-3", | ||||
| 		"@misskey-dev/browser-image-resizer": "2.2.1-misskey.10", | ||||
| 		"@rollup/plugin-json": "6.1.0", | ||||
| 		"@rollup/plugin-replace": "5.0.5", | ||||
|   | ||||
| @@ -6,12 +6,16 @@ SPDX-License-Identifier: AGPL-3.0-only | ||||
| <template> | ||||
| <div> | ||||
| 	<span v-if="!available">{{ i18n.ts.waiting }}<MkEllipsis/></span> | ||||
| 	<div ref="captchaEl"></div> | ||||
| 	<div v-if="props.provider == 'mcaptcha'"> | ||||
| 		<div id="mcaptcha__widget-container" class="m-captcha-style"></div> | ||||
| 		<div ref="captchaEl"></div> | ||||
| 	</div> | ||||
| 	<div v-else ref="captchaEl"></div> | ||||
| </div> | ||||
| </template> | ||||
|  | ||||
| <script lang="ts" setup> | ||||
| import { ref, shallowRef, computed, onMounted, onBeforeUnmount, watch } from 'vue'; | ||||
| import { ref, shallowRef, computed, onMounted, onBeforeUnmount, watch, onUnmounted } from 'vue'; | ||||
| import { defaultStore } from '@/store.js'; | ||||
| import { i18n } from '@/i18n.js'; | ||||
|  | ||||
| @@ -26,7 +30,7 @@ export type Captcha = { | ||||
| 	getResponse(id: string): string; | ||||
| }; | ||||
|  | ||||
| export type CaptchaProvider = 'hcaptcha' | 'recaptcha' | 'turnstile'; | ||||
| export type CaptchaProvider = 'hcaptcha' | 'recaptcha' | 'turnstile' | 'mcaptcha'; | ||||
|  | ||||
| type CaptchaContainer = { | ||||
| 	readonly [_ in CaptchaProvider]?: Captcha; | ||||
| @@ -39,6 +43,7 @@ declare global { | ||||
| const props = defineProps<{ | ||||
| 	provider: CaptchaProvider; | ||||
| 	sitekey: string | null; // null will show error on request | ||||
| 	instanceUrl?: string | null; | ||||
| 	modelValue?: string | null; | ||||
| }>(); | ||||
|  | ||||
| @@ -55,6 +60,7 @@ const variable = computed(() => { | ||||
| 		case 'hcaptcha': return 'hcaptcha'; | ||||
| 		case 'recaptcha': return 'grecaptcha'; | ||||
| 		case 'turnstile': return 'turnstile'; | ||||
| 		case 'mcaptcha': return 'mcaptcha'; | ||||
| 	} | ||||
| }); | ||||
|  | ||||
| @@ -65,6 +71,7 @@ const src = computed(() => { | ||||
| 		case 'hcaptcha': return 'https://js.hcaptcha.com/1/api.js?render=explicit&recaptchacompat=off'; | ||||
| 		case 'recaptcha': return 'https://www.recaptcha.net/recaptcha/api.js?render=explicit'; | ||||
| 		case 'turnstile': return 'https://challenges.cloudflare.com/turnstile/v0/api.js?render=explicit'; | ||||
| 		case 'mcaptcha': return null; | ||||
| 	} | ||||
| }); | ||||
|  | ||||
| @@ -72,9 +79,9 @@ const scriptId = computed(() => `script-${props.provider}`); | ||||
|  | ||||
| const captcha = computed<Captcha>(() => window[variable.value] || {} as unknown as Captcha); | ||||
|  | ||||
| if (loaded) { | ||||
| if (loaded || props.provider === 'mcaptcha') { | ||||
| 	available.value = true; | ||||
| } else { | ||||
| } else if (src.value !== null) { | ||||
| 	(document.getElementById(scriptId.value) ?? document.head.appendChild(Object.assign(document.createElement('script'), { | ||||
| 		async: true, | ||||
| 		id: scriptId.value, | ||||
| @@ -87,7 +94,7 @@ function reset() { | ||||
| 	if (captcha.value.reset) captcha.value.reset(); | ||||
| } | ||||
|  | ||||
| function requestRender() { | ||||
| async function requestRender() { | ||||
| 	if (captcha.value.render && captchaEl.value instanceof Element) { | ||||
| 		captcha.value.render(captchaEl.value, { | ||||
| 			sitekey: props.sitekey, | ||||
| @@ -96,6 +103,15 @@ function requestRender() { | ||||
| 			'expired-callback': callback, | ||||
| 			'error-callback': callback, | ||||
| 		}); | ||||
| 	} else if (props.provider === 'mcaptcha' && props.instanceUrl && props.sitekey) { | ||||
| 		const { default: Widget } = await import('@mcaptcha/vanilla-glue'); | ||||
| 		// @ts-expect-error avoid typecheck error | ||||
| 		new Widget({ | ||||
| 			siteKey: { | ||||
| 				instanceUrl: new URL(props.instanceUrl), | ||||
| 				key: props.sitekey, | ||||
| 			}, | ||||
| 		}); | ||||
| 	} else { | ||||
| 		window.setTimeout(requestRender, 1); | ||||
| 	} | ||||
| @@ -105,14 +121,27 @@ function callback(response?: string) { | ||||
| 	emit('update:modelValue', typeof response === 'string' ? response : null); | ||||
| } | ||||
|  | ||||
| function onReceivedMessage(message: MessageEvent) { | ||||
| 	if (message.data.token) { | ||||
| 		if (props.instanceUrl && new URL(message.origin).host === new URL(props.instanceUrl).host) { | ||||
| 			callback(<string>message.data.token); | ||||
| 		} | ||||
| 	} | ||||
| } | ||||
|  | ||||
| onMounted(() => { | ||||
| 	if (available.value) { | ||||
| 		window.addEventListener('message', onReceivedMessage); | ||||
| 		requestRender(); | ||||
| 	} else { | ||||
| 		watch(available, requestRender); | ||||
| 	} | ||||
| }); | ||||
|  | ||||
| onUnmounted(() => { | ||||
| 	window.removeEventListener('message', onReceivedMessage); | ||||
| }); | ||||
|  | ||||
| onBeforeUnmount(() => { | ||||
| 	reset(); | ||||
| }); | ||||
|   | ||||
| @@ -5,7 +5,7 @@ SPDX-License-Identifier: AGPL-3.0-only | ||||
|  | ||||
| <template> | ||||
| <div :class="$style.root" :style="{ zIndex, top: `${y - 64}px`, left: `${x - 64}px` }"> | ||||
| 	<span class="text" :class="{ up }">+1</span> | ||||
| 	<span class="text" :class="{ up }">+{{ value }}</span> | ||||
| </div> | ||||
| </template> | ||||
|  | ||||
| @@ -16,7 +16,9 @@ import * as os from '@/os.js'; | ||||
| const props = withDefaults(defineProps<{ | ||||
| 	x: number; | ||||
| 	y: number; | ||||
| 	value?: number; | ||||
| }>(), { | ||||
| 	value: 1, | ||||
| }); | ||||
|  | ||||
| const emit = defineEmits<{ | ||||
|   | ||||
| @@ -63,6 +63,7 @@ SPDX-License-Identifier: AGPL-3.0-only | ||||
| 				</template> | ||||
| 			</MkInput> | ||||
| 			<MkCaptcha v-if="instance.enableHcaptcha" ref="hcaptcha" v-model="hCaptchaResponse" :class="$style.captcha" provider="hcaptcha" :sitekey="instance.hcaptchaSiteKey"/> | ||||
| 			<MkCaptcha v-if="instance.enableMcaptcha" ref="mcaptcha" v-model="mCaptchaResponse" :class="$style.captcha" provider="mcaptcha" :sitekey="instance.mcaptchaSiteKey" :instanceUrl="instance.mcaptchaInstanceUrl"/> | ||||
| 			<MkCaptcha v-if="instance.enableRecaptcha" ref="recaptcha" v-model="reCaptchaResponse" :class="$style.captcha" provider="recaptcha" :sitekey="instance.recaptchaSiteKey"/> | ||||
| 			<MkCaptcha v-if="instance.enableTurnstile" ref="turnstile" v-model="turnstileResponse" :class="$style.captcha" provider="turnstile" :sitekey="instance.turnstileSiteKey"/> | ||||
| 			<MkButton type="submit" :disabled="shouldDisableSubmitting" large gradate rounded data-cy-signup-submit style="margin: 0 auto;"> | ||||
| @@ -117,6 +118,7 @@ const passwordStrength = ref<'' | 'low' | 'medium' | 'high'>(''); | ||||
| const passwordRetypeState = ref<null | 'match' | 'not-match'>(null); | ||||
| const submitting = ref<boolean>(false); | ||||
| const hCaptchaResponse = ref<string | null>(null); | ||||
| const mCaptchaResponse = ref<string | null>(null); | ||||
| const reCaptchaResponse = ref<string | null>(null); | ||||
| const turnstileResponse = ref<string | null>(null); | ||||
| const usernameAbortController = ref<null | AbortController>(null); | ||||
| @@ -125,6 +127,7 @@ const emailAbortController = ref<null | AbortController>(null); | ||||
| const shouldDisableSubmitting = computed((): boolean => { | ||||
| 	return submitting.value || | ||||
| 		instance.enableHcaptcha && !hCaptchaResponse.value || | ||||
| 		instance.enableMcaptcha && !mCaptchaResponse.value || | ||||
| 		instance.enableRecaptcha && !reCaptchaResponse.value || | ||||
| 		instance.enableTurnstile && !turnstileResponse.value || | ||||
| 		instance.emailRequiredForSignup && emailState.value !== 'ok' || | ||||
| @@ -252,6 +255,7 @@ async function onSubmit(): Promise<void> { | ||||
| 			emailAddress: email.value, | ||||
| 			invitationCode: invitationCode.value, | ||||
| 			'hcaptcha-response': hCaptchaResponse.value, | ||||
| 			'm-captcha-response': mCaptchaResponse.value, | ||||
| 			'g-recaptcha-response': reCaptchaResponse.value, | ||||
| 			'turnstile-response': turnstileResponse.value, | ||||
| 		}); | ||||
|   | ||||
| @@ -16,13 +16,13 @@ | ||||
| 	<!-- https://developer.mozilla.org/en-US/docs/Web/HTTP/CSP --> | ||||
| 	<meta | ||||
| 		http-equiv="Content-Security-Policy" | ||||
| 		content="default-src 'self'; | ||||
| 		content="default-src 'self' https://newassets.hcaptcha.com/ https://challenges.cloudflare.com/ http://localhost:7493/; | ||||
| 			worker-src 'self'; | ||||
| 			script-src 'self' 'unsafe-eval'; | ||||
| 			script-src 'self' 'unsafe-eval' https://*.hcaptcha.com https://challenges.cloudflare.com; | ||||
| 			style-src 'self' 'unsafe-inline'; | ||||
| 			img-src 'self' data: www.google.com xn--931a.moe localhost:3000 localhost:5173 127.0.0.1:5173 127.0.0.1:3000; | ||||
| 			media-src 'self' localhost:3000 localhost:5173 127.0.0.1:5173 127.0.0.1:3000; | ||||
| 			connect-src 'self' localhost:3000 localhost:5173 127.0.0.1:5173 127.0.0.1:3000;" | ||||
| 			connect-src 'self' localhost:3000 localhost:5173 127.0.0.1:5173 127.0.0.1:3000 https://newassets.hcaptcha.com;" | ||||
| 	/> | ||||
| 	<meta property="og:site_name" content="[DEV BUILD] Misskey" /> | ||||
| 	<meta name="viewport" content="width=device-width, initial-scale=1"> | ||||
|   | ||||
| @@ -10,6 +10,7 @@ SPDX-License-Identifier: AGPL-3.0-only | ||||
| 			<MkRadios v-model="provider"> | ||||
| 				<option :value="null">{{ i18n.ts.none }} ({{ i18n.ts.notRecommended }})</option> | ||||
| 				<option value="hcaptcha">hCaptcha</option> | ||||
| 				<option value="mcaptcha">mCaptcha</option> | ||||
| 				<option value="recaptcha">reCAPTCHA</option> | ||||
| 				<option value="turnstile">Turnstile</option> | ||||
| 			</MkRadios> | ||||
| @@ -28,6 +29,24 @@ SPDX-License-Identifier: AGPL-3.0-only | ||||
| 					<MkCaptcha provider="hcaptcha" :sitekey="hcaptchaSiteKey || '10000000-ffff-ffff-ffff-000000000001'"/> | ||||
| 				</FormSlot> | ||||
| 			</template> | ||||
| 			<template v-else-if="provider === 'mcaptcha'"> | ||||
| 				<MkInput v-model="mcaptchaSiteKey"> | ||||
| 					<template #prefix><i class="ti ti-key"></i></template> | ||||
| 					<template #label>{{ i18n.ts.mcaptchaSiteKey }}</template> | ||||
| 				</MkInput> | ||||
| 				<MkInput v-model="mcaptchaSecretKey"> | ||||
| 					<template #prefix><i class="ti ti-key"></i></template> | ||||
| 					<template #label>{{ i18n.ts.mcaptchaSecretKey }}</template> | ||||
| 				</MkInput> | ||||
| 				<MkInput v-model="mcaptchaInstanceUrl"> | ||||
| 					<template #prefix><i class="ti ti-link"></i></template> | ||||
| 					<template #label>{{ i18n.ts.mcaptchaInstanceUrl }}</template> | ||||
| 				</MkInput> | ||||
| 				<FormSlot v-if="mcaptchaSiteKey && mcaptchaInstanceUrl"> | ||||
| 					<template #label>{{ i18n.ts.preview }}</template> | ||||
| 					<MkCaptcha provider="mcaptcha" :sitekey="mcaptchaSiteKey" :instanceUrl="mcaptchaInstanceUrl"/> | ||||
| 				</FormSlot> | ||||
| 			</template> | ||||
| 			<template v-else-if="provider === 'recaptcha'"> | ||||
| 				<MkInput v-model="recaptchaSiteKey"> | ||||
| 					<template #prefix><i class="ti ti-key"></i></template> | ||||
| @@ -81,6 +100,9 @@ const MkCaptcha = defineAsyncComponent(() => import('@/components/MkCaptcha.vue' | ||||
| const provider = ref<CaptchaProvider | null>(null); | ||||
| const hcaptchaSiteKey = ref<string | null>(null); | ||||
| const hcaptchaSecretKey = ref<string | null>(null); | ||||
| const mcaptchaSiteKey = ref<string | null>(null); | ||||
| const mcaptchaSecretKey = ref<string | null>(null); | ||||
| const mcaptchaInstanceUrl = ref<string | null>(null); | ||||
| const recaptchaSiteKey = ref<string | null>(null); | ||||
| const recaptchaSecretKey = ref<string | null>(null); | ||||
| const turnstileSiteKey = ref<string | null>(null); | ||||
| @@ -90,12 +112,18 @@ async function init() { | ||||
| 	const meta = await misskeyApi('admin/meta'); | ||||
| 	hcaptchaSiteKey.value = meta.hcaptchaSiteKey; | ||||
| 	hcaptchaSecretKey.value = meta.hcaptchaSecretKey; | ||||
| 	mcaptchaSiteKey.value = meta.mcaptchaSiteKey; | ||||
| 	mcaptchaSecretKey.value = meta.mcaptchaSecretKey; | ||||
| 	mcaptchaInstanceUrl.value = meta.mcaptchaInstanceUrl; | ||||
| 	recaptchaSiteKey.value = meta.recaptchaSiteKey; | ||||
| 	recaptchaSecretKey.value = meta.recaptchaSecretKey; | ||||
| 	turnstileSiteKey.value = meta.turnstileSiteKey; | ||||
| 	turnstileSecretKey.value = meta.turnstileSecretKey; | ||||
|  | ||||
| 	provider.value = meta.enableHcaptcha ? 'hcaptcha' : meta.enableRecaptcha ? 'recaptcha' : meta.enableTurnstile ? 'turnstile' : null; | ||||
| 	provider.value = meta.enableHcaptcha ? 'hcaptcha' : | ||||
| 		meta.enableRecaptcha ? 'recaptcha' : | ||||
| 		meta.enableTurnstile ? 'turnstile' : | ||||
| 		meta.enableMcaptcha ? 'mcaptcha' : null; | ||||
| } | ||||
|  | ||||
| function save() { | ||||
| @@ -103,6 +131,10 @@ function save() { | ||||
| 		enableHcaptcha: provider.value === 'hcaptcha', | ||||
| 		hcaptchaSiteKey: hcaptchaSiteKey.value, | ||||
| 		hcaptchaSecretKey: hcaptchaSecretKey.value, | ||||
| 		enableMcaptcha: provider.value === 'mcaptcha', | ||||
| 		mcaptchaSiteKey: mcaptchaSiteKey.value, | ||||
| 		mcaptchaSecretKey: mcaptchaSecretKey.value, | ||||
| 		mcaptchaInstanceUrl: mcaptchaInstanceUrl.value, | ||||
| 		enableRecaptcha: provider.value === 'recaptcha', | ||||
| 		recaptchaSiteKey: recaptchaSiteKey.value, | ||||
| 		recaptchaSecretKey: recaptchaSecretKey.value, | ||||
|   | ||||
| @@ -13,6 +13,7 @@ SPDX-License-Identifier: AGPL-3.0-only | ||||
| 					<template #icon><i class="ti ti-shield"></i></template> | ||||
| 					<template #label>{{ i18n.ts.botProtection }}</template> | ||||
| 					<template v-if="enableHcaptcha" #suffix>hCaptcha</template> | ||||
| 					<template v-else-if="enableMcaptcha" #suffix>mCaptcha</template> | ||||
| 					<template v-else-if="enableRecaptcha" #suffix>reCAPTCHA</template> | ||||
| 					<template v-else-if="enableTurnstile" #suffix>Turnstile</template> | ||||
| 					<template v-else #suffix>{{ i18n.ts.none }} ({{ i18n.ts.notRecommended }})</template> | ||||
| @@ -155,6 +156,7 @@ import { definePageMetadata } from '@/scripts/page-metadata.js'; | ||||
|  | ||||
| const summalyProxy = ref<string>(''); | ||||
| const enableHcaptcha = ref<boolean>(false); | ||||
| const enableMcaptcha = ref<boolean>(false); | ||||
| const enableRecaptcha = ref<boolean>(false); | ||||
| const enableTurnstile = ref<boolean>(false); | ||||
| const sensitiveMediaDetection = ref<string>('none'); | ||||
| @@ -174,6 +176,7 @@ async function init() { | ||||
| 	const meta = await misskeyApi('admin/meta'); | ||||
| 	summalyProxy.value = meta.summalyProxy; | ||||
| 	enableHcaptcha.value = meta.enableHcaptcha; | ||||
| 	enableMcaptcha.value = meta.enableMcaptcha; | ||||
| 	enableRecaptcha.value = meta.enableRecaptcha; | ||||
| 	enableTurnstile.value = meta.enableTurnstile; | ||||
| 	sensitiveMediaDetection.value = meta.sensitiveMediaDetection; | ||||
|   | ||||
							
								
								
									
										761
									
								
								packages/frontend/src/pages/drop-and-fusion.vue
									
									
									
									
									
										Normal file
									
								
							
							
						
						| @@ -0,0 +1,761 @@ | ||||
| <!-- | ||||
| SPDX-FileCopyrightText: syuilo and other misskey contributors | ||||
| SPDX-License-Identifier: AGPL-3.0-only | ||||
| --> | ||||
|  | ||||
| <template> | ||||
| <MkStickyContainer> | ||||
| 	<template #header><MkPageHeader/></template> | ||||
| 	<MkSpacer :contentMax="800"> | ||||
| 		<div class="_gaps_s" :class="$style.root" style="margin: 0 auto;" :style="{ maxWidth: GAME_WIDTH + 'px' }"> | ||||
| 			<div style="display: flex;"> | ||||
| 				<div :class="$style.frame" style="flex: 1; margin-right: 10px;"> | ||||
| 					<div :class="$style.frameInner"> | ||||
| 						SCORE: <b><MkNumber :value="score"/></b> | ||||
| 					</div> | ||||
| 				</div> | ||||
| 				<div :class="[$style.frame, $style.stock]" style="margin-left: auto;"> | ||||
| 					<div :class="$style.frameInner" style="text-align: center;"> | ||||
| 						NEXT >>> | ||||
| 						<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" | ||||
| 						> | ||||
| 							<div v-for="x in stock" :key="x.id" style="display: inline-block;"> | ||||
| 								<img :src="x.fruit.img" style="width: 32px;"/> | ||||
| 							</div> | ||||
| 						</TransitionGroup> | ||||
| 					</div> | ||||
| 				</div> | ||||
| 			</div> | ||||
| 			<div :class="$style.main"> | ||||
| 				<div ref="containerEl" :class="[$style.container, { [$style.gameOver]: gameOver }]" @click.stop.prevent="onClick" @touchmove="onTouchmove" @touchend="onTouchend" @mousemove="onMousemove"> | ||||
| 					<img src="/client-assets/drop-and-fusion/frame.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> | ||||
| 					<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="currentPick?.fruit.img" :class="$style.currentFruit" :style="{ top: -(currentPick?.fruit.size / 2) + 'px', left: (mouseX - (currentPick?.fruit.size / 2)) + 'px', width: `${currentPick?.fruit.size}px` }"/> | ||||
| 					</Transition> | ||||
| 					<template v-if="dropReady"> | ||||
| 						<img src="/client-assets/drop-and-fusion/drop-arrow.svg" :class="$style.currentFruitArrow" :style="{ top: (currentPick?.fruit.size / 2) + 10 + 'px', left: (mouseX - 10) + 'px', width: `20px` }"/> | ||||
| 						<div :class="$style.dropGuide" :style="{ left: (mouseX - 2) + 'px' }"/> | ||||
| 					</template> | ||||
| 					<div v-if="gameOver" :class="$style.gameOverLabel"> | ||||
| 						<div>GAME OVER!</div> | ||||
| 						<div>SCORE: <MkNumber :value="score"/></div> | ||||
| 					</div> | ||||
| 				</div> | ||||
| 			</div> | ||||
| 			<MkButton @click="restart">Restart</MkButton> | ||||
| 		</div> | ||||
| 	</MkSpacer> | ||||
| </MkStickyContainer> | ||||
| </template> | ||||
|  | ||||
| <script lang="ts" setup> | ||||
| import * as Matter from 'matter-js'; | ||||
| import { Ref, onMounted, ref, shallowRef } from 'vue'; | ||||
| import { EventEmitter } from 'eventemitter3'; | ||||
| import { definePageMetadata } from '@/scripts/page-metadata.js'; | ||||
| import * as sound from '@/scripts/sound.js'; | ||||
| import MkRippleEffect from '@/components/MkRippleEffect.vue'; | ||||
| import * as os from '@/os.js'; | ||||
| import MkNumber from '@/components/MkNumber.vue'; | ||||
| import MkPlusOneEffect from '@/components/MkPlusOneEffect.vue'; | ||||
| import MkButton from '@/components/MkButton.vue'; | ||||
|  | ||||
| const containerEl = shallowRef<HTMLElement>(); | ||||
| const canvasEl = shallowRef<HTMLCanvasElement>(); | ||||
| const mouseX = ref(0); | ||||
|  | ||||
| const BASE_SIZE = 30; | ||||
| const FRUITS = [{ | ||||
| 	id: '9377076d-c980-4d83-bdaf-175bc58275b7', | ||||
| 	level: 10, | ||||
| 	size: BASE_SIZE * 1.25 * 1.25 * 1.25 * 1.25 * 1.25 * 1.25 * 1.25 * 1.25 * 1.25, | ||||
| 	score: 512, | ||||
| 	available: false, | ||||
| 	sfxPitch: 0.25, | ||||
| 	img: '/client-assets/drop-and-fusion/exploding_head.png', | ||||
| 	imgSize: 256, | ||||
| 	spriteScale: 1.12, | ||||
| }, { | ||||
| 	id: 'be9f38d2-b267-4b1a-b420-904e22e80568', | ||||
| 	level: 9, | ||||
| 	size: BASE_SIZE * 1.25 * 1.25 * 1.25 * 1.25 * 1.25 * 1.25 * 1.25 * 1.25, | ||||
| 	score: 256, | ||||
| 	available: false, | ||||
| 	sfxPitch: 0.5, | ||||
| 	img: '/client-assets/drop-and-fusion/face_with_symbols_on_mouth.png', | ||||
| 	imgSize: 256, | ||||
| 	spriteScale: 1.12, | ||||
| }, { | ||||
| 	id: 'beb30459-b064-4888-926b-f572e4e72e0c', | ||||
| 	level: 8, | ||||
| 	size: BASE_SIZE * 1.25 * 1.25 * 1.25 * 1.25 * 1.25 * 1.25 * 1.25, | ||||
| 	score: 128, | ||||
| 	available: false, | ||||
| 	sfxPitch: 0.75, | ||||
| 	img: '/client-assets/drop-and-fusion/cold_face.png', | ||||
| 	imgSize: 256, | ||||
| 	spriteScale: 1.12, | ||||
| }, { | ||||
| 	id: 'feab6426-d9d8-49ae-849c-048cdbb6cdf0', | ||||
| 	level: 7, | ||||
| 	size: BASE_SIZE * 1.25 * 1.25 * 1.25 * 1.25 * 1.25 * 1.25, | ||||
| 	score: 64, | ||||
| 	available: false, | ||||
| 	sfxPitch: 1, | ||||
| 	img: '/client-assets/drop-and-fusion/zany_face.png', | ||||
| 	imgSize: 256, | ||||
| 	spriteScale: 1.12, | ||||
| }, { | ||||
| 	id: 'd6d8fed6-6d18-4726-81a1-6cf2c974df8a', | ||||
| 	level: 6, | ||||
| 	size: BASE_SIZE * 1.25 * 1.25 * 1.25 * 1.25 * 1.25, | ||||
| 	score: 32, | ||||
| 	available: false, | ||||
| 	sfxPitch: 1.5, | ||||
| 	img: '/client-assets/drop-and-fusion/pleading_face.png', | ||||
| 	imgSize: 256, | ||||
| 	spriteScale: 1.12, | ||||
| }, { | ||||
| 	id: '249c728e-230f-4332-bbbf-281c271c75b2', | ||||
| 	level: 5, | ||||
| 	size: BASE_SIZE * 1.25 * 1.25 * 1.25 * 1.25, | ||||
| 	score: 16, | ||||
| 	available: true, | ||||
| 	sfxPitch: 2, | ||||
| 	img: '/client-assets/drop-and-fusion/face_with_open_mouth.png', | ||||
| 	imgSize: 256, | ||||
| 	spriteScale: 1.12, | ||||
| }, { | ||||
| 	id: '23d67613-d484-4a93-b71e-3e81b19d6186', | ||||
| 	level: 4, | ||||
| 	size: BASE_SIZE * 1.25 * 1.25 * 1.25, | ||||
| 	score: 8, | ||||
| 	available: true, | ||||
| 	sfxPitch: 2.5, | ||||
| 	img: '/client-assets/drop-and-fusion/smiling_face_with_sunglasses.png', | ||||
| 	imgSize: 256, | ||||
| 	spriteScale: 1.12, | ||||
| }, { | ||||
| 	id: '3cbd0add-ad7d-4685-bad0-29f6dddc0b99', | ||||
| 	level: 3, | ||||
| 	size: BASE_SIZE * 1.25 * 1.25, | ||||
| 	score: 4, | ||||
| 	available: true, | ||||
| 	sfxPitch: 3, | ||||
| 	img: '/client-assets/drop-and-fusion/grinning_squinting_face.png', | ||||
| 	imgSize: 256, | ||||
| 	spriteScale: 1.12, | ||||
| }, { | ||||
| 	id: '8f86d4f4-ee02-41bf-ad38-1ce0ae457fb5', | ||||
| 	level: 2, | ||||
| 	size: BASE_SIZE * 1.25, | ||||
| 	score: 2, | ||||
| 	available: true, | ||||
| 	sfxPitch: 3.5, | ||||
| 	img: '/client-assets/drop-and-fusion/smiling_face_with_hearts.png', | ||||
| 	imgSize: 256, | ||||
| 	spriteScale: 1.12, | ||||
| }, { | ||||
| 	id: '64ec4add-ce39-42b4-96cb-33908f3f118d', | ||||
| 	level: 1, | ||||
| 	size: BASE_SIZE, | ||||
| 	score: 1, | ||||
| 	available: true, | ||||
| 	sfxPitch: 4, | ||||
| 	img: '/client-assets/drop-and-fusion/heart_suit.png', | ||||
| 	imgSize: 256, | ||||
| 	spriteScale: 1.12, | ||||
| }] as const; | ||||
|  | ||||
| const GAME_WIDTH = 450; | ||||
| const GAME_HEIGHT = 600; | ||||
| const PHYSICS_QUALITY_FACTOR = 32; // 低いほどパフォーマンスが高いがガタガタして安定しなくなる | ||||
|  | ||||
| let viewScaleX = 1; | ||||
| let viewScaleY = 1; | ||||
| const currentPick = shallowRef<{ id: string; fruit: typeof FRUITS[number] } | null>(null); | ||||
| const stock = shallowRef<{ id: string; fruit: typeof FRUITS[number] }[]>([]); | ||||
| const score = ref(0); | ||||
| const combo = ref(0); | ||||
| const comboPrev = ref(0); | ||||
| const dropReady = ref(true); | ||||
| const gameOver = ref(false); | ||||
| const gameStarted = ref(false); | ||||
|  | ||||
| class Game extends EventEmitter<{ | ||||
| 	changeScore: (score: number) => void; | ||||
| 	changeCombo: (combo: number) => void; | ||||
| 	changeStock: (stock: { id: string; fruit: typeof FRUITS[number] }[]) => void; | ||||
| 	dropped: () => void; | ||||
| 	fusioned: (x: number, y: number, score: number) => void; | ||||
| 	gameOver: () => void; | ||||
| }> { | ||||
| 	private COMBO_INTERVAL = 1000; | ||||
| 	public readonly DROP_INTERVAL = 500; | ||||
| 	private PLAYAREA_MARGIN = 25; | ||||
| 	private engine: Matter.Engine; | ||||
| 	private render: Matter.Render; | ||||
| 	private runner: Matter.Runner; | ||||
| 	private detector: Matter.Detector; | ||||
| 	private overflowCollider: Matter.Body; | ||||
| 	private isGameOver = false; | ||||
|  | ||||
| 	/** | ||||
| 	 * フィールドに出ていて、かつ合体の対象となるアイテム | ||||
| 	 */ | ||||
| 	private activeBodyIds: Matter.Body['id'][] = []; | ||||
|  | ||||
| 	private latestDroppedBodyId: Matter.Body['id'] | null = null; | ||||
|  | ||||
| 	private latestDroppedAt = 0; | ||||
| 	private latestFusionedAt = 0; | ||||
| 	private stock: { id: string; fruit: typeof FRUITS[number] }[] = []; | ||||
|  | ||||
| 	private _combo = 0; | ||||
| 	private get combo() { | ||||
| 		return this._combo; | ||||
| 	} | ||||
| 	private set combo(value: number) { | ||||
| 		this._combo = value; | ||||
| 		this.emit('changeCombo', value); | ||||
| 	} | ||||
|  | ||||
| 	private _score = 0; | ||||
| 	private get score() { | ||||
| 		return this._score; | ||||
| 	} | ||||
| 	private set score(value: number) { | ||||
| 		this._score = value; | ||||
| 		this.emit('changeScore', value); | ||||
| 	} | ||||
|  | ||||
| 	constructor() { | ||||
| 		super(); | ||||
|  | ||||
| 		this.engine = Matter.Engine.create({ | ||||
| 			constraintIterations: 2 * PHYSICS_QUALITY_FACTOR, | ||||
| 			positionIterations: 6 * PHYSICS_QUALITY_FACTOR, | ||||
| 			velocityIterations: 4 * PHYSICS_QUALITY_FACTOR, | ||||
| 			gravity: { | ||||
| 				x: 0, | ||||
| 				y: 1, | ||||
| 			}, | ||||
| 			timing: { | ||||
| 				timeScale: 2, | ||||
| 			}, | ||||
| 			enableSleeping: false, | ||||
| 		}); | ||||
|  | ||||
| 		this.render = Matter.Render.create({ | ||||
| 			engine: this.engine, | ||||
| 			canvas: canvasEl.value, | ||||
| 			options: { | ||||
| 				width: GAME_WIDTH, | ||||
| 				height: GAME_HEIGHT, | ||||
| 				background: 'transparent', // transparent to hide | ||||
| 				wireframeBackground: 'transparent', // transparent to hide | ||||
| 				wireframes: false, | ||||
| 				showSleeping: false, | ||||
| 				pixelRatio: window.devicePixelRatio, | ||||
| 			}, | ||||
| 		}); | ||||
|  | ||||
| 		Matter.Render.run(this.render); | ||||
|  | ||||
| 		this.runner = Matter.Runner.create(); | ||||
| 		Matter.Runner.run(this.runner, this.engine); | ||||
|  | ||||
| 		this.detector = Matter.Detector.create(); | ||||
|  | ||||
| 		this.engine.world.bodies = []; | ||||
|  | ||||
| 		//#region walls | ||||
| 		const WALL_OPTIONS: Matter.IChamferableBodyDefinition = { | ||||
| 			isStatic: true, | ||||
| 			render: { | ||||
| 				strokeStyle: 'transparent', | ||||
| 				fillStyle: 'transparent', | ||||
| 			}, | ||||
| 		}; | ||||
|  | ||||
| 		const thickness = 100; | ||||
| 		Matter.Composite.add(this.engine.world, [ | ||||
| 			Matter.Bodies.rectangle(GAME_WIDTH / 2, GAME_HEIGHT + (thickness / 2) - this.PLAYAREA_MARGIN, GAME_WIDTH, thickness, WALL_OPTIONS), | ||||
| 			Matter.Bodies.rectangle(GAME_WIDTH + (thickness / 2) - this.PLAYAREA_MARGIN, GAME_HEIGHT / 2, thickness, GAME_HEIGHT, WALL_OPTIONS), | ||||
| 			Matter.Bodies.rectangle(-((thickness / 2) - this.PLAYAREA_MARGIN), GAME_HEIGHT / 2, thickness, GAME_HEIGHT, WALL_OPTIONS), | ||||
| 		]); | ||||
| 		//#endregion | ||||
|  | ||||
| 		this.overflowCollider = Matter.Bodies.rectangle(GAME_WIDTH / 2, 0, GAME_WIDTH, 125, { | ||||
| 			isStatic: true, | ||||
| 			isSensor: true, | ||||
| 			render: { | ||||
| 				strokeStyle: 'transparent', | ||||
| 				fillStyle: 'transparent', | ||||
| 			}, | ||||
| 		}); | ||||
| 		Matter.Composite.add(this.engine.world, this.overflowCollider); | ||||
|  | ||||
| 		// fit the render viewport to the scene | ||||
| 		Matter.Render.lookAt(this.render, { | ||||
| 			min: { x: 0, y: 0 }, | ||||
| 			max: { x: GAME_WIDTH, y: GAME_HEIGHT }, | ||||
| 		}); | ||||
| 	} | ||||
|  | ||||
| 	private createBody(fruit: typeof FRUITS[number], x: number, y: number) { | ||||
| 		return Matter.Bodies.circle(x, y, fruit.size / 2, { | ||||
| 			label: fruit.id, | ||||
| 			density: 0.0005, | ||||
| 			frictionAir: 0.01, | ||||
| 			restitution: 0.4, | ||||
| 			friction: 0.5, | ||||
| 			frictionStatic: 5, | ||||
| 			//mass: 0, | ||||
| 			render: { | ||||
| 				sprite: { | ||||
| 					texture: fruit.img, | ||||
| 					xScale: (fruit.size / fruit.imgSize) * fruit.spriteScale, | ||||
| 					yScale: (fruit.size / fruit.imgSize) * fruit.spriteScale, | ||||
| 				}, | ||||
| 			}, | ||||
| 		}); | ||||
| 	} | ||||
|  | ||||
| 	private fusion(bodyA: Matter.Body, bodyB: Matter.Body) { | ||||
| 		const now = Date.now(); | ||||
| 		if (this.latestFusionedAt > now - this.COMBO_INTERVAL) { | ||||
| 			this.combo++; | ||||
| 		} else { | ||||
| 			this.combo = 1; | ||||
| 		} | ||||
| 		this.latestFusionedAt = now; | ||||
|  | ||||
| 		// TODO: 単に位置だけでなくそれぞれの動きベクトルも融合する | ||||
| 		const newX = (bodyA.position.x + bodyB.position.x) / 2; | ||||
| 		const newY = (bodyA.position.y + bodyB.position.y) / 2; | ||||
|  | ||||
| 		Matter.Composite.remove(this.engine.world, [bodyA, bodyB]); | ||||
| 		this.activeBodyIds = this.activeBodyIds.filter(x => x !== bodyA.id && x !== bodyB.id); | ||||
|  | ||||
| 		const currentFruit = FRUITS.find(y => y.id === bodyA.label)!; | ||||
| 		const nextFruit = FRUITS.find(x => x.level === currentFruit.level + 1); | ||||
|  | ||||
| 		if (nextFruit) { | ||||
| 			const body = this.createBody(nextFruit, newX, newY); | ||||
| 			Matter.Composite.add(this.engine.world, body); | ||||
|  | ||||
| 			// 連鎖してfusionした場合の分かりやすさのため少し間を置いてからfusion対象になるようにする | ||||
| 			window.setTimeout(() => { | ||||
| 				this.activeBodyIds.push(body.id); | ||||
| 			}, 100); | ||||
|  | ||||
| 			const additionalScore = Math.round(currentFruit.score * (1 + (this.combo / 3))); | ||||
| 			this.score += additionalScore; | ||||
|  | ||||
| 			const pan = ((newX / GAME_WIDTH) - 0.5) * 2; | ||||
| 			sound.playRaw('syuilo/bubble2', 1, pan, nextFruit.sfxPitch); | ||||
|  | ||||
| 			this.emit('fusioned', newX, newY, additionalScore); | ||||
| 		} else { | ||||
| 			//const VELOCITY = 30; | ||||
| 			//for (let i = 0; i < 10; i++) { | ||||
| 			//	const body = createBody(FRUITS.find(x => x.level === (1 + Math.floor(Math.random() * 3)))!, x + ((Math.random() * VELOCITY) - (VELOCITY / 2)), y + ((Math.random() * VELOCITY) - (VELOCITY / 2))); | ||||
| 			//	Matter.Composite.add(world, body); | ||||
| 			//	bodies.push(body); | ||||
| 			//} | ||||
| 			//sound.playRaw({ | ||||
| 			//	type: 'syuilo/bubble2', | ||||
| 			//	volume: 1, | ||||
| 			//}); | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	private gameOver() { | ||||
| 		this.isGameOver = true; | ||||
| 		Matter.Runner.stop(this.runner); | ||||
| 		this.emit('gameOver'); | ||||
| 	} | ||||
|  | ||||
| 	public start() { | ||||
| 		for (let i = 0; i < 4; i++) { | ||||
| 			this.stock.push({ | ||||
| 				id: Math.random().toString(), | ||||
| 				fruit: FRUITS.filter(x => x.available)[Math.floor(Math.random() * FRUITS.filter(x => x.available).length)], | ||||
| 			}); | ||||
| 		} | ||||
| 		this.emit('changeStock', this.stock); | ||||
|  | ||||
| 		// TODO: fusion予約状態のアイテムは光らせるなどの演出をすると楽しそう | ||||
| 		let fusionReservedPairs: { bodyA: Matter.Body; bodyB: Matter.Body }[] = []; | ||||
|  | ||||
| 		const minCollisionDepthForSound = 2.5; | ||||
| 		const maxCollisionDepthForSound = 9; | ||||
| 		const soundPitchMax = 4; | ||||
| 		const soundPitchMin = 0.5; | ||||
|  | ||||
| 		Matter.Events.on(this.engine, 'collisionStart', (event) => { | ||||
| 			for (const pairs of event.pairs) { | ||||
| 				const { bodyA, bodyB } = pairs; | ||||
| 				if (bodyA.id === this.overflowCollider.id || bodyB.id === this.overflowCollider.id) { | ||||
| 					if (bodyA.id === this.latestDroppedBodyId || bodyB.id === this.latestDroppedBodyId) { | ||||
| 						continue; | ||||
| 					} | ||||
| 					this.gameOver(); | ||||
| 					break; | ||||
| 				} | ||||
| 				const shouldFusion = (bodyA.label === bodyB.label) && !fusionReservedPairs.some(x => x.bodyA.id === bodyA.id || x.bodyA.id === bodyB.id || x.bodyB.id === bodyA.id || x.bodyB.id === bodyB.id); | ||||
| 				if (shouldFusion) { | ||||
| 					if (this.activeBodyIds.includes(bodyA.id) && this.activeBodyIds.includes(bodyB.id)) { | ||||
| 						this.fusion(bodyA, bodyB); | ||||
| 					} else { | ||||
| 						fusionReservedPairs.push({ bodyA, bodyB }); | ||||
| 						window.setTimeout(() => { | ||||
| 							fusionReservedPairs = fusionReservedPairs.filter(x => x.bodyA.id !== bodyA.id && x.bodyB.id !== bodyB.id); | ||||
| 							this.fusion(bodyA, bodyB); | ||||
| 						}, 100); | ||||
| 					} | ||||
| 				} else { | ||||
| 					const energy = pairs.collision.depth; | ||||
| 					if (energy > minCollisionDepthForSound) { | ||||
| 						const vol = (Math.min(maxCollisionDepthForSound, energy - minCollisionDepthForSound) / maxCollisionDepthForSound) / 4; | ||||
| 						const pan = ((((bodyA.position.x + bodyB.position.x) / 2) / GAME_WIDTH) - 0.5) * 2; | ||||
| 						const pitch = soundPitchMin + ((soundPitchMax - soundPitchMin) * (1 - (Math.min(10, energy) / 10))); | ||||
| 						sound.playRaw('syuilo/poi1', vol, pan, pitch); | ||||
| 					} | ||||
| 				} | ||||
| 			} | ||||
| 		}); | ||||
|  | ||||
| 		window.setInterval(() => { | ||||
| 			if (this.latestFusionedAt < Date.now() - this.COMBO_INTERVAL) { | ||||
| 				this.combo = 0; | ||||
| 			} | ||||
| 		}, 500); | ||||
| 	} | ||||
|  | ||||
| 	public drop(_x: number) { | ||||
| 		if (this.isGameOver) return; | ||||
| 		if (Date.now() - this.latestDroppedAt < this.DROP_INTERVAL) { | ||||
| 			return; | ||||
| 		} | ||||
| 		const st = this.stock.shift()!; | ||||
| 		this.stock.push({ | ||||
| 			id: Math.random().toString(), | ||||
| 			fruit: FRUITS.filter(x => x.available)[Math.floor(Math.random() * FRUITS.filter(x => x.available).length)], | ||||
| 		}); | ||||
| 		this.emit('changeStock', this.stock); | ||||
|  | ||||
| 		const x = Math.min(GAME_WIDTH - this.PLAYAREA_MARGIN - (st.fruit.size / 2), Math.max(this.PLAYAREA_MARGIN + (st.fruit.size / 2), _x)); | ||||
| 		const body = this.createBody(st.fruit, x, st.fruit.size / 2); | ||||
| 		Matter.Composite.add(this.engine.world, body); | ||||
| 		this.activeBodyIds.push(body.id); | ||||
| 		this.latestDroppedBodyId = body.id; | ||||
| 		this.latestDroppedAt = Date.now(); | ||||
| 		this.emit('dropped'); | ||||
| 		const pan = ((x / GAME_WIDTH) - 0.5) * 2; | ||||
| 		sound.playRaw('syuilo/poi2', 1, pan); | ||||
| 	} | ||||
|  | ||||
| 	public dispose() { | ||||
| 		Matter.Render.stop(this.render); | ||||
| 		Matter.Runner.stop(this.runner); | ||||
| 		Matter.World.clear(this.engine.world, false); | ||||
| 		Matter.Engine.clear(this.engine); | ||||
| 	} | ||||
| } | ||||
|  | ||||
| let game: Game; | ||||
|  | ||||
| function onClick(ev: MouseEvent) { | ||||
| 	const rect = containerEl.value.getBoundingClientRect(); | ||||
|  | ||||
| 	const x = (ev.clientX - rect.left) / viewScaleX; | ||||
|  | ||||
| 	game.drop(x); | ||||
| } | ||||
|  | ||||
| function onTouchend(ev: TouchEvent) { | ||||
| 	const rect = containerEl.value.getBoundingClientRect(); | ||||
|  | ||||
| 	const x = (ev.changedTouches[0].clientX - rect.left) / viewScaleX; | ||||
|  | ||||
| 	game.drop(x); | ||||
| } | ||||
|  | ||||
| function onMousemove(ev: MouseEvent) { | ||||
| 	mouseX.value = ev.clientX - containerEl.value.getBoundingClientRect().left; | ||||
| } | ||||
|  | ||||
| function onTouchmove(ev: TouchEvent) { | ||||
| 	mouseX.value = ev.touches[0].clientX - containerEl.value.getBoundingClientRect().left; | ||||
| } | ||||
|  | ||||
| function restart() { | ||||
| 	game.dispose(); | ||||
| 	gameOver.value = false; | ||||
| 	currentPick.value = null; | ||||
| 	dropReady.value = true; | ||||
| 	stock.value = []; | ||||
| 	score.value = 0; | ||||
| 	combo.value = 0; | ||||
| 	comboPrev.value = 0; | ||||
| 	game = new Game(); | ||||
| 	attachGame(); | ||||
| 	game.start(); | ||||
| } | ||||
|  | ||||
| function attachGame() { | ||||
| 	game.addListener('changeScore', value => { | ||||
| 		score.value = value; | ||||
| 	}); | ||||
|  | ||||
| 	game.addListener('changeCombo', value => { | ||||
| 		if (value === 0) { | ||||
| 			comboPrev.value = combo.value; | ||||
| 		} else { | ||||
| 			comboPrev.value = value; | ||||
| 		} | ||||
| 		combo.value = value; | ||||
| 	}); | ||||
|  | ||||
| 	game.addListener('changeStock', value => { | ||||
| 		currentPick.value = JSON.parse(JSON.stringify(value[0])); | ||||
| 		stock.value = JSON.parse(JSON.stringify(value.slice(1))); | ||||
| 	}); | ||||
|  | ||||
| 	game.addListener('dropped', () => { | ||||
| 		dropReady.value = false; | ||||
| 		window.setTimeout(() => { | ||||
| 			if (!gameOver.value) { | ||||
| 				dropReady.value = true; | ||||
| 			} | ||||
| 		}, game.DROP_INTERVAL); | ||||
| 	}); | ||||
|  | ||||
| 	game.addListener('fusioned', (x, y, score) => { | ||||
| 		const rect = canvasEl.value.getBoundingClientRect(); | ||||
| 		const domX = rect.left + (x * viewScaleX); | ||||
| 		const domY = rect.top + (y * viewScaleY); | ||||
| 		os.popup(MkRippleEffect, { x: domX, y: domY }, {}, 'end'); | ||||
| 		os.popup(MkPlusOneEffect, { x: domX, y: domY, value: score }, {}, 'end'); | ||||
| 	}); | ||||
|  | ||||
| 	game.addListener('gameOver', () => { | ||||
| 		currentPick.value = null; | ||||
| 		dropReady.value = false; | ||||
| 		gameOver.value = true; | ||||
| 	}); | ||||
| } | ||||
|  | ||||
| onMounted(() => { | ||||
| 	game = new Game(); | ||||
|  | ||||
| 	attachGame(); | ||||
|  | ||||
| 	game.start(); | ||||
|  | ||||
| 	const actualCanvasWidth = canvasEl.value.getBoundingClientRect().width; | ||||
| 	const actualCanvasHeight = canvasEl.value.getBoundingClientRect().height; | ||||
| 	viewScaleX = actualCanvasWidth / GAME_WIDTH; | ||||
| 	viewScaleY = actualCanvasHeight / GAME_HEIGHT; | ||||
| }); | ||||
|  | ||||
| definePageMetadata({ | ||||
| 	title: 'Drop & Fusion', | ||||
| 	icon: 'ti ti-apple', | ||||
| }); | ||||
| </script> | ||||
|  | ||||
| <style lang="scss" module> | ||||
| .transition_stock_move, | ||||
| .transition_stock_enterActive, | ||||
| .transition_stock_leaveActive { | ||||
| 	transition: opacity 0.4s cubic-bezier(0,.5,.5,1), transform 0.4s cubic-bezier(0,.5,.5,1) !important; | ||||
| } | ||||
| .transition_stock_enterFrom, | ||||
| .transition_stock_leaveTo { | ||||
| 	opacity: 0; | ||||
| 	transform: scale(0.7); | ||||
| } | ||||
| .transition_stock_leaveActive { | ||||
| 	position: absolute; | ||||
| } | ||||
|  | ||||
| .transition_picked_move, | ||||
| .transition_picked_enterActive { | ||||
| 	transition: opacity 0.5s cubic-bezier(0,.5,.5,1), transform 0.5s cubic-bezier(0,.5,.5,1) !important; | ||||
| } | ||||
| .transition_picked_leaveActive { | ||||
| 	transition: all 0s !important; | ||||
| } | ||||
| .transition_picked_enterFrom, | ||||
| .transition_picked_leaveTo { | ||||
| 	opacity: 0; | ||||
| 	transform: translateY(-50px); | ||||
| } | ||||
| .transition_picked_leaveActive { | ||||
| 	position: absolute; | ||||
| } | ||||
|  | ||||
| .transition_combo_move, | ||||
| .transition_combo_enterActive { | ||||
| 	transition: all 0s !important; | ||||
| } | ||||
| .transition_combo_leaveActive { | ||||
| 	transition: opacity 0.4s cubic-bezier(0,.5,.5,1), transform 0.4s cubic-bezier(0,.5,.5,1) !important; | ||||
| } | ||||
| .transition_combo_enterFrom, | ||||
| .transition_combo_leaveTo { | ||||
| 	opacity: 0; | ||||
| 	transform: scale(0.7); | ||||
| } | ||||
| .transition_combo_leaveActive { | ||||
| 	position: absolute; | ||||
| } | ||||
|  | ||||
| .root { | ||||
| 	user-select: none; | ||||
|  | ||||
| 	* { | ||||
| 		user-select: none; | ||||
| 	} | ||||
| } | ||||
|  | ||||
| .frame { | ||||
| 	padding: 7px; | ||||
| 	background: #8C4F26; | ||||
| 	box-shadow: 0 6px 16px #0007, 0 0 1px 1px #693410, inset 0 0 2px 1px #ce8a5c; | ||||
| 	border-radius: 10px; | ||||
| } | ||||
| .frameInner { | ||||
| 	padding: 4px 8px; | ||||
| 	background: #F1E8DC; | ||||
| 	box-shadow: 0 0 2px 1px #ce8a5c, inset 0 0 1px 1px #693410; | ||||
| 	border-radius: 6px; | ||||
| 	color: #693410; | ||||
| } | ||||
|  | ||||
| .main { | ||||
| 	position: relative; | ||||
| } | ||||
|  | ||||
| .mainFrameImg { | ||||
| 	position: absolute; | ||||
| 	top: 0; | ||||
| 	left: 0; | ||||
| 	width: 100%; | ||||
| 	filter: drop-shadow(0 6px 16px #0007); | ||||
| 	pointer-events: none; | ||||
| 	user-select: none; | ||||
| } | ||||
|  | ||||
| .canvas { | ||||
| 	position: relative; | ||||
| 	display: block; | ||||
| 	z-index: 1; | ||||
| 	margin-top: -50px; | ||||
| 	max-width: 100%; | ||||
| 	pointer-events: none; | ||||
| 	user-select: none; | ||||
| } | ||||
|  | ||||
| .container { | ||||
| 	position: relative; | ||||
| } | ||||
|  | ||||
| .stock { | ||||
| 	pointer-events: none; | ||||
| 	user-select: none; | ||||
| } | ||||
|  | ||||
| .combo { | ||||
| 	position: absolute; | ||||
| 	z-index: 3; | ||||
| 	top: 50%; | ||||
| 	width: 100%; | ||||
| 	text-align: center; | ||||
| 	font-weight: bold; | ||||
| 	font-style: oblique; | ||||
| 	pointer-events: none; | ||||
| 	user-select: none; | ||||
| } | ||||
|  | ||||
| .currentFruit { | ||||
| 	position: absolute; | ||||
| 	margin-top: 20px; | ||||
| 	z-index: 2; | ||||
| 	filter: drop-shadow(0 6px 16px #0007); | ||||
| 	pointer-events: none; | ||||
| 	user-select: none; | ||||
| } | ||||
|  | ||||
| .currentFruitArrow { | ||||
| 	position: absolute; | ||||
| 	margin-top: 20px; | ||||
| 	z-index: 3; | ||||
| 	animation: currentFruitArrow 2s ease infinite; | ||||
| 	pointer-events: none; | ||||
| 	user-select: none; | ||||
| } | ||||
|  | ||||
| .dropGuide { | ||||
| 	position: absolute; | ||||
| 	top: 50px; | ||||
| 	z-index: 3; | ||||
| 	width: 3px; | ||||
| 	height: calc(100% - 50px); | ||||
| 	background: #f002; | ||||
| 	pointer-events: none; | ||||
| 	user-select: none; | ||||
| } | ||||
|  | ||||
| .gameOverLabel { | ||||
| 	position: absolute; | ||||
| 	z-index: 10; | ||||
| 	top: 50%; | ||||
| 	width: 100%; | ||||
| 	padding: 16px; | ||||
| 	box-sizing: border-box; | ||||
| 	background: #0007; | ||||
| 	color: #fff; | ||||
| 	text-align: center; | ||||
| 	font-weight: bold; | ||||
| } | ||||
|  | ||||
| .gameOver { | ||||
| 	.canvas { | ||||
| 		filter: grayscale(1); | ||||
| 	} | ||||
| } | ||||
|  | ||||
| @keyframes currentFruitArrow { | ||||
| 	0% { transform: translateY(0); } | ||||
| 	25% { transform: translateY(-8px); } | ||||
| 	50% { transform: translateY(0); } | ||||
| 	75% { transform: translateY(-8px); } | ||||
| 	100% { transform: translateY(0); } | ||||
| } | ||||
| </style> | ||||
| @@ -527,6 +527,10 @@ export const routes = [{ | ||||
| 	path: '/clicker', | ||||
| 	component: page(() => import('./pages/clicker.vue')), | ||||
| 	loginRequired: true, | ||||
| }, { | ||||
| 	path: '/drop-and-fusion', | ||||
| 	component: page(() => import('./pages/drop-and-fusion.vue')), | ||||
| 	loginRequired: true, | ||||
| }, { | ||||
| 	path: '/timeline', | ||||
| 	component: page(() => import('./pages/timeline.vue')), | ||||
|   | ||||
| @@ -92,7 +92,13 @@ export type OperationType = typeof operationTypes[number]; | ||||
|  * @param soundStore サウンド設定 | ||||
|  * @param options `useCache`: デフォルトは`true` 一度再生した音声はキャッシュする | ||||
|  */ | ||||
| export async function loadAudio(soundStore: SoundStore, options?: { useCache?: boolean; }) { | ||||
| export async function loadAudio(soundStore: { | ||||
| 	type: Exclude<SoundType, '_driveFile_'>; | ||||
| } | { | ||||
| 	type: '_driveFile_'; | ||||
| 	fileId: string; | ||||
| 	fileUrl: string; | ||||
| }, options?: { useCache?: boolean; }) { | ||||
| 	if (_DEV_) console.log('loading audio. opts:', options); | ||||
| 	// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition | ||||
| 	if (soundStore.type === null || (soundStore.type === '_driveFile_' && !soundStore.fileUrl)) { | ||||
| @@ -179,18 +185,31 @@ export async function playFile(soundStore: SoundStore) { | ||||
| 	createSourceNode(buffer, soundStore.volume)?.start(); | ||||
| } | ||||
|  | ||||
| export function createSourceNode(buffer: AudioBuffer, volume: number) : AudioBufferSourceNode | null { | ||||
| export async function playRaw(type: Exclude<SoundType, '_driveFile_'>, volume = 1, pan = 0, playbackRate = 1) { | ||||
| 	const buffer = await loadAudio({ type }); | ||||
| 	if (!buffer) return; | ||||
| 	createSourceNode(buffer, volume, pan, playbackRate)?.start(); | ||||
| } | ||||
|  | ||||
| export function createSourceNode(buffer: AudioBuffer, volume: number, pan = 0, playbackRate = 1) : AudioBufferSourceNode | null { | ||||
| 	const masterVolume = defaultStore.state.sound_masterVolume; | ||||
| 	if (isMute() || masterVolume === 0 || volume === 0) { | ||||
| 		return null; | ||||
| 	} | ||||
|  | ||||
| 	const panNode = ctx.createStereoPanner(); | ||||
| 	panNode.pan.value = pan; | ||||
|  | ||||
| 	const gainNode = ctx.createGain(); | ||||
| 	gainNode.gain.value = masterVolume * volume; | ||||
|  | ||||
| 	const soundSource = ctx.createBufferSource(); | ||||
| 	soundSource.buffer = buffer; | ||||
| 	soundSource.connect(gainNode).connect(ctx.destination); | ||||
| 	soundSource.playbackRate.value = playbackRate; | ||||
| 	soundSource | ||||
| 		.connect(panNode) | ||||
| 		.connect(gainNode) | ||||
| 		.connect(ctx.destination); | ||||
|  | ||||
| 	return soundSource; | ||||
| } | ||||
|   | ||||
| @@ -27,6 +27,11 @@ function toolsMenuItems(): MenuItem[] { | ||||
| 		to: '/clicker', | ||||
| 		text: '🍪👈', | ||||
| 		icon: 'ti ti-cookie', | ||||
| 	}, { | ||||
| 		type: 'link', | ||||
| 		to: '/drop-and-fusion', | ||||
| 		text: 'Drop & Fusion', | ||||
| 		icon: 'ti ti-apple', | ||||
| 	}, ($i && ($i.isAdmin || $i.policies.canManageCustomEmojis)) ? { | ||||
| 		type: 'link', | ||||
| 		to: '/custom-emojis-manager', | ||||
|   | ||||
| @@ -1,6 +1,6 @@ | ||||
| /* | ||||
|  * version: 2023.12.2 | ||||
|  * generatedAt: 2024-01-02T08:53:57.449Z | ||||
|  * generatedAt: 2024-01-04T18:10:15.096Z | ||||
|  */ | ||||
|  | ||||
| import type { SwitchCaseResponseType } from '../api.js'; | ||||
|   | ||||
| @@ -1,6 +1,6 @@ | ||||
| /* | ||||
|  * version: 2023.12.2 | ||||
|  * generatedAt: 2024-01-02T08:53:57.445Z | ||||
|  * generatedAt: 2024-01-04T18:10:15.094Z | ||||
|  */ | ||||
|  | ||||
| import type { | ||||
|   | ||||
| @@ -1,6 +1,6 @@ | ||||
| /* | ||||
|  * version: 2023.12.2 | ||||
|  * generatedAt: 2024-01-02T08:53:57.443Z | ||||
|  * generatedAt: 2024-01-04T18:10:15.093Z | ||||
|  */ | ||||
|  | ||||
| import { operations } from './types.js'; | ||||
|   | ||||
| @@ -1,6 +1,6 @@ | ||||
| /* | ||||
|  * version: 2023.12.2 | ||||
|  * generatedAt: 2024-01-02T08:53:57.441Z | ||||
|  * generatedAt: 2024-01-04T18:10:15.091Z | ||||
|  */ | ||||
|  | ||||
| import { components } from './types.js'; | ||||
|   | ||||
| @@ -3,7 +3,7 @@ | ||||
|  | ||||
| /* | ||||
|  * version: 2023.12.2 | ||||
|  * generatedAt: 2024-01-02T08:53:56.447Z | ||||
|  * generatedAt: 2024-01-04T18:10:15.023Z | ||||
|  */ | ||||
|  | ||||
| /** | ||||
| @@ -4400,6 +4400,9 @@ export type operations = { | ||||
|             emailRequiredForSignup: boolean; | ||||
|             enableHcaptcha: boolean; | ||||
|             hcaptchaSiteKey: string | null; | ||||
|             enableMcaptcha: boolean; | ||||
|             mcaptchaSiteKey: string | null; | ||||
|             mcaptchaInstanceUrl: string | null; | ||||
|             enableRecaptcha: boolean; | ||||
|             recaptchaSiteKey: string | null; | ||||
|             enableTurnstile: boolean; | ||||
| @@ -4425,6 +4428,7 @@ export type operations = { | ||||
|             bannedEmailDomains?: string[]; | ||||
|             preservedUsernames: string[]; | ||||
|             hcaptchaSecretKey: string | null; | ||||
|             mcaptchaSecretKey: string | null; | ||||
|             recaptchaSecretKey: string | null; | ||||
|             turnstileSecretKey: string | null; | ||||
|             sensitiveMediaDetection: string; | ||||
| @@ -8197,6 +8201,10 @@ export type operations = { | ||||
|           enableHcaptcha?: boolean; | ||||
|           hcaptchaSiteKey?: string | null; | ||||
|           hcaptchaSecretKey?: string | null; | ||||
|           enableMcaptcha?: boolean; | ||||
|           mcaptchaSiteKey?: string | null; | ||||
|           mcaptchaInstanceUrl?: string | null; | ||||
|           mcaptchaSecretKey?: string | null; | ||||
|           enableRecaptcha?: boolean; | ||||
|           recaptchaSiteKey?: string | null; | ||||
|           recaptchaSecretKey?: string | null; | ||||
| @@ -18704,6 +18712,9 @@ export type operations = { | ||||
|             emailRequiredForSignup: boolean; | ||||
|             enableHcaptcha: boolean; | ||||
|             hcaptchaSiteKey: string | null; | ||||
|             enableMcaptcha: boolean; | ||||
|             mcaptchaSiteKey: string | null; | ||||
|             mcaptchaInstanceUrl: string | null; | ||||
|             enableRecaptcha: boolean; | ||||
|             recaptchaSiteKey: string | null; | ||||
|             enableTurnstile: boolean; | ||||
|   | ||||
 かっこかり
					かっこかり