From a86fffb577c3c4b571b5dcb7fa36f1d4b4d9fa4c Mon Sep 17 00:00:00 2001 From: iseau395 <70857830+iseau395@users.noreply.github.com> Date: Thu, 14 Dec 2023 18:30:13 -0800 Subject: [PATCH] Fix all the warnings --- src/lib/context_menu/ContextMenu.svelte | 2 +- src/lib/context_menu/ContextMenuButton.svelte | 2 +- src/lib/map/field.ts | 14 +++++----- src/lib/map/games/over-under/over-under.ts | 2 +- src/lib/map/games/spin-up/roller.ts | 6 ++--- src/lib/map/games/spin-up/spin-up.ts | 2 +- src/lib/map/objects/object.ts | 10 ++++--- src/lib/map/paths/PathItem.svelte | 26 +++++++++---------- src/lib/map/paths/PathSidebar.svelte | 3 +-- src/lib/map/saving.ts | 9 ++++--- src/lib/save_screens/NewSaveScreen.svelte | 2 +- src/lib/save_screens/SaveFile.svelte | 8 +++--- src/main.ts | 2 +- test/map/spin-up/disc.test.ts | 6 ++--- 14 files changed, 49 insertions(+), 45 deletions(-) diff --git a/src/lib/context_menu/ContextMenu.svelte b/src/lib/context_menu/ContextMenu.svelte index 5946c83..4d022cb 100644 --- a/src/lib/context_menu/ContextMenu.svelte +++ b/src/lib/context_menu/ContextMenu.svelte @@ -27,7 +27,7 @@
{#each options as option} - button_pressed("on_select" in option ? option.on_select : null) : undefined}/> + button_pressed("on_select" in option ? option.on_select : () => {}) : undefined}/> {/each}
diff --git a/src/lib/context_menu/ContextMenuButton.svelte b/src/lib/context_menu/ContextMenuButton.svelte index 661b310..c7f200c 100644 --- a/src/lib/context_menu/ContextMenuButton.svelte +++ b/src/lib/context_menu/ContextMenuButton.svelte @@ -6,7 +6,7 @@ export let og_y: number; export let name: string; - export let options: ContextMenuOption[]; + export let options: ContextMenuOption[] | null; let submenu_visible = false; function onmouseenter() { diff --git a/src/lib/map/field.ts b/src/lib/map/field.ts index a592d2e..9fc0389 100644 --- a/src/lib/map/field.ts +++ b/src/lib/map/field.ts @@ -89,8 +89,8 @@ export function update_field(input: Input) { last_mouse_y = input.mouse_y; } -let game_type_value = undefined; -let is_skills_value = undefined; +let game_type_value: GameType | undefined = undefined; +let is_skills_value: boolean | undefined = undefined; game_type.subscribe(v => game_type_value = v); is_skills.subscribe(v => is_skills_value = v); @@ -101,10 +101,10 @@ export let game: Promise = new Promise(async (resolve) => { switch (game_type_value) { case GameType.OverUnder: { - value = new (await import("./games/over-under/over-under")).OverUnder(is_skills_value); + value = new (await import("./games/over-under/over-under")).OverUnder(is_skills_value!); } break; case GameType.SpinUp: { - value = new (await import("./games/spin-up/spin-up")).SpinUp(is_skills_value); + value = new (await import("./games/spin-up/spin-up")).SpinUp(is_skills_value!); } break; } @@ -222,10 +222,10 @@ export async function reset_field() { switch (game_type_value) { case GameType.OverUnder: { - value = new (await import("./games/over-under/over-under")).OverUnder(is_skills_value); + value = new (await import("./games/over-under/over-under")).OverUnder(is_skills_value!); } break; case GameType.SpinUp: { - value = new (await import("./games/spin-up/spin-up")).SpinUp(is_skills_value); + value = new (await import("./games/spin-up/spin-up")).SpinUp(is_skills_value!); } break; } @@ -233,7 +233,7 @@ export async function reset_field() { save_state(); - bg_cache.getContext("2d").scale(1/cache_scale, 1/cache_scale); + bg_cache.getContext("2d")!.scale(1/cache_scale, 1/cache_scale); game_loaded = true; init_load = false; redraw_background = true; diff --git a/src/lib/map/games/over-under/over-under.ts b/src/lib/map/games/over-under/over-under.ts index b3723bd..f026d7c 100644 --- a/src/lib/map/games/over-under/over-under.ts +++ b/src/lib/map/games/over-under/over-under.ts @@ -6,7 +6,7 @@ import { save_state, saveable, saveable_off } from "../../saving"; @saveable("overunder") export class OverUnder implements Game { - objects: Triball[]; + objects: Triball[] = []; constructor(is_skills: boolean) { register_insert_option({ diff --git a/src/lib/map/games/spin-up/roller.ts b/src/lib/map/games/spin-up/roller.ts index fd0d550..bb06cbf 100644 --- a/src/lib/map/games/spin-up/roller.ts +++ b/src/lib/map/games/spin-up/roller.ts @@ -25,16 +25,16 @@ export class Roller { this.rotated = rotated; if (!this.rotated) - add_box_collision(this, 0, 0, 9.8 * inch_pixel_ratio, 2.4 * inch_pixel_ratio); + add_box_collision(this as any, 0, 0, 9.8 * inch_pixel_ratio, 2.4 * inch_pixel_ratio); else - add_box_collision(this, 0, 0, 2.4 * inch_pixel_ratio, 9.8 * inch_pixel_ratio); + add_box_collision(this as any, 0, 0, 2.4 * inch_pixel_ratio, 9.8 * inch_pixel_ratio); this.state = state; } @on("update") public update(input: Input) { - const mouse_over = in_collision(this, input.gridless_mouse_x, input.gridless_mouse_y); + const mouse_over = in_collision(this as any, input.gridless_mouse_x, input.gridless_mouse_y); if (input.mouse_button == 0 && mouse_over && input.mouse_button_changed && selection == -1) { this.state++; diff --git a/src/lib/map/games/spin-up/spin-up.ts b/src/lib/map/games/spin-up/spin-up.ts index d577f11..ac031d0 100644 --- a/src/lib/map/games/spin-up/spin-up.ts +++ b/src/lib/map/games/spin-up/spin-up.ts @@ -8,7 +8,7 @@ import { remove_callbacks } from "../../objects/object"; @saveable("spinup") export class SpinUp implements Game { - objects: (Disc | Roller)[]; + objects: (Disc | Roller)[] = []; constructor(is_skills: boolean) { register_insert_option({ diff --git a/src/lib/map/objects/object.ts b/src/lib/map/objects/object.ts index 2e39060..9c64104 100644 --- a/src/lib/map/objects/object.ts +++ b/src/lib/map/objects/object.ts @@ -27,6 +27,8 @@ export function reset_objects() { objects.clear(); for (const event in callbacks) { + // eslint-disable-next-line @typescript-eslint/ban-ts-comment + // @ts-ignore callbacks[event].clear(); } } @@ -37,8 +39,8 @@ export function object(Base: T) { super(...args); this[id_symbol] = current_id++; - this[callback_symbol] = this[callback_symbol] ?? Base.prototype[callback_symbol] ?? Base.prototype.prototype[callback_symbol]; - this[collision_symbol] = this[collision_symbol] ?? Base.prototype[collision_symbol] ?? Base.prototype.prototype[collision_symbol]; + (this as any)[callback_symbol] = (this as any)[callback_symbol] ?? Base.prototype[callback_symbol] ?? Base.prototype.prototype[callback_symbol]; + (this as any)[collision_symbol] = (this as any)[collision_symbol] ?? Base.prototype[collision_symbol] ?? Base.prototype.prototype[collision_symbol]; objects.set(this[id_symbol], this); @@ -117,7 +119,7 @@ export function in_collision(object: T) { if (collision_symbol in object) - object[collision_symbol].length = 0; + object[collision_symbol]!.length = 0; } export let selection = -1; @@ -199,7 +201,7 @@ export function remove_callbacks(target: { [callback_symbol]?: Map { - off(event, target[id_symbol]); + off(event, target[id_symbol]!); }); } diff --git a/src/lib/map/paths/PathItem.svelte b/src/lib/map/paths/PathItem.svelte index 9cd3fbf..92b8e77 100644 --- a/src/lib/map/paths/PathItem.svelte +++ b/src/lib/map/paths/PathItem.svelte @@ -22,7 +22,7 @@ if ("points" in segment) { let unsub: () => void; onMount(() => { - const ctx = canvas.getContext("2d"); + const ctx = canvas.getContext("2d")!; unsub = segment.subscribe(() => { if (!("points" in segment)) return; @@ -98,7 +98,7 @@ } } - function isBefore(el1, el2) { + function isBefore(el1: HTMLElement, el2: HTMLElement) { let cur; if (el2.parentNode === el1.parentNode) { for (cur = el1.previousSibling; cur; cur = cur.previousSibling) { @@ -109,8 +109,8 @@ } function dragStart(ev: DragEvent) { - ev.dataTransfer.effectAllowed = "move"; - ev.dataTransfer.setData("text/plain", null); + ev.dataTransfer!.effectAllowed = "move"; + ev.dataTransfer!.setData("text/plain", ""); $selected = ev.target as HTMLLIElement; (ev.target as HTMLLIElement).style.opacity = "0"; } @@ -122,25 +122,25 @@ $selected.style.boxShadow = "-5px -5px 0 #00AA00"; $selected.style.marginLeft = "5px"; - if (isBefore($selected, ev.target)) { - (ev.target as HTMLLIElement).parentNode.insertBefore($selected, ev.target as HTMLLIElement); + if (isBefore($selected, ev.target! as HTMLElement)) { + (ev.target as HTMLLIElement).parentNode!.insertBefore($selected, ev.target as HTMLLIElement); } else { - (ev.target as HTMLLIElement).parentNode.insertBefore($selected, (ev.target as HTMLLIElement).nextSibling); + (ev.target as HTMLLIElement).parentNode!.insertBefore($selected, (ev.target as HTMLLIElement).nextSibling); } ev.preventDefault(); } function dragEnd(ev: DragEvent) { - $selected.style.boxShadow = "none"; - $selected.style.marginLeft = "0"; + $selected!.style.boxShadow = "none"; + $selected!.style.marginLeft = "0"; - if (isBefore($selected, ev.target)) { - (ev.target as HTMLLIElement).parentNode.insertBefore($selected, ev.target as HTMLLIElement); + if (isBefore($selected!, ev.target! as HTMLElement)) { + (ev.target as HTMLLIElement).parentNode!.insertBefore($selected!, ev.target as HTMLLIElement); } else { - (ev.target as HTMLLIElement).parentNode.insertBefore($selected, (ev.target as HTMLLIElement).nextSibling); + (ev.target as HTMLLIElement).parentNode!.insertBefore($selected!, (ev.target as HTMLLIElement).nextSibling); } - const nodes = Array.prototype.slice.call( (ev.target as HTMLLIElement).parentElement.children ); + const nodes = Array.prototype.slice.call( (ev.target as HTMLLIElement).parentElement!.children ); path.move_segment(index, nodes.indexOf(ev.target)); index = nodes.indexOf(ev.target); diff --git a/src/lib/map/paths/PathSidebar.svelte b/src/lib/map/paths/PathSidebar.svelte index ff55281..f5c793e 100644 --- a/src/lib/map/paths/PathSidebar.svelte +++ b/src/lib/map/paths/PathSidebar.svelte @@ -33,9 +33,8 @@ {/if}
  • -