mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2026-04-27 11:27:04 +02:00
MISC: A bunch of enums stuff. (#212)
* Some game enums moved to utils/enums. Others can eventually be moved there as well. * findEnumMember function for performing fuzzy matching of player input with enum members, without needing separate fuzzy functions for every enum. * Also used findEnumMember for safely loading save games (allows case changes in enum values) * Changed capitalization on some enums. * BREAKING: removed classGains work formulas function * Split ClassType enum into UniversityClassType and GymType. * Added universityGains and gymGains work formulas functions * Provided the new split enums to the player on ns.enums.
This commit is contained in:
@@ -1,4 +0,0 @@
|
||||
/** Verifies that a supplied value is a member of the provided object/enum. Works for enums as well as enum-like objects (const {} as const). */
|
||||
export function checkEnum<T extends Record<string, unknown>>(obj: T, value: unknown): value is T[keyof T] {
|
||||
return Object.values(obj).includes(value);
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
/** Verifies that a supplied value is a member of the provided object/enum. Works for enums as well as enum-like objects (const {} as const). */
|
||||
export function checkEnum<T extends Record<string, unknown>>(obj: T, value: unknown): value is T[keyof T] {
|
||||
return Object.values(obj).includes(value);
|
||||
}
|
||||
|
||||
export function findEnumMember<T extends Record<string, string>>(obj: T, value: string): T[keyof T] | undefined {
|
||||
const lowerValue = value.toLowerCase().replace(/ /g, "");
|
||||
for (const member of Object.values(obj) as T[keyof T][]) {
|
||||
if (lowerValue.includes(member.toLowerCase().replace(/ /g, ""))) return member;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user