From c61002a12899abe265b8bd6c24e1b26557d65e4f Mon Sep 17 00:00:00 2001 From: lajbel Date: Tue, 17 Dec 2024 19:45:29 -0300 Subject: [PATCH] chore: format all files and fix test --- CODE_OF_CONDUCT.md | 63 +++++++++++++++-------------- README.md | 5 ++- examples/animation.js | 12 ++++-- examples/component.js | 4 +- examples/fastLoop.js | 38 ++++++++++------- examples/livequery.js | 8 ++-- examples/particletrail.js | 8 ++-- examples/tiled.js | 4 +- scripts/test.js | 10 +++-- src/assets/shader.ts | 5 ++- src/components/draw/particles.ts | 10 +++-- src/components/misc/textInput.ts | 3 +- src/components/misc/timer.ts | 40 +++++++++++++----- src/components/physics/area.ts | 9 +++-- src/components/physics/effectors.ts | 4 +- src/game/events/events.ts | 32 +++++++++------ src/game/gravity.ts | 8 +++- src/game/initEvents.ts | 13 +++--- src/gfx/draw/drawDebug.ts | 18 +++++++-- src/gfx/draw/drawTexture.ts | 6 ++- src/math/math.ts | 30 +++++++------- src/utils/events.ts | 9 ++++- tests/playtests/test536.js | 4 +- tests/playtests/tsconfig.json | 2 +- tsconfig.dts.json | 2 +- tsconfig.json | 2 +- 26 files changed, 213 insertions(+), 136 deletions(-) diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md index e8ac3f43..de8e238a 100644 --- a/CODE_OF_CONDUCT.md +++ b/CODE_OF_CONDUCT.md @@ -1,40 +1,41 @@ ![KAPLAY](/kaplay.webp) + # KAPLAY Code of Conduct -Based on the [![Contributor Covenant](https://img.shields.io/badge/Contributor%20Covenant-2.0-4baaaa.svg)](https://www.contributor-covenant.org/version/2/0/code_of_conduct.html) +Based on the +[![Contributor Covenant](https://img.shields.io/badge/Contributor%20Covenant-2.0-4baaaa.svg)](https://www.contributor-covenant.org/version/2/0/code_of_conduct.html) ## Our Pledge We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone. -We pledge to act and interact in ways that contribute to an open, -welcoming, and healthy community. +We pledge to act and interact in ways that contribute to an open, welcoming, and +healthy community. ## Our Standards Examples of behavior that contributes to a positive environment for our community include: -* Demonstrating empathy and kindness toward other people -* Being respectful of differing opinions, viewpoints, and experiences -* Giving and gracefully accepting constructive feedback -* Accepting responsibility and apologizing to those affected by our mistakes, +- Demonstrating empathy and kindness toward other people +- Being respectful of differing opinions, viewpoints, and experiences +- Giving and gracefully accepting constructive feedback +- Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience -* Focusing on what is best not just for us as individuals, but for the - overall community +- Focusing on what is best not just for us as individuals, but for the overall + community Examples of unacceptable behavior include: -* The use of sexualized language or imagery, and sexual attention or - advances of any kind -* Trolling, insulting or derogatory comments, and personal or political attacks -* Public or private harassment -* Publishing others' private information, such as a physical or email - address, without their explicit permission, accidents such as - using personal email in a co-author is allowed, but try to avoid - that from happening -* Other conduct which could reasonably be considered inappropriate in a +- The use of sexualized language or imagery, and sexual attention or advances of + any kind +- Trolling, insulting or derogatory comments, and personal or political attacks +- Public or private harassment +- Publishing others' private information, such as a physical or email address, + without their explicit permission, accidents such as using personal email in a + co-author is allowed, but try to avoid that from happening +- Other conduct which could reasonably be considered inappropriate in a professional setting ## Enforcement Responsibilities @@ -53,16 +54,17 @@ decisions when appropriate. This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. -Examples of representing our community include using an official e-mail address that ends with @kaplayjs.com, -posting via an official social media account, talking in discord, or acting as an appointed -representative at an online or offline event. +Examples of representing our community include using an official e-mail address +that ends with @kaplayjs.com, posting via an official social media account, +talking in discord, or acting as an appointed representative at an online or +offline event. ## Enforcement Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at -support@kaplayjs.com, or #support in the Discord, -All complaints will be reviewed and investigated promptly and fairly. +support@kaplayjs.com, or #support in the Discord, All complaints will be +reviewed and investigated promptly and fairly. All community leaders are obligated to respect the privacy and security of the reporter of any incident. @@ -83,8 +85,8 @@ behavior was inappropriate. A public apology may be requested. ### 2. Warning -**Community Impact**: A violation through a single incident or series -of actions. +**Community Impact**: A violation through a single incident or series of +actions. **Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with @@ -110,11 +112,11 @@ Violating these terms may lead to a permanent ban. standards, including sustained inappropriate behavior, harassment of an individual, spamming messages on any of our platforms, or scamming other users. -**Consequence**: A permanent ban from any sort of public interaction within -the community. +**Consequence**: A permanent ban from any sort of public interaction within the +community. -**Important**: We dont give this punishment regularly, -this is only used in extreme circumstances. +**Important**: We dont give this punishment regularly, this is only used in +extreme circumstances. ## Attribution @@ -122,7 +124,8 @@ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0, available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html. -Community Impact Guidelines were inspired by [Mozilla's code of conduct +Community Impact Guidelines were inspired by +[Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity). [homepage]: https://www.contributor-covenant.org diff --git a/README.md b/README.md index eb6a47cd..9844cb73 100644 --- a/README.md +++ b/README.md @@ -184,12 +184,15 @@ Collections of games made with KAPLAY (and Kaboom), selected by KAPLAY: - [Newgrounds.com](https://www.newgrounds.com/playlist/379920/kaplay-games) ## Credits + - Thanks to [tga](https://space55.xyz) for all his work on the original Kaboom.js - Thanks to [mulfok](https://twitter.com/MulfoK) for the awesome [mulfok32](https://lospec.com/palette-list/mulfok32) color palette, used in KAPLAY sprites and art -- Thanks to [Pixabay](https://pixabay.com/users/pixabay-1/) for the great [burp](https://pixabay.com/sound-effects/burp-104984/) sound, used in `burp()` function +- Thanks to [Pixabay](https://pixabay.com/users/pixabay-1/) for the great + [burp](https://pixabay.com/sound-effects/burp-104984/) sound, used in `burp()` + function - Thansk to [Kenney](https://kenney.nl/) for all used assets for examples - [Impact Sound Pack](https://kenney.nl/assets/impact-sounds) - [1-Bit Platformer Pack](https://kenney.nl/assets/1-bit-platformer-pack) diff --git a/examples/animation.js b/examples/animation.js index 4cd4ef0d..6a22a74c 100644 --- a/examples/animation.js +++ b/examples/animation.js @@ -26,10 +26,14 @@ rotatingBean.animate("angle", [0, 360], { onClick(() => { rotatingBean.animation.seek(0); -}) +}); -rotatingBean.onAnimateChannelFinished(name => { debug.log(`${name} finished`) }) -rotatingBean.onAnimateFinished(() => { debug.log(`All finished`) }) +rotatingBean.onAnimateChannelFinished(name => { + debug.log(`${name} finished`); +}); +rotatingBean.onAnimateFinished(() => { + debug.log(`All finished`); +}); // Now we'll move this bean from left to right const movingBean = add([ @@ -48,7 +52,7 @@ movingBean.animate("pos", [vec2(50, 150), vec2(150, 150)], { onClick(() => { movingBean.animation.paused = !movingBean.animation.paused; -}) +}); // Same animation as before, but relative to the spawn position const secondMovingBean = add([ diff --git a/examples/component.js b/examples/component.js index 2c20277b..ba57d9d6 100644 --- a/examples/component.js +++ b/examples/component.js @@ -116,8 +116,8 @@ add([ bean.onUse(id => { debug.log(`Component ${id} added`); -}) +}); bean.onUnuse(id => { debug.log(`Component ${id} removed`); -}) \ No newline at end of file +}); diff --git a/examples/fastLoop.js b/examples/fastLoop.js index b61a13d5..515b452c 100644 --- a/examples/fastLoop.js +++ b/examples/fastLoop.js @@ -7,15 +7,20 @@ loadBean(); const interval = 0.001; const delay = 1; -loop(interval, () => { - const bean = add([ - sprite("bean"), - pos(rand(vec2(0), vec2(width(), height()))), - ]); - wait(delay, () => { - destroy(bean); - }); -}, -1, true); +loop( + interval, + () => { + const bean = add([ + sprite("bean"), + pos(rand(vec2(0), vec2(width(), height()))), + ]); + wait(delay, () => { + destroy(bean); + }); + }, + -1, + true, +); const counter = add([ pos(10, 10), @@ -31,14 +36,17 @@ add([ update() { this.width = counter.width; this.height = counter.height; - } - } -]) + }, + }, +]); var beanCount = 0; onAdd(() => beanCount++); onDestroy(() => beanCount--); loop(0.1, () => { - const error = 100 * Math.abs((delay / interval) - beanCount) / (delay / interval); - counter.text = `${beanCount.toFixed().padStart(5)} beans\nerror: ${error.toFixed(2).padStart(5)}%`; -}); \ No newline at end of file + const error = 100 * Math.abs((delay / interval) - beanCount) + / (delay / interval); + counter.text = `${beanCount.toFixed().padStart(5)} beans\nerror: ${ + error.toFixed(2).padStart(5) + }%`; +}); diff --git a/examples/livequery.js b/examples/livequery.js index 7fedd74d..3759f263 100644 --- a/examples/livequery.js +++ b/examples/livequery.js @@ -15,7 +15,7 @@ loop(5, () => { area(), timer(), color(WHITE), - "touchable" + "touchable", ]); ghost.wait(5, () => { ghost.unuse("area"); @@ -25,8 +25,8 @@ loop(5, () => { ghost.use(area()); ghost.tag("touchable"); ghost.use(color(WHITE)); - }) - }) + }); + }); } }); @@ -36,4 +36,4 @@ onClick("touchable", (ghost) => { loop(1, () => { debug.log(`There are ${q.length} touchable ghosts`); -}); \ No newline at end of file +}); diff --git a/examples/particletrail.js b/examples/particletrail.js index f176cd1f..5bc25b24 100644 --- a/examples/particletrail.js +++ b/examples/particletrail.js @@ -20,11 +20,11 @@ onLoad(() => { rate: 5, direction: -90, spread: 2, - }) - ]) + }), + ]); onMouseMove((pos, delta) => { trail.emitter.position = pos; trail.emit(1); - }) -}) \ No newline at end of file + }); +}); diff --git a/examples/tiled.js b/examples/tiled.js index aad33e8e..2abe179b 100644 --- a/examples/tiled.js +++ b/examples/tiled.js @@ -16,7 +16,7 @@ add([ add([ circle(4), - pos(150, 150) -]) + pos(150, 150), +]); // debug.inspect = true diff --git a/scripts/test.js b/scripts/test.js index d533de5a..69da89bb 100644 --- a/scripts/test.js +++ b/scripts/test.js @@ -8,9 +8,9 @@ import { build } from "./lib/build.js"; import { wait } from "./lib/util.js"; const exampleCI = JSON.parse( - (await fs.readFile( - new URL("../examples/ciTest.json", import.meta.url), - )).toString(), + ( + await fs.readFile(new URL("../examples/ciTest.json", import.meta.url)) + ).toString(), ); await build(); @@ -19,7 +19,9 @@ const server = serve({ port: port }); let failed = false; console.log("launching browser"); -const browser = await puppeteer.launch(); +const browser = await puppeteer.launch({ + args: ["--no-sandbox"], +}); console.log("getting examples list"); let examples; diff --git a/src/assets/shader.ts b/src/assets/shader.ts index 786b48ec..718d28bf 100644 --- a/src/assets/shader.ts +++ b/src/assets/shader.ts @@ -200,7 +200,10 @@ export function loadShader( vert?: string, frag?: string, ) { - return _k.assets.shaders.addLoaded(name, makeShader(_k.gfx.ggl, vert, frag)); + return _k.assets.shaders.addLoaded( + name, + makeShader(_k.gfx.ggl, vert, frag), + ); } export function loadShaderURL( diff --git a/src/components/draw/particles.ts b/src/components/draw/particles.ts index 8234d559..68ee729d 100644 --- a/src/components/draw/particles.ts +++ b/src/components/draw/particles.ts @@ -138,7 +138,7 @@ export interface ParticlesComp extends Comp { * Relative direction of the emitter */ direction: number; - } + }; /** * Emit a number of particles */ @@ -237,9 +237,11 @@ export function particles(popt: ParticlesOpt, eopt: EmitterOpt): ParticlesComp { dampingRange[1], ); const lt = lifetime ? rand(lifetime[0], lifetime[1]) : null; - const pos = this.emitter.position.add(eopt.shape - ? eopt.shape.random() - : vec2()); + const pos = this.emitter.position.add( + eopt.shape + ? eopt.shape.random() + : vec2(), + ); const p = particles[index]; p.t = 0; diff --git a/src/components/misc/textInput.ts b/src/components/misc/textInput.ts index 02aca2b3..a620dcb9 100644 --- a/src/components/misc/textInput.ts +++ b/src/components/misc/textInput.ts @@ -39,7 +39,8 @@ export function textInput( charEv = _k.k.onCharInput((character) => { if ( this.hasFocus - && (!maxInputLength || this.typedText.length < maxInputLength) + && (!maxInputLength + || this.typedText.length < maxInputLength) ) { if (_k.k.isKeyDown("shift")) { this.typedText += character.toUpperCase(); diff --git a/src/components/misc/timer.ts b/src/components/misc/timer.ts index b3dcdf99..0c3ee043 100644 --- a/src/components/misc/timer.ts +++ b/src/components/misc/timer.ts @@ -20,7 +20,7 @@ export interface TimerComp extends Comp { * The maximum number of loops per frame allowed, * to keep loops with sub-frame intervals from freezing the game. */ - maxLoopsPerFrame: number + maxLoopsPerFrame: number; /** * Run the callback after n seconds. */ @@ -33,7 +33,12 @@ export interface TimerComp extends Comp { * * @since v3000.0 */ - loop(time: number, action: () => void, maxLoops?: number, waitFirst?: boolean): TimerController; + loop( + time: number, + action: () => void, + maxLoops?: number, + waitFirst?: boolean, + ): TimerController; /** * Tweeeeen! Note that this doesn't specifically mean tweening on this object's property, this just registers the timer on this object, so the tween will cancel with the object gets destroyed, or paused when obj.paused is true. * @@ -52,9 +57,15 @@ export function timer(maxLoopsPerFrame: number = 1000): TimerComp { return { id: "timer", maxLoopsPerFrame, - loop(this: GameObj, time: number, action: () => void, count: number = -1, waitFirst: boolean = false): TimerController { + loop( + this: GameObj, + time: number, + action: () => void, + count: number = -1, + waitFirst: boolean = false, + ): TimerController { let t: number = waitFirst ? 0 : time; - let onEndEvents = new KEvent; + let onEndEvents = new KEvent(); const ev = this.onUpdate(() => { t += _k.app.state.dt; for (let i = 0; t >= time && i < this.maxLoopsPerFrame; i++) { @@ -69,21 +80,28 @@ export function timer(maxLoopsPerFrame: number = 1000): TimerComp { action(); t -= time; } - }) + }); return { get paused() { - return ev.paused + return ev.paused; }, set paused(p) { - ev.paused = p + ev.paused = p; }, cancel: ev.cancel, onEnd: onEndEvents.add, - then(f) { onEndEvents.add(f); return this; } - } + then(f) { + onEndEvents.add(f); + return this; + }, + }; }, - wait(this: GameObj, time: number, action?: () => void): TimerController { - return this.loop(time, action ?? (() => { }), 1, true); + wait( + this: GameObj, + time: number, + action?: () => void, + ): TimerController { + return this.loop(time, action ?? (() => {}), 1, true); }, tween( this: GameObj, diff --git a/src/components/physics/area.ts b/src/components/physics/area.ts index d1d10236..a81052eb 100644 --- a/src/components/physics/area.ts +++ b/src/components/physics/area.ts @@ -265,7 +265,9 @@ export function area(opt: AreaCompOpt = {}): AreaComp { add(this: GameObj) { areaCount++; if (this.area.cursor) { - events.push(this.onHover(() => _k.app.setCursor(this.area.cursor!))); + events.push( + this.onHover(() => _k.app.setCursor(this.area.cursor!)), + ); } events.push(this.onCollideUpdate((obj, col) => { @@ -591,8 +593,9 @@ export function area(opt: AreaCompOpt = {}): AreaComp { return `area: ${this.area.scale?.x?.toFixed(1)}x`; } else { - return `area: (${this.area.scale?.x?.toFixed(1)}x, ${this.area.scale.y?.toFixed(1) - }y)`; + return `area: (${this.area.scale?.x?.toFixed(1)}x, ${ + this.area.scale.y?.toFixed(1) + }y)`; } }, }; diff --git a/src/components/physics/effectors.ts b/src/components/physics/effectors.ts index 30b5c671..36f097ab 100644 --- a/src/components/physics/effectors.ts +++ b/src/components/physics/effectors.ts @@ -107,8 +107,8 @@ export function pointEffector(opts: PointEffectorCompOpt): PointEffectorComp { const forceScale = this.forceMode === "constant" ? 1 : this.forceMode === "inverseLinear" - ? 1 / distance - : 1 / distance ** 2; + ? 1 / distance + : 1 / distance ** 2; const force = dir.scale( this.forceMagnitude * forceScale / length, ); diff --git a/src/game/events/events.ts b/src/game/events/events.ts index 19a00adb..ac2127ed 100644 --- a/src/game/events/events.ts +++ b/src/game/events/events.ts @@ -15,13 +15,13 @@ export function on( tag: Tag, cb: (obj: GameObj, ...args: TupleWithoutFirst) => void, ): KEventController { - if (!_k.game.objEvents.registers[event]) { - _k.game.objEvents.registers[event] = + if (!_k.game.objEvents.registers[ event]) { + _k.game.objEvents.registers[ event] = new Registry() as any; } return _k.game.objEvents.on( - event, + event, (obj, ...args) => { if (obj.is(tag)) { cb(obj, ...args as TupleWithoutFirst); @@ -96,11 +96,14 @@ export const onUse = overload2((action: (obj: GameObj, id: string) => void) => { return on("use", tag, action); }); -export const onUnuse = overload2((action: (obj: GameObj, id: string) => void) => { - return _k.game.events.on("unuse", action); -}, (tag: Tag, action: (obj: GameObj) => void) => { - return on("unuse", tag, action); -}); +export const onUnuse = overload2( + (action: (obj: GameObj, id: string) => void) => { + return _k.game.events.on("unuse", action); + }, + (tag: Tag, action: (obj: GameObj) => void) => { + return on("unuse", tag, action); + }, +); export const onTag = overload2((action: (obj: GameObj, id: string) => void) => { return _k.game.events.on("tag", action); @@ -108,11 +111,14 @@ export const onTag = overload2((action: (obj: GameObj, id: string) => void) => { return on("tag", tag, action); }); -export const onUntag = overload2((action: (obj: GameObj, id: string) => void) => { - return _k.game.events.on("untag", action); -}, (tag: Tag, action: (obj: GameObj) => void) => { - return on("untag", tag, action); -}); +export const onUntag = overload2( + (action: (obj: GameObj, id: string) => void) => { + return _k.game.events.on("untag", action); + }, + (tag: Tag, action: (obj: GameObj) => void) => { + return on("untag", tag, action); + }, +); // add an event that runs with objs with t1 collides with objs with t2 export function onCollide( diff --git a/src/game/gravity.ts b/src/game/gravity.ts index 54fd0c4a..00fee26a 100644 --- a/src/game/gravity.ts +++ b/src/game/gravity.ts @@ -4,7 +4,9 @@ import { type Vec2, vec2 } from "../math"; export function setGravity(g: number) { // If g > 0 use either the current direction or use (0, 1) // Else null - _k.game.gravity = g ? (_k.game.gravity || vec2(0, 1)).unit().scale(g) : null; + _k.game.gravity = g + ? (_k.game.gravity || vec2(0, 1)).unit().scale(g) + : null; } export function getGravity() { @@ -15,7 +17,9 @@ export function getGravity() { export function setGravityDirection(d: Vec2) { // If gravity > 0 keep magnitude, otherwise use 1 - _k.game.gravity = d.unit().scale(_k.game.gravity ? _k.game.gravity.len() : 1); + _k.game.gravity = d.unit().scale( + _k.game.gravity ? _k.game.gravity.len() : 1, + ); } export function getGravityDirection() { diff --git a/src/game/initEvents.ts b/src/game/initEvents.ts index b3fb1325..a356bb8e 100644 --- a/src/game/initEvents.ts +++ b/src/game/initEvents.ts @@ -1,7 +1,6 @@ import { burp } from "../audio"; import { FrameBuffer, updateViewport } from "../gfx"; -import {_k -} from "../kaplay"; +import { _k } from "../kaplay"; import { clamp } from "../math/math"; import { toFixed } from "../utils"; @@ -21,7 +20,9 @@ export function initEvents() { _k.app.onResize(() => { if (_k.app.isFullscreen()) return; const fixedSize = _k.globalOpt.width && _k.globalOpt.height; - if (fixedSize && !_k.globalOpt.stretch && !_k.globalOpt.letterbox) return; + if (fixedSize && !_k.globalOpt.stretch && !_k.globalOpt.letterbox) { + return; + } _k.canvas.width = _k.canvas.offsetWidth * _k.pixelDensity; _k.canvas.height = _k.canvas.offsetHeight * _k.pixelDensity; @@ -35,8 +36,10 @@ export function initEvents() { _k.gfx.ggl.gl.drawingBufferWidth, _k.gfx.ggl.gl.drawingBufferHeight, ); - _k.gfx.width = _k.gfx.ggl.gl.drawingBufferWidth / _k.pixelDensity / _k.gscale; - _k.gfx.height = _k.gfx.ggl.gl.drawingBufferHeight / _k.pixelDensity / _k.gscale; + _k.gfx.width = _k.gfx.ggl.gl.drawingBufferWidth / _k.pixelDensity + / _k.gscale; + _k.gfx.height = _k.gfx.ggl.gl.drawingBufferHeight / _k.pixelDensity + / _k.gscale; } }); diff --git a/src/gfx/draw/drawDebug.ts b/src/gfx/draw/drawDebug.ts index f20111a2..1a9113bf 100644 --- a/src/gfx/draw/drawDebug.ts +++ b/src/gfx/draw/drawDebug.ts @@ -184,7 +184,8 @@ export function drawDebug() { _k.game.logs = _k.game.logs .filter((log) => - _k.app.time() - log.time < (_k.globalOpt.logTime || LOG_TIME) + _k.app.time() - log.time + < (_k.globalOpt.logTime || LOG_TIME) ); const ftext = formatText({ @@ -219,7 +220,11 @@ export function drawDebug() { } } -function prettyDebug(object: any | undefined, inside: boolean = false, seen: Set = new Set): string { +function prettyDebug( + object: any | undefined, + inside: boolean = false, + seen: Set = new Set(), +): string { if (seen.has(object)) return ""; var outStr = "", tmp; if (inside && typeof object === "string") { @@ -228,7 +233,8 @@ function prettyDebug(object: any | undefined, inside: boolean = false, seen: Set if (Array.isArray(object)) { outStr = [ "[", - object.map(e => prettyDebug(e, true, seen.union(new Set([object])))).join(", "), + object.map(e => prettyDebug(e, true, seen.union(new Set([object])))) + .join(", "), "]", ].join(""); object = outStr; @@ -246,7 +252,11 @@ function prettyDebug(object: any | undefined, inside: boolean = false, seen: Set (tmp = Object.getOwnPropertyNames(object) .map(p => `${/^\w+$/.test(p) ? p : JSON.stringify(p)}: ${ - prettyDebug(object[p], true, seen.union(new Set([object]))) + prettyDebug( + object[p], + true, + seen.union(new Set([object])), + ) }` ) .join(", ")) diff --git a/src/gfx/draw/drawTexture.ts b/src/gfx/draw/drawTexture.ts index dd3205a5..a24bcb81 100644 --- a/src/gfx/draw/drawTexture.ts +++ b/src/gfx/draw/drawTexture.ts @@ -18,8 +18,10 @@ export function drawTexture(opt: DrawTextureOpt) { if (opt.tiled) { const offset = anchorPt(opt.anchor || DEF_ANCHOR); - const offsetX = (opt.pos?.x || 0) - (offset.x + 1) * 0.5 * (opt.width || w); - const offsetY = (opt.pos?.y || 0) - (offset.y + 1) * 0.5 * (opt.height || h); + const offsetX = (opt.pos?.x || 0) + - (offset.x + 1) * 0.5 * (opt.width || w); + const offsetY = (opt.pos?.y || 0) + - (offset.y + 1) * 0.5 * (opt.height || h); const fcols = (opt.width || w) / w; const frows = (opt.height || h) / h; diff --git a/src/math/math.ts b/src/math/math.ts index e9964a37..c6a07dcf 100644 --- a/src/math/math.ts +++ b/src/math/math.ts @@ -125,8 +125,8 @@ export class Vec2 { return Math.abs(this.x) > Math.abs(this.y) ? this.x < 0 ? Vec2.LEFT : Vec2.RIGHT : this.y < 0 - ? Vec2.UP - : Vec2.DOWN; + ? Vec2.UP + : Vec2.DOWN; } /** Clone the vector */ @@ -1385,7 +1385,7 @@ export class Mat4 { const r = Math.sqrt(this.m[0] * this.m[0] + this.m[1] * this.m[1]); return new Vec2( Math.atan(this.m[0] * this.m[4] + this.m[1] * this.m[5]) - / (r * r), + / (r * r), 0, ); } @@ -1394,7 +1394,7 @@ export class Mat4 { return new Vec2( 0, Math.atan(this.m[0] * this.m[4] + this.m[1] * this.m[5]) - / (s * s), + / (s * s), ); } else { @@ -1933,7 +1933,7 @@ export function testPolygonPoint(poly: Polygon, pt: Vec2): boolean { ((p[i].y > pt.y) != (p[j].y > pt.y)) && (pt.x < (p[j].x - p[i].x) * (pt.y - p[i].y) / (p[j].y - p[i].y) - + p[i].x) + + p[i].x) ) { c = !c; } @@ -1951,7 +1951,7 @@ export function testEllipsePoint(ellipse: Ellipse, pt: Vec2): boolean { const vx = pt.x * c + pt.y * s; const vy = -pt.x * s + pt.y * c; return vx * vx / (ellipse.radiusX * ellipse.radiusX) - + vy * vy / (ellipse.radiusY * ellipse.radiusY) < 1; + + vy * vy / (ellipse.radiusY * ellipse.radiusY) < 1; } export function testEllipseCircle(ellipse: Ellipse, circle: Circle): boolean { @@ -2888,7 +2888,7 @@ export class Ellipse { const vx = point.x * c + point.y * s; const vy = -point.x * s + point.y * c; return vx * vx / (this.radiusX * this.radiusX) - + vy * vy / (this.radiusY * this.radiusY) < 1; + + vy * vy / (this.radiusY * this.radiusY) < 1; } raycast(origin: Vec2, direction: Vec2): RaycastResult { return raycastEllipse(origin, direction, this); @@ -3287,21 +3287,21 @@ export function kochanekBartels( const hx = h( pt2.x, 0.5 * (1 - tension) * (1 + bias) * (1 + continuity) * (pt2.x - pt1.x) - + 0.5 * (1 - tension) * (1 - bias) * (1 - continuity) - * (pt3.x - pt2.x), + + 0.5 * (1 - tension) * (1 - bias) * (1 - continuity) + * (pt3.x - pt2.x), 0.5 * (1 - tension) * (1 + bias) * (1 - continuity) * (pt3.x - pt2.x) - + 0.5 * (1 - tension) * (1 - bias) * (1 + continuity) - * (pt4.x - pt3.x), + + 0.5 * (1 - tension) * (1 - bias) * (1 + continuity) + * (pt4.x - pt3.x), pt3.x, ); const hy = h( pt2.y, 0.5 * (1 - tension) * (1 + bias) * (1 + continuity) * (pt2.y - pt1.y) - + 0.5 * (1 - tension) * (1 - bias) * (1 - continuity) - * (pt3.y - pt2.y), + + 0.5 * (1 - tension) * (1 - bias) * (1 - continuity) + * (pt3.y - pt2.y), 0.5 * (1 - tension) * (1 + bias) * (1 - continuity) * (pt3.y - pt2.y) - + 0.5 * (1 - tension) * (1 - bias) * (1 + continuity) - * (pt4.y - pt3.y), + + 0.5 * (1 - tension) * (1 - bias) * (1 + continuity) + * (pt4.y - pt3.y), pt3.y, ); return (t: number) => { diff --git a/src/utils/events.ts b/src/utils/events.ts index 5c44b8c7..93088795 100644 --- a/src/utils/events.ts +++ b/src/utils/events.ts @@ -66,7 +66,8 @@ export class KEventController { } export class KEvent { - private cancellers: WeakMap<(...args: Args) => unknown, () => void> = new WeakMap(); + private cancellers: WeakMap<(...args: Args) => unknown, () => void> = + new WeakMap(); private handlers: Registry<(...args: Args) => unknown> = new Registry(); add(action: (...args: Args) => unknown): KEventController { @@ -97,8 +98,12 @@ export class KEvent { const result = action(...args); let cancel; - if (result === EVENT_CANCEL_SYMBOL && (cancel = this.cancellers.get(action))) + if ( + result === EVENT_CANCEL_SYMBOL + && (cancel = this.cancellers.get(action)) + ) { cancel(); + } }); } numListeners(): number { diff --git a/tests/playtests/test536.js b/tests/playtests/test536.js index b7e088ff..27ea6f08 100644 --- a/tests/playtests/test536.js +++ b/tests/playtests/test536.js @@ -11,8 +11,8 @@ const bean = add([ { update() { this.angle += 400 * dt(); - } - } + }, + }, ]); camPos(0, 0); diff --git a/tests/playtests/tsconfig.json b/tests/playtests/tsconfig.json index a70a602c..3ce20bbb 100644 --- a/tests/playtests/tsconfig.json +++ b/tests/playtests/tsconfig.json @@ -14,4 +14,4 @@ "moduleDetection": "force", "noImplicitAny": false } -} \ No newline at end of file +} diff --git a/tsconfig.dts.json b/tsconfig.dts.json index ae6558e7..8ae3cf93 100644 --- a/tsconfig.dts.json +++ b/tsconfig.dts.json @@ -15,4 +15,4 @@ "include": [ "src/**/*" ] -} \ No newline at end of file +} diff --git a/tsconfig.json b/tsconfig.json index 692955f7..2b3427a3 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -20,4 +20,4 @@ "scripts/**/*", "tests/auto/color.spec.ts" ] -} \ No newline at end of file +}