-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathplugin.ts
More file actions
131 lines (112 loc) · 3.51 KB
/
plugin.ts
File metadata and controls
131 lines (112 loc) · 3.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
import * as ap from 'archipelago.js';
import {WorldData, ItemInfo} from './item-data.model';
import {readJsonFromFile} from './utils';
import {applyPatches} from "./patches/index";
// install a bunch of polyfills for archipelago.js
require('iterator-polyfill');
declare global {
namespace sc {
var randoData: WorldData;
var multiWorldHud: sc.MultiWorldHudBox;
}
}
// BEHOLD... THE UNIFILLS
// They're not polyfills because they are only guaranteed to work in this one particular environment lol
// The polyfill for this added 87 (!) dependencies
declare global {
interface Array<T> {
toSorted(comparefn?: (a: any, b: any) => number): Array<T>;
}
}
if (!Array.prototype.toSorted) {
Array.prototype.toSorted = function<T extends Array<E>, E>(this: T, comparefn?: (a: any, b: any) => number) {
let result = [...this];
result.sort(comparefn);
return result;
};
}
// This one would probably be similar but I did not even download it
Object.fromEntries = function(iterable: Iterable<[key: any, value: any]>) {
let result: Record<any, any> = {};
for (const [key, value] of iterable) {
result[key] = value;
}
return result;
};
import structuredClone from "@ungap/structured-clone";
if (!("structuredClone" in globalThis)) {
// @ts-expect-error
globalThis.structuredClone = structuredClone;
}
declare global {
namespace ig.Input {
interface KnownActions {
pgdn: true;
pgup: true;
home: true;
end: true;
}
}
}
export default class MwRandomizer {
baseDirectory: string;
randoData!: WorldData;
itemdb: any;
constructor(mod: {baseDirectory: string}) {
this.baseDirectory = mod.baseDirectory;
}
getColoredStatus(status: string) {
switch (status.toLowerCase()) {
case sc.MULTIWORLD_CONNECTION_STATUS.CONNECTED.toLowerCase():
return `\\c[2]${status}\\c[0]`;
case sc.MULTIWORLD_CONNECTION_STATUS.DISCONNECTED.toLowerCase():
return `\\c[1]${status}\\c[0]`;
case sc.MULTIWORLD_CONNECTION_STATUS.CONNECTING.toLowerCase():
return `\\c[3]${status}\\c[0]`;
}
}
getGuiString(item: {icon: string; label: string}): string {
return `\\i[${item.icon}]${item.label}`;
}
async prestart() {
let randoData: WorldData = await readJsonFromFile(this.baseDirectory + "data/out/data.json");
this.randoData = randoData;
sc.randoData = randoData;
let itemdb = await readJsonFromFile("assets/data/item-database.json");
this.itemdb = itemdb;
// For those times JS decides to override `this`
// Used several times in the injection code
let plugin = this;
applyPatches(this);
sc.PartyModel.inject({
addPartyMember(name: string, ...args) {
this.parent(name, ...args);
sc.party.getPartyMemberModel(name).setSpLevel(sc.model.player.spLevel);
},
});
let mwIcons = new ig.Font(plugin.baseDirectory.substring(7) + "assets/media/font/icons-multiworld.png", 16, ig.MultiFont.ICON_START);
let index = sc.fontsystem.font.iconSets.length;
sc.fontsystem.font.pushIconSet(mwIcons);
sc.fontsystem.font.setMapping({
"mw-item": [index, 0],
"ap-logo": [index, 2],
"ap-item-unknown": [index, 2],
"ap-item-trap": [index, 3],
"ap-item-filler": [index, 4],
"ap-item-useful": [index, 5],
"ap-item-prog": [index, 6],
"ap-locked": [index, 7],
});
sc.CrossCode.inject({
init() {
this.parent();
sc.multiWorldHud = new sc.MultiWorldHudBox();
sc.gui.rightHudPanel.addHudBox(sc.multiWorldHud);
ig.input.bind(ig.KEY.PAGE_DOWN, "pgdn");
ig.input.bind(ig.KEY.PAGE_UP, "pgup");
ig.input.bind(ig.KEY.HOME, "home");
ig.input.bind(ig.KEY.END, "end");
},
});
}
}