You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/ts/handler.ts
+13-10Lines changed: 13 additions & 10 deletions
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,6 @@
1
1
exportclassHandler<T>implementsIterable<T>{
2
2
/** This stores the stringified Identifier as the key and then the values is obviously T. We store the identifier stringified because objects are never equal so we can't `get()` from the Map without using the same obj reference. */
console.error(`Tried to register object with Identifier "${identifier.toString()}" to a Handler, but it already exists!`);
17
17
// todo ASAP: should this return?
@@ -28,7 +28,7 @@ export class Handler<T> implements Iterable<T> {
28
28
console.warn(`Tried to get object from a Handler but identifier was undefined. Will return %cundefined%c.`,"font-style: italic;","font-style: default;");
console.warn(`Tried to get object from a Handler with Identifier "${identifier}" that does not exist. Will return %cundefined%c.`,"font-style: italic;","font-style: default;");
34
34
}
@@ -46,11 +46,11 @@ export class Handler<T> implements Iterable<T> {
46
46
}
47
47
48
48
/**
49
-
* Gets a stringified key from a given registered value
49
+
* Gets a stringified identifier from a given registered value
@@ -90,7 +90,7 @@ export class UniqueKeyHandler<T> implements Iterable<T> {
90
90
* If a {@link T} is registered with the given ID than return it, if it's not then return undefined
91
91
* @param key The key to get from
92
92
*/
93
-
getFromIdentifier(key: string): T|undefined{
93
+
getFromKey(key: string): T|undefined{
94
94
if(key===undefined){
95
95
console.warn(`Tried to get object from a UniqueKeyHandler but key was undefined. Will return %cundefined%c.`,"font-style: italic;","font-style: default;");
96
96
returnundefined;
@@ -107,7 +107,7 @@ export class UniqueKeyHandler<T> implements Iterable<T> {
console.warn(`Cannot construct a new Identifier from invalid string "${stringified}". Returning %cundefined%c.`,"font-style: italic;","font-style: default;");
@@ -149,7 +149,7 @@ export class Identifier {
149
149
/**
150
150
* @returns Format: `namespace:uid`
151
151
*/
152
-
toString(): string{
152
+
toString(): StringifiedIdentifier{
153
153
return`${this.namespace}:${this.uid}`;
154
154
}
155
155
@@ -163,4 +163,7 @@ export class Identifier {
163
163
else
164
164
returnfalse;
165
165
}
166
-
}
166
+
}
167
+
168
+
/** An alias for a `string` that exists to make typing more clear to the user whenever a stringified identifier is involved, as there are obviously requirements expected in that case that need to be clearly shown to the user to avoid errors. */
Copy file name to clipboardExpand all lines: src/ts/handlers.ts
+12-12Lines changed: 12 additions & 12 deletions
Original file line number
Diff line number
Diff line change
@@ -1,7 +1,7 @@
1
1
//* Ideally I would put things like BackgroundHandler in personalization.ts but because of lexical declarations we can't do that without getting circular imports as far as I can tell. This is fine.
@@ -89,7 +89,7 @@ export class CurrentlyClickedHandler extends Handler<CurrentlyClickedObject> {
89
89
* This method kinda sucks but we need it to work this way because of how {@link HTMLSelectElement}s work
90
90
* @param stringifiedIdentifier The stringified identifier of whatever {@link Background} we want from {@link currentlyClickedHandler}. Usually `currentlyClickedSelect`'s `value`
console.log("Successfully added mod from file: "+file.name);
307
307
};
@@ -378,7 +378,7 @@ export class ModHandler extends UniqueKeyHandler<Mod<any>> {
378
378
*/
379
379
overrideregister(key: string,mod: Mod<any>){
380
380
//! below will always warn, should that be changed?
381
-
if(this.getFromIdentifier(key)!==undefined){//* do this before registering so we can get a more user-friendly popup than the console.error that we usually get for this type of error
381
+
if(this.getFromKey(key)!==undefined){//* do this before registering so we can get a more user-friendly popup than the console.error that we usually get for this type of error
382
382
newSimplePopup({x: 400,y: 200,title: "Error",text: `The mod namespace "${key}" is already present!`});
0 commit comments