Skip to content

Fix typings #27

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: apjs2
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions .gitmodules

This file was deleted.

1 change: 0 additions & 1 deletion extern/apjs
Submodule apjs deleted from 60a248
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"license": "MIT",
"devDependencies": {
"@types/node": "^20.4.9",
"@types/ungap__structured-clone": "^1.2.0",
"esbuild": "^0.18.15",
"nax-ccuilib": "naxane/nax-ccuilib",
"nax-module-cache": "github:naxane/nax-module-cache",
Expand Down
2 changes: 1 addition & 1 deletion src/item-data.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ export interface WorldData {
quests: RawQuests;
shops: RawShops;
descriptions: { [itemId: number]: { [locale: string]: string } };
markers: { [area: string]: MarkerInfo[] }
markers: { [area: string]: MarkerInfo<any>[] }
}

export type RawItems = { [mapName: string]: RawMapItems };
Expand Down
3 changes: 1 addition & 2 deletions src/package-utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// import * as fs from "node:fs";
const fs = require("fs");
const fs: typeof import('fs') = (0, eval)('require("fs")');
import * as ap from "archipelago.js";

const CACHE_DIR = ".apcache";
Expand Down
42 changes: 16 additions & 26 deletions src/patches/chest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,18 @@ import {RawChest} from "../item-data.model";

declare global {
namespace ig.ENTITY {
interface Chest extends ig.Entity.Settings {
interface Chest {
mwCheck?: RawChest;
analyzeColor: sc.ANALYSIS_COLORS;
analyzeLabel: string;
collectedLabel: string;
rawChest: ap.Item | undefined;
}

interface ChestConstructor extends ImpactClass<Chest> {
new(...args: any[]): Chest;
}

var Chest: ChestConstructor;
}
namespace sc {
namespace QUICK_MENU_TYPES {
namespace Chest {
interface Settings extends sc.QuickMenuTypesBase {
interface Settings extends sc.QuickMenuTypesBaseSettings {
type: "Chest";
entity: ig.ENTITY.Chest;
}
Expand Down Expand Up @@ -49,7 +43,7 @@ declare global {

show(this: this, tooltip: sc.QuickMenuTypesBase): void;
hide(this: this): void;
setData(this: this, chest: ig.ENTITY.Chest): boolean;
setData(this: this, chest: ig.Entity): boolean;
alignToBase(this: this, otherHook: ig.GuiHook): void;
}
interface ChestConstructor extends ImpactClass<Chest> {
Expand All @@ -70,7 +64,7 @@ export function patch(plugin: MwRandomizer) {
return;
}

this.mwCheck = map.chests?.[this.mapId];
this.mwCheck = map.chests?.[this.mapId!];
if (!this.mwCheck) {
return;
}
Expand All @@ -83,22 +77,16 @@ export function patch(plugin: MwRandomizer) {
sc.multiworld.seenChests.add(this.mwCheck.mwids[0]);
}

const clearance = sc.multiworld.options.chestClearanceLevels?.[this.mwCheck.mwids[0]];
const clearance = sc.multiworld.options.chestClearanceLevels?.[this.mwCheck.mwids[0]];

if (clearance != undefined) {
this.chestType = sc.CHEST_TYPE[clearance];
}

const anims = this.animSheet.anims as unknown as {
idleKey: ig.MultiDirAnimationSet
idleMasterKey: ig.MultiDirAnimationSet
idleGold: ig.MultiDirAnimationSet
idleSilver: ig.MultiDirAnimationSet
idleBronze: ig.MultiDirAnimationSet
idle: ig.MultiDirAnimationSet
open: ig.MultiDirAnimationSet
end: ig.MultiDirAnimationSet
}
const anims = this.animSheet.anims as unknown as Record<
'idleKey' | 'idleMasterKey' | 'idleGold' | 'idleSilver' |
'idleBronze' | 'idle' | 'open' | 'end',
ig.SingleDirAnimationSet>

// FILLER items get a normal chest with an archipelago logo on it
// These are the default values
Expand Down Expand Up @@ -142,16 +130,18 @@ export function patch(plugin: MwRandomizer) {
let animations = anims[name].animations;

if (name.startsWith("idle")) {
animations[0].sheet.offY = newOffY;
animations[0].sheet.offX = newOffX;
const sheet = animations[0].sheet as ig.TileSheet;
sheet.offY = newOffY;
sheet.offX = newOffX;
}

if (name == "idleGold") {
animations[1].sequence = [sequence];
}

if (name == "open" || name == "end") {
anims[name].animations[0].sheet.offY = newOffY + 24;
const sheet = animations[0].sheet as ig.TileSheet;
sheet.offY = newOffY + 24;
}
}
},
Expand Down Expand Up @@ -180,7 +170,7 @@ export function patch(plugin: MwRandomizer) {
},

isQuickMenuVisible() {
return this.mwCheck && this.rawChest;
return !!(this.mwCheck && this.rawChest);
},

_reallyOpenUp() {
Expand Down Expand Up @@ -282,7 +272,7 @@ export function patch(plugin: MwRandomizer) {
},

setData(chest) {
if (!chest.mwCheck) {
if (!(chest instanceof ig.ENTITY.Chest) || !chest.mwCheck) {
return false;
}

Expand Down
1 change: 1 addition & 0 deletions src/patches/entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export function patch(plugin: MwRandomizer) {
if (
entity
&& entity.settings
&& 'mapId' in entity.settings
&& entity.settings.mapId
&& mapOverrides.cutscenes
&& mapOverrides.cutscenes[entity.settings.mapId]
Expand Down
17 changes: 9 additions & 8 deletions src/patches/gui-misc.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as ap from 'archipelago.js';
import type MwRandomizer from '../plugin';

import type * as _ from 'nax-ccuilib/src/headers/nax/input-field.d.ts'
import type {} from 'nax-ccuilib/src/headers/nax/input-field.d.ts'
import type {} from 'nax-ccuilib/src/headers/nax/input-field-type.d.ts'

declare global {
namespace sc {
Expand Down Expand Up @@ -41,7 +41,7 @@ declare global {
back: null;
keepOpen: boolean;

getOptions(this: this): Record<string, string>;
getOptions(this: this): sc.MultiWorldModel.AnyConnectionInformation;
onBackButtonPress(this: this): void;
connectFromInput(this: this): void;
}
Expand Down Expand Up @@ -192,7 +192,8 @@ export function patch(plugin: MwRandomizer) {
this.fields[i].obscure ?? false
);

inputGui.description = ig.lang.get("sc.gui.mw.connection-menu." + this.fields[i].key);
// @ts-expect-error
inputGui.data = ig.lang.get("sc.gui.mw.connection-menu." + this.fields[i].key);

this.buttongroup.addFocusGui(inputGui, 0, i);
inputGui.hook.pos.y = (textGui.hook.size.y + this.vSpacer) * i;
Expand Down Expand Up @@ -244,21 +245,21 @@ export function patch(plugin: MwRandomizer) {

this.connect = new sc.ButtonGui("Connect", sc.BUTTON_MENU_WIDTH);
this.connect.onButtonPress = this.connectFromInput.bind(this);
this.connect.description = ig.lang.get("sc.gui.mw.connection-menu.connect");
this.connect.data = ig.lang.get("sc.gui.mw.connection-menu.connect");
this.buttongroup.addFocusGui(this.connect, 0, this.fields.length);

this.disconnect = new sc.ButtonGui("Disconnect", sc.BUTTON_MENU_WIDTH);
this.disconnect.onButtonPress = () => { sc.multiworld.disconnect() };
this.disconnect.setPos(sc.BUTTON_MENU_WIDTH + this.hSpacer);
this.disconnect.description = ig.lang.get("sc.gui.mw.connection-menu.disconnect");
this.disconnect.data = ig.lang.get("sc.gui.mw.connection-menu.disconnect");
this.buttongroup.addFocusGui(this.disconnect, 1, this.fields.length);

this.buttongroup.addSelectionCallback(button => {
if (button == undefined) {
sc.menu.setInfoText("", true);
return;
}
sc.menu.setInfoText(button.description);
sc.menu.setInfoText((button as sc.ButtonGui).data as string);
});

this.buttongroup.setMouseFocusLostCallback(() => {
Expand Down Expand Up @@ -298,7 +299,7 @@ export function patch(plugin: MwRandomizer) {
result[this.fields[i].key] = this.inputGuis[i].value.join("");
}

return result;
return result as unknown as sc.MultiWorldModel.AnyConnectionInformation;
},

connectFromInput() {
Expand Down
6 changes: 3 additions & 3 deletions src/patches/login.ts
Original file line number Diff line number Diff line change
Expand Up @@ -228,11 +228,11 @@ export function patch(plugin: MwRandomizer) {
});

sc.SaveList.inject({
onSlotLoadPressed(button: sc.SaveSlotButton) {
onSlotLoadPressed(button) {
let callback = this.parent;
let slot: ig.SaveSlot = ig.storage.getSlot(button.slot == -2 ? -1 : button.slot);
let mw = slot.data.vars.storage.mw;
sc.multiworld.spawnLoginGui(mw?.connectionInfo, mw, () => { callback(button); }, () => { callback(button) });
sc.multiworld.spawnLoginGui(mw?.connectionInfo, mw, () => { callback.call(this, button); }, () => { callback.call(this, button) });
}
});

Expand All @@ -246,7 +246,7 @@ export function patch(plugin: MwRandomizer) {
sc.menu.setDirectMode(true, sc.MENU_SUBMENU.AP_TEXT_CLIENT);
sc.menu.exitCallback = () => {
if (sc.multiworld.client.authenticated) {
button.data = 0;
(button as sc.ButtonGui).data = 0;
oldCallback(button);
}
};
Expand Down
8 changes: 0 additions & 8 deletions src/patches/map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,6 @@ declare global {
}

var MultiworldChestMarker: MultiworldMapMarkerConstructor;

interface MapAreaContainer {
loadNewArea(areaName: string): void;
createLandmarks(doAnything: boolean, floor: MapFloor): void;
}

interface MapFloor extends ig.GuiElementBase {
}
}
}

Expand Down
4 changes: 4 additions & 0 deletions src/patches/marquee.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@ declare global {
}

var MarqueeGroup: sc.MarqueeGroupConstructor;

interface ButtonGui {
textChild: ItemMarqueeGui
}
}
}

Expand Down
4 changes: 3 additions & 1 deletion src/patches/multiworld-hud.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,9 @@ export function patch(plugin: MwRandomizer) {
for (var i = this.contentEntries.length, gui = null; i--; ) {
gui = this.contentEntries[i];
gui.subGui.updateOption(isNormalSize);
gui.setContent(gui.subGui);

// potential crash? setContent doesn't exist on sc.MultiWorldItemContent
// gui.setContent(gui.subGui);
}
this.rearrangeContent();
},
Expand Down
34 changes: 17 additions & 17 deletions src/patches/multiworld-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@ export function patch(plugin: MwRandomizer) {
};

sc.MULTIWORLD_CONNECTION_STATUS = {
CONNECTED: "CONNECTED",
CONNECTING: "CONNECTING",
DISCONNECTED: "DISCONNECTED",
CONNECTED: "CONNECTED" as sc.MULTIWORLD_CONNECTION_STATUS.CONNECTED,
CONNECTING: "CONNECTING" as sc.MULTIWORLD_CONNECTION_STATUS.CONNECTING,
DISCONNECTED: "DISCONNECTED" as sc.MULTIWORLD_CONNECTION_STATUS.DISCONNECTED,
};


sc.MultiWorldModel = ig.GameAddon.extend({
observers: [],
client: null,
Expand All @@ -30,7 +31,7 @@ export function patch(plugin: MwRandomizer) {
numItems: 0,

init() {
this.client = new ap.Client({autoFetchDataPackage: false});
this.client = new ap.Client({autoFetchDataPackage: false, debugLogVersions: true});
ig.storage.register(this);
this.numItems = 676;

Expand Down Expand Up @@ -404,18 +405,18 @@ export function patch(plugin: MwRandomizer) {
// Lots of errors here, sorry

// Unset all variables that aren't bound to properties already
this.slimLocationInfo = null;
this.locationInfo = null;
this.connectionInfo = null;
this.mode = null;
this.options = null;

this.dataPackageChecksums = null;

this.questSettings = null;
this.receivedItemMap = null;
this.offlineCheckBuffer = null;
this.seenChests = null;
this.slimLocationInfo = null as any;
this.locationInfo = null as any;
this.connectionInfo = null as any;
this.mode = null as any;
this.options = null as any;

this.dataPackageChecksums = null as any;

this.questSettings = null as any;
this.receivedItemMap = null as any;
this.offlineCheckBuffer = null as any;
this.seenChests = null as any;
},

onLevelLoadStart() {
Expand Down Expand Up @@ -532,7 +533,6 @@ export function patch(plugin: MwRandomizer) {
saveDataPackage(this.client.package.exportPackage());
} catch (e: any) {
fatalError(e.message);
this.roomInfo = null;
return;
}

Expand Down
4 changes: 2 additions & 2 deletions src/patches/new-game.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ export function patch(plugin: MwRandomizer) {
sc.NewGamePlusModel.inject({
options: { "rhombus-start": true },
onReset() {
this.options = { "rhombus-start": true },
this.active = false;
this.parent();
this.options['rhombus-start'] = true;
}
});

Expand Down
4 changes: 2 additions & 2 deletions src/patches/shop.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ declare global {
}

interface ShopItemButton {
apItem: ap.NetworkItem | undefined;
apItem: ap.Item | undefined;
itemId: number | undefined;
worldGui: sc.TextGui | undefined;
slot: string | undefined;
Expand Down Expand Up @@ -104,7 +104,7 @@ export function patch(plugin: MwRandomizer) {
const gui = entry.gui as unknown as sc.ShopItemButton;
gui.hook.pos.y += accum;

const itemId: number = gui.data.id;
const itemId: number = gui.data.id as number;
const mwid: number = this.shopData[itemId];

if (sc.multiworld.localCheckedLocations.has(mwid)) {
Expand Down
Loading