Skip to content

Commit

Permalink
Fix circular dependency.
Browse files Browse the repository at this point in the history
  • Loading branch information
phulin committed Nov 1, 2024
1 parent afc7acd commit bd76155
Show file tree
Hide file tree
Showing 10 changed files with 64 additions and 72 deletions.
2 changes: 1 addition & 1 deletion packages/tome-kolmafia-lib/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "tome-kolmafia-lib",
"version": "5.28107.2",
"version": "5.28107.3",
"description": "Library functions for tome-kolmafia-mock and tome-kolmafia-react.",
"author": "loathers",
"license": "MIT",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// IMPORTANT: This file is automatically generated
// If you would like to update it, try yarn generate
/* eslint-disable @typescript-eslint/no-explicit-any */
import { remoteCall } from "../../api/remote";
import { remoteCallFunction as remoteCall } from "../remote";
8 changes: 3 additions & 5 deletions packages/tome-kolmafia-lib/scripts/updateDefinitions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ function reasonableDefault(
case "boolean":
return "false";
case "void":
return "";
return "undefined";
case "ModifierValueType":
case "Environment":
return '"none"';
case "never":
return "";
return "undefined";
}
// Union of string literals.
const match = resultType.match(/("[A-Za-z0-9]+")( \| +"[A-Za-z0-9]+")+/);
Expand Down Expand Up @@ -118,9 +118,7 @@ function generateFunctions(data: string, enumeratedTypes: string[]) {
`export function ${prevFuncName}(...args: unknown[]): ${resultsStr} {`,
);
out.push(
` ${isNever ? "throw" : "return"} remoteCall('${prevFuncName}', args${
def !== "" ? `, ${def}` : ""
})`,
` ${isNever ? "throw" : "return"} remoteCall('${prevFuncName}', args, ${def})`,
);
out.push("}");
results = [];
Expand Down
9 changes: 1 addition & 8 deletions packages/tome-kolmafia-lib/src/api/remote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,19 +89,12 @@ function processOverrides<T>(
* @param default_ Default return value, while we wait for a response.
* @param processOverrides If true, ignore values overridden (development mode). If this is true, may not return singletonized value.
*/
export function remoteCall(name: string, args: unknown[]): void;
export function remoteCall<T>(
name: string,
args: unknown[],
default_: T,
ignoreOverrides?: boolean,
): T;
export function remoteCall<T>(
name: string,
args: unknown[],
default_?: T,
ignoreOverrides = false,
): void | T {
): T {
if (args.some((arg) => arg === null)) {
throw new Error("Can't make a remote call with null arguments.");
}
Expand Down
2 changes: 1 addition & 1 deletion packages/tome-kolmafia-lib/src/api/transform.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { EnumeratedType, enumeratedTypes } from "../kolmafia";
import { EnumeratedType, enumeratedTypes } from "../kolmafia/generated/types";
import {
EnumeratedTypeName,
Identified,
Expand Down
20 changes: 1 addition & 19 deletions packages/tome-kolmafia-lib/src/kolmafia/enumerated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,7 @@ import {
makePlaceholder,
ValidIdentifier,
} from "../types";

type RemoteCall = <T>(
name: string,
args: unknown[],
default_?: T,
ignoreOverrides?: boolean,
) => void | T;

let remoteCallFunction: RemoteCall = <T>(
name: string,
args: unknown[],
default_?: T,
) => {
return default_;
};

export function setRemoteCallFunction(remoteCall: RemoteCall) {
remoteCallFunction = remoteCall;
}
import { remoteCallFunction } from "./remote";

export type TypeName<T> = T extends MafiaClass<infer U> ? U : never;

Expand Down
72 changes: 36 additions & 36 deletions packages/tome-kolmafia-lib/src/kolmafia/generated/functions.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// IMPORTANT: This file is automatically generated
// If you would like to update it, try yarn generate
/* eslint-disable @typescript-eslint/no-explicit-any */
import { remoteCall } from "../../api/remote";
import { remoteCallFunction as remoteCall } from "../remote";
import {
Bounty,
Class,
Expand All @@ -25,7 +25,7 @@ import {

export function abort(string?: string): never;
export function abort(...args: unknown[]): never {
throw remoteCall("abort", args);
throw remoteCall("abort", args, undefined);
}
export function absorbedMonsters(): { [monster: string]: boolean };
export function absorbedMonsters(...args: unknown[]): {
Expand All @@ -36,7 +36,7 @@ export function absorbedMonsters(...args: unknown[]): {
export function addItemCondition(count: number, item: Item): void;
export function addItemCondition(item: Item, count: number): void;
export function addItemCondition(...args: unknown[]): void {
return remoteCall("addItemCondition", args);
return remoteCall("addItemCondition", args, undefined);
}
export function adv1(
locationValue: Location,
Expand Down Expand Up @@ -154,7 +154,7 @@ export function batchClose(...args: unknown[]): boolean {
}
export function batchOpen(): void;
export function batchOpen(...args: unknown[]): void {
return remoteCall("batchOpen", args);
return remoteCall("batchOpen", args, undefined);
}
export function bjornifyFamiliar(familiar: Familiar): boolean;
export function bjornifyFamiliar(...args: unknown[]): boolean {
Expand Down Expand Up @@ -269,19 +269,19 @@ export function charAt(...args: unknown[]): string {
}
export function chatClan(messageValue: string, recipientValue?: string): void;
export function chatClan(...args: unknown[]): void {
return remoteCall("chatClan", args);
return remoteCall("chatClan", args, undefined);
}
export function chatMacro(macroValue: string): void;
export function chatMacro(...args: unknown[]): void {
return remoteCall("chatMacro", args);
return remoteCall("chatMacro", args, undefined);
}
export function chatNotify(messageValue: string, colorValue: string): void;
export function chatNotify(...args: unknown[]): void {
return remoteCall("chatNotify", args);
return remoteCall("chatNotify", args, undefined);
}
export function chatPrivate(recipientValue: string, messageValue: string): void;
export function chatPrivate(...args: unknown[]): void {
return remoteCall("chatPrivate", args);
return remoteCall("chatPrivate", args, undefined);
}
export function chew(item: Item, count?: number): boolean;
export function chew(count: number, item: Item): boolean;
Expand All @@ -301,15 +301,15 @@ export function classModifier(...args: unknown[]): Class {
}
export function clear(agg: any): void;
export function clear(...args: unknown[]): void {
return remoteCall("clear", args);
return remoteCall("clear", args, undefined);
}
export function clearBoozeHelper(): void;
export function clearBoozeHelper(...args: unknown[]): void {
return remoteCall("clearBoozeHelper", args);
return remoteCall("clearBoozeHelper", args, undefined);
}
export function clearFoodHelper(): void;
export function clearFoodHelper(...args: unknown[]): void {
return remoteCall("clearFoodHelper", args);
return remoteCall("clearFoodHelper", args, undefined);
}
export function cliExecute(string: string): boolean;
export function cliExecute(...args: unknown[]): boolean {
Expand Down Expand Up @@ -346,7 +346,7 @@ export function containsText(...args: unknown[]): boolean {
}
export function council(): void;
export function council(...args: unknown[]): void {
return remoteCall("council", args);
return remoteCall("council", args, undefined);
}
export function count(agg: any): number;
export function count(...args: unknown[]): number {
Expand Down Expand Up @@ -456,7 +456,7 @@ export function daycount(...args: unknown[]): number {
}
export function debugprint(string: string): void;
export function debugprint(...args: unknown[]): void {
return remoteCall("debugprint", args);
return remoteCall("debugprint", args, undefined);
}
export function descToEffect(value: string): Effect;
export function descToEffect(...args: unknown[]): Effect {
Expand All @@ -468,7 +468,7 @@ export function descToItem(...args: unknown[]): Item {
}
export function disable(name: string): void;
export function disable(...args: unknown[]): void {
return remoteCall("disable", args);
return remoteCall("disable", args, undefined);
}
export function dispensaryAvailable(): boolean;
export function dispensaryAvailable(...args: unknown[]): boolean {
Expand All @@ -490,7 +490,7 @@ export function drinksilent(...args: unknown[]): boolean {
}
export function dump(arg: any, color?: string): void;
export function dump(...args: unknown[]): void {
return remoteCall("dump", args);
return remoteCall("dump", args, undefined);
}
export function eat(item: Item, count?: number): boolean;
export function eat(count: number, item: Item): boolean;
Expand Down Expand Up @@ -538,7 +538,7 @@ export function emptyCloset(...args: unknown[]): boolean {
}
export function enable(name: string): void;
export function enable(...args: unknown[]): void {
return remoteCall("enable", args);
return remoteCall("enable", args, undefined);
}
export function endsWith(source: string, suffix: string): boolean;
export function endsWith(...args: unknown[]): boolean {
Expand Down Expand Up @@ -1374,15 +1374,15 @@ export function loadHtml(...args: unknown[]): string {
}
export function lockFamiliarEquipment(lock: boolean): void;
export function lockFamiliarEquipment(...args: unknown[]): void {
return remoteCall("lockFamiliarEquipment", args);
return remoteCall("lockFamiliarEquipment", args, undefined);
}
export function logN(val: number, base?: number): number;
export function logN(...args: unknown[]): number {
return remoteCall("logN", args, 0);
}
export function logprint(string: string): void;
export function logprint(...args: unknown[]): void {
return remoteCall("logprint", args);
return remoteCall("logprint", args, undefined);
}
export function makeUrl(
string: string,
Expand Down Expand Up @@ -1547,7 +1547,7 @@ export function monsterPockets(...args: unknown[]): { [key: number]: boolean } {
}
export function moodExecute(multiplicity: number): void;
export function moodExecute(...args: unknown[]): void {
return remoteCall("moodExecute", args);
return remoteCall("moodExecute", args, undefined);
}
export function moodList(): string[];
export function moodList(...args: unknown[]): string[] {
Expand Down Expand Up @@ -1993,11 +1993,11 @@ export function prepareForAdventure(...args: unknown[]): boolean {
export function print(string?: string): void;
export function print(string: string, color?: string): void;
export function print(...args: unknown[]): void {
return remoteCall("print", args);
return remoteCall("print", args, undefined);
}
export function printHtml(string: string, logToSession?: boolean): void;
export function printHtml(...args: unknown[]): void {
return remoteCall("printHtml", args);
return remoteCall("printHtml", args, undefined);
}
export function propertyDefaultValue(nameValue: string): string;
export function propertyDefaultValue(...args: unknown[]): string {
Expand Down Expand Up @@ -2084,7 +2084,7 @@ export function readCcs(...args: unknown[]): string {
}
export function receiveFax(): void;
export function receiveFax(...args: unknown[]): void {
return remoteCall("receiveFax", args);
return remoteCall("receiveFax", args, undefined);
}
export function refreshShop(): boolean;
export function refreshShop(...args: unknown[]): boolean {
Expand All @@ -2101,7 +2101,7 @@ export function refreshStatus(...args: unknown[]): boolean {
export function removeItemCondition(count: number, item: Item): void;
export function removeItemCondition(item: Item, count: number): void;
export function removeItemCondition(...args: unknown[]): void {
return remoteCall("removeItemCondition", args);
return remoteCall("removeItemCondition", args, undefined);
}
export function removeProperty(
nameValue: string,
Expand Down Expand Up @@ -2251,7 +2251,7 @@ export function sellsItem(...args: unknown[]): boolean {
}
export function sendFax(): void;
export function sendFax(...args: unknown[]): void {
return remoteCall("sendFax", args);
return remoteCall("sendFax", args, undefined);
}
export function sessionLogs(dayCount: number): string[];
export function sessionLogs(player: string, dayCount: number): string[];
Expand All @@ -2266,23 +2266,23 @@ export function sessionLogs(...args: unknown[]): string[] {
export function setAutoAttack(attackValue: number): void;
export function setAutoAttack(attackValue: string): void;
export function setAutoAttack(...args: unknown[]): void {
return remoteCall("setAutoAttack", args);
return remoteCall("setAutoAttack", args, undefined);
}
export function setCcs(name: string): boolean;
export function setCcs(...args: unknown[]): boolean {
return remoteCall("setCcs", args, false);
}
export function setLength(buffer: string, i: number): void;
export function setLength(...args: unknown[]): void {
return remoteCall("setLength", args);
return remoteCall("setLength", args, undefined);
}
export function setLocation(location: Location): void;
export function setLocation(...args: unknown[]): void {
return remoteCall("setLocation", args);
return remoteCall("setLocation", args, undefined);
}
export function setProperty(nameValue: string, value: string): void;
export function setProperty(...args: unknown[]): void {
return remoteCall("setProperty", args);
return remoteCall("setProperty", args, undefined);
}
export function shopAmount(item: Item): number;
export function shopAmount(...args: unknown[]): number {
Expand Down Expand Up @@ -2366,7 +2366,7 @@ export function stillsAvailable(...args: unknown[]): number {
}
export function stopCounter(label: string): void;
export function stopCounter(...args: unknown[]): void {
return remoteCall("stopCounter", args);
return remoteCall("stopCounter", args, undefined);
}
export function storageAmount(item: Item): number;
export function storageAmount(...args: unknown[]): number {
Expand Down Expand Up @@ -2689,7 +2689,7 @@ export function towerDoor(...args: unknown[]): boolean {
}
export function traceprint(string: string): void;
export function traceprint(...args: unknown[]): void {
return remoteCall("traceprint", args);
return remoteCall("traceprint", args, undefined);
}
export function trackCopyCount(monster: Monster): number;
export function trackCopyCount(...args: unknown[]): number {
Expand Down Expand Up @@ -2729,7 +2729,7 @@ export function unusualConstructDisc(...args: unknown[]): Item {
}
export function updateCandyPrices(): void;
export function updateCandyPrices(...args: unknown[]): void {
return remoteCall("updateCandyPrices", args);
return remoteCall("updateCandyPrices", args, undefined);
}
export function urlDecode(string: string): string;
export function urlDecode(...args: unknown[]): string {
Expand Down Expand Up @@ -2769,7 +2769,7 @@ export function userConfirm(...args: unknown[]): boolean {
}
export function userNotify(message: string, onlyShowWhenHidden?: boolean): void;
export function userNotify(...args: unknown[]): void {
return remoteCall("userNotify", args);
return remoteCall("userNotify", args, undefined);
}
export function userPrompt(message: string, options?: any): string;
export function userPrompt(
Expand Down Expand Up @@ -2811,11 +2811,11 @@ export function votingBoothInitiatives(...args: unknown[]): {
}
export function wait(delay: number): void;
export function wait(...args: unknown[]): void {
return remoteCall("wait", args);
return remoteCall("wait", args, undefined);
}
export function waitq(delay: number): void;
export function waitq(...args: unknown[]): void {
return remoteCall("waitq", args);
return remoteCall("waitq", args, undefined);
}
export function weaponHands(item: Item): number;
export function weaponHands(...args: unknown[]): number {
Expand Down Expand Up @@ -2855,15 +2855,15 @@ export function willUsuallyMiss(...args: unknown[]): boolean {
}
export function write(string: string): void;
export function write(...args: unknown[]): void {
return remoteCall("write", args);
return remoteCall("write", args, undefined);
}
export function writeCcs(data: string, name: string): boolean;
export function writeCcs(...args: unknown[]): boolean {
return remoteCall("writeCcs", args, false);
}
export function writeln(string: string): void;
export function writeln(...args: unknown[]): void {
return remoteCall("writeln", args);
return remoteCall("writeln", args, undefined);
}
export function xpath(html: string, xpath: string): string[];
export function xpath(...args: unknown[]): string[] {
Expand Down
1 change: 1 addition & 0 deletions packages/tome-kolmafia-lib/src/kolmafia/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from "./enumerated";
export * from "./generated/functions";
export * from "./generated/types";
export * from "./remote";
Loading

0 comments on commit bd76155

Please sign in to comment.