Skip to content

Commit

Permalink
Fix all the warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
iseau395 committed Dec 15, 2023
1 parent 46a187d commit a86fffb
Show file tree
Hide file tree
Showing 14 changed files with 49 additions and 45 deletions.
2 changes: 1 addition & 1 deletion src/lib/context_menu/ContextMenu.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
<span style="left: {x}px; top:{y}px;" on:contextmenu|preventDefault>
<div on:mouseenter on:mouseleave>
{#each options as option}
<ContextMenuButton name={option.name} options={"options" in option ? option.options : null} og_x={x ?? og_x} og_y={y ?? og_y} on:click={"on_select" in option ? () => button_pressed("on_select" in option ? option.on_select : null) : undefined}/>
<ContextMenuButton name={option.name} options={"options" in option ? option.options : null} og_x={x ?? og_x} og_y={y ?? og_y} on:click={"on_select" in option ? () => button_pressed("on_select" in option ? option.on_select : () => {}) : undefined}/>
{/each}
</div>
</span>
Expand Down
2 changes: 1 addition & 1 deletion src/lib/context_menu/ContextMenuButton.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
14 changes: 7 additions & 7 deletions src/lib/map/field.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -101,10 +101,10 @@ export let game: Promise<Game> = new Promise<Game>(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;
}

Expand Down Expand Up @@ -222,18 +222,18 @@ 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;
}

if (!value) return reject();

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;
Expand Down
2 changes: 1 addition & 1 deletion src/lib/map/games/over-under/over-under.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down
6 changes: 3 additions & 3 deletions src/lib/map/games/spin-up/roller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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++;
Expand Down
2 changes: 1 addition & 1 deletion src/lib/map/games/spin-up/spin-up.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down
10 changes: 6 additions & 4 deletions src/lib/map/objects/object.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
Expand All @@ -37,8 +39,8 @@ export function object<T extends { new(...args: any[]): MapObject }>(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);

Expand Down Expand Up @@ -117,7 +119,7 @@ export function in_collision<T extends { [collision_symbol]: Collision[] } & Map

export function clear_collision<T extends { [collision_symbol]?: Collision[] } & MapObject>(object: T) {
if (collision_symbol in object)
object[collision_symbol].length = 0;
object[collision_symbol]!.length = 0;
}

export let selection = -1;
Expand Down Expand Up @@ -199,7 +201,7 @@ export function remove_callbacks(target: { [callback_symbol]?: Map<keyof Events,
if (!target[callback_symbol] || !target[id_symbol]) return;

target[callback_symbol].forEach((_, event) => {
off(event, target[id_symbol]);
off(event, target[id_symbol]!);
});
}

Expand Down
26 changes: 13 additions & 13 deletions src/lib/map/paths/PathItem.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand All @@ -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";
}
Expand All @@ -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);
Expand Down
3 changes: 1 addition & 2 deletions src/lib/map/paths/PathSidebar.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,8 @@
{/if}

<li>

<button on:click={() => $insert_dropdown_open = ! $insert_dropdown_open}>
<svg viewbox="0 0 50 50">
<svg viewBox="0 0 50 50">
<line x1="5" y1="25" x2="45" y2="25" stroke="#555555" stroke-width="5" stroke-linecap="round" />
<line x1="25" y1="5" x2="25" y2="45" stroke="#555555" stroke-width="5" stroke-linecap="round" />
</svg>
Expand Down
9 changes: 6 additions & 3 deletions src/lib/map/saving.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { writable } from "svelte/store";
import { game_type } from "../../stores/settings";
import { reset_objects } from "./objects/object";
import type { GameType } from "./games/game";

const SAVE_VERSION = 0;

Expand Down Expand Up @@ -37,11 +38,11 @@ export function saveable_off<T extends Saveable>(object: T) {
}
}

let game_type_value = undefined;
let game_type_value: GameType | undefined = undefined;
game_type.subscribe(v => game_type_value = v);

export function get_save_state() {
let data = `${SAVE_VERSION},${game_type_value}`;
let data = `${SAVE_VERSION},${game_type_value!}`;

save_callbacks.forEach((callback, save_id) => {
data += `|${save_id}:${callback()}`;
Expand All @@ -53,9 +54,11 @@ export function get_save_state() {
}

export function load_save_state(raw_data: string) {
if (!raw_data) return;

const data = raw_data.split("|");

const metadata = data.shift().split(",");
const metadata = data.shift()!.split(",");

game_type.set(+metadata[1]);

Expand Down
2 changes: 1 addition & 1 deletion src/lib/save_screens/NewSaveScreen.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
if (!selected_game_type || !save_name.trim()) return;
$new_save_screen_open = false;
$game_type = string_to_game_type(selected_game_type);
$game_type = string_to_game_type(selected_game_type)!;
$is_skills = skills;
$current_save_id = save_name.trim();
Expand Down
8 changes: 4 additions & 4 deletions src/lib/save_screens/SaveFile.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
export let update_saves_list: () => void;
const raw_save_data = localStorage.getItem(`file-${id}`);
const save_data = raw_save_data.split("|");
const save_data = raw_save_data!.split("|");
const metadata = save_data.shift().split(",");
const metadata = save_data.shift()!.split(",");
const save_game_type: GameType = +metadata[1];
Expand All @@ -28,7 +28,7 @@
await reset_field();
await game;
load_save_state(raw_save_data);
load_save_state(raw_save_data!);
reset_undo();
$load_save_screen_open = false;
Expand All @@ -39,7 +39,7 @@
localStorage.removeItem(`file-${id}`);
const save_list = localStorage.getItem("save-list").split("|");
const save_list = localStorage.getItem("save-list")!.split("|");
save_list.splice(save_list.indexOf(id), 1);
Expand Down
2 changes: 1 addition & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import "./app.css";
import App from "./App.svelte";

const app = new App({
target: document.getElementById("app"),
target: document.getElementById("app")!,
});

export default app;
6 changes: 3 additions & 3 deletions test/map/spin-up/disc.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ describe("Disc", () => {
mouse_button: -1,
mouse_button_changed: false,
wheel: 1,
keys: new Map<string, boolean | undefined>(),
keys: new Map<string, boolean | null>(),
});

update_objects({
Expand All @@ -41,7 +41,7 @@ describe("Disc", () => {
mouse_button: 0,
mouse_button_changed: true,
wheel: 1,
keys: new Map<string, boolean | undefined>(),
keys: new Map<string, boolean | null>(),
});

expect(disc.x / inch_pixel_ratio).toBe(x1);
Expand All @@ -55,7 +55,7 @@ describe("Disc", () => {
mouse_button: 0,
mouse_button_changed: false,
wheel: 1,
keys: new Map<string, boolean | undefined>(),
keys: new Map<string, boolean | null>(),
});

expect(disc.x / inch_pixel_ratio).toBe(x2);
Expand Down

0 comments on commit a86fffb

Please sign in to comment.