summaryrefslogtreecommitdiff
path: root/packages/misskey-bubble-game
diff options
context:
space:
mode:
authordakkar <dakkar@thenautilus.net>2024-10-09 15:17:22 +0100
committerdakkar <dakkar@thenautilus.net>2024-10-09 15:17:22 +0100
commitf00576bce6b5f4086112f48046316bfe49559759 (patch)
tree9268031a42551f3bfafbb33091f925e0cb5af3aa /packages/misskey-bubble-game
parentMerge branch 'merge-requests/668' into feature/2024.9.0 (diff)
parentMerge pull request #14580 from misskey-dev/develop (diff)
downloadsharkey-f00576bce6b5f4086112f48046316bfe49559759.tar.gz
sharkey-f00576bce6b5f4086112f48046316bfe49559759.tar.bz2
sharkey-f00576bce6b5f4086112f48046316bfe49559759.zip
Merge remote-tracking branch 'misskey/master' into feature/2024.9.0
Diffstat (limited to 'packages/misskey-bubble-game')
-rw-r--r--packages/misskey-bubble-game/build.js32
-rw-r--r--packages/misskey-bubble-game/eslint.config.js1
-rw-r--r--packages/misskey-bubble-game/src/game.ts30
3 files changed, 37 insertions, 26 deletions
diff --git a/packages/misskey-bubble-game/build.js b/packages/misskey-bubble-game/build.js
index e626c97a59..a80b71646f 100644
--- a/packages/misskey-bubble-game/build.js
+++ b/packages/misskey-bubble-game/build.js
@@ -1,32 +1,32 @@
-import * as esbuild from "esbuild";
-import { build } from "esbuild";
-import { globSync } from "glob";
-import { execa } from "execa";
-import fs from "node:fs";
-import { fileURLToPath } from "node:url";
-import { dirname } from "node:path";
+import fs from 'node:fs';
+import { fileURLToPath } from 'node:url';
+import { dirname } from 'node:path';
+import * as esbuild from 'esbuild';
+import { build } from 'esbuild';
+import { globSync } from 'glob';
+import { execa } from 'execa';
const _filename = fileURLToPath(import.meta.url);
const _dirname = dirname(_filename);
const _package = JSON.parse(fs.readFileSync(_dirname + '/package.json', 'utf-8'));
-const entryPoints = globSync("./src/**/**.{ts,tsx}");
+const entryPoints = globSync('./src/**/**.{ts,tsx}');
/** @type {import('esbuild').BuildOptions} */
const options = {
entryPoints,
minify: process.env.NODE_ENV === 'production',
- outdir: "./built",
- target: "es2022",
- platform: "browser",
- format: "esm",
+ outdir: './built',
+ target: 'es2022',
+ platform: 'browser',
+ format: 'esm',
sourcemap: 'linked',
};
// built配下をすべて削除する
fs.rmSync('./built', { recursive: true, force: true });
-if (process.argv.map(arg => arg.toLowerCase()).includes("--watch")) {
+if (process.argv.map(arg => arg.toLowerCase()).includes('--watch')) {
await watchSrc();
} else {
await buildSrc();
@@ -36,7 +36,7 @@ async function buildSrc() {
console.log(`[${_package.name}] start building...`);
await build(options)
- .then(it => {
+ .then(() => {
console.log(`[${_package.name}] build succeeded.`);
})
.catch((err) => {
@@ -65,7 +65,7 @@ function buildDts() {
{
stdout: process.stdout,
stderr: process.stderr,
- }
+ },
);
}
@@ -86,7 +86,7 @@ async function watchSrc() {
},
}];
- console.log(`[${_package.name}] start watching...`)
+ console.log(`[${_package.name}] start watching...`);
const context = await esbuild.context({ ...options, plugins });
await context.watch();
diff --git a/packages/misskey-bubble-game/eslint.config.js b/packages/misskey-bubble-game/eslint.config.js
index 86c21a22a3..bce383b1a6 100644
--- a/packages/misskey-bubble-game/eslint.config.js
+++ b/packages/misskey-bubble-game/eslint.config.js
@@ -1,6 +1,7 @@
import tsParser from '@typescript-eslint/parser';
import sharedConfig from '../shared/eslint.config.js';
+// eslint-disable-next-line import/no-default-export
export default [
...sharedConfig,
{
diff --git a/packages/misskey-bubble-game/src/game.ts b/packages/misskey-bubble-game/src/game.ts
index 3bce4b1dcf..7f230e39cb 100644
--- a/packages/misskey-bubble-game/src/game.ts
+++ b/packages/misskey-bubble-game/src/game.ts
@@ -199,13 +199,12 @@ export class DropAndFusionGame extends EventEmitter<{
};
if (mono.shape === 'circle') {
return Matter.Bodies.circle(x, y, mono.sizeX / 2, options);
- // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
} else if (mono.shape === 'rectangle') {
return Matter.Bodies.rectangle(x, y, mono.sizeX, mono.sizeY, options);
- } else if (mono.shape === 'custom') {
- return Matter.Bodies.fromVertices(x, y, mono.vertices!.map(i => i.map(j => ({
- x: (j.x / mono.verticesSize!) * mono.sizeX,
- y: (j.y / mono.verticesSize!) * mono.sizeY,
+ } else if (mono.shape === 'custom' && mono.vertices != null && mono.verticesSize != null) { //eslint-disable-line @typescript-eslint/no-unnecessary-condition
+ return Matter.Bodies.fromVertices(x, y, mono.vertices.map(i => i.map(j => ({
+ x: (j.x / mono.verticesSize!) * mono.sizeX, //eslint-disable-line @typescript-eslint/no-non-null-assertion
+ y: (j.y / mono.verticesSize!) * mono.sizeY, //eslint-disable-line @typescript-eslint/no-non-null-assertion
}))), options);
} else {
throw new Error('unrecognized shape');
@@ -227,7 +226,12 @@ export class DropAndFusionGame extends EventEmitter<{
this.gameOverReadyBodyIds = this.gameOverReadyBodyIds.filter(x => x !== bodyA.id && x !== bodyB.id);
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);
+
+ if (currentMono == null) {
+ throw new Error('Current Mono Not Found');
+ }
+
const nextMono = this.monoDefinitions.find(x => x.level === currentMono.level + 1) ?? null;
if (nextMono) {
@@ -362,14 +366,18 @@ export class DropAndFusionGame extends EventEmitter<{
}
public getActiveMonos() {
- return this.engine.world.bodies.map(x => this.monoDefinitions.find((mono) => mono.id === x.label)!).filter(x => x !== undefined);
+ return this.engine.world.bodies
+ .map(x => this.monoDefinitions.find((mono) => mono.id === x.label))
+ .filter(x => x !== undefined);
}
public drop(_x: number) {
if (this.isGameOver) return;
if (this.frame - this.latestDroppedAt < this.DROP_COOLTIME) return;
- const head = this.stock.shift()!;
+ const head = this.stock.shift();
+ if (!head) return;
+
this.stock.push({
id: this.rng().toString(),
mono: this.monoDefinitions.filter(x => x.dropCandidate)[Math.floor(this.rng() * this.monoDefinitions.filter(x => x.dropCandidate).length)],
@@ -411,13 +419,15 @@ export class DropAndFusionGame extends EventEmitter<{
});
if (this.holding) {
- const head = this.stock.shift()!;
+ const head = this.stock.shift();
+ if (!head) return;
this.stock.unshift(this.holding);
this.holding = head;
this.emit('changeHolding', this.holding);
this.emit('changeStock', this.stock);
} else {
- const head = this.stock.shift()!;
+ const head = this.stock.shift();
+ if (!head) return;
this.holding = head;
this.stock.push({
id: this.rng().toString(),