libram 0.8.35 → 0.8.36

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/combat.d.ts CHANGED
@@ -119,7 +119,7 @@ export declare class Macro {
119
119
  * Create a new macro with an "abort" step to this macro, with a warning message to print
120
120
  *
121
121
  * @param warning The warning message to print
122
- * @returns {Macro} This object itself.
122
+ * @returns {Macro} This object itself.
123
123
  */
124
124
  static abortWithWarning<T extends Macro>(this: Constructor<T>, warning: string): T;
125
125
  /**
@@ -134,7 +134,12 @@ export declare class Macro {
134
134
  * @returns {Macro} This object itself.
135
135
  */
136
136
  static runaway<T extends Macro>(this: Constructor<T>): T;
137
- private static makeBALLSPredicate;
137
+ /**
138
+ *
139
+ * @param condition The BALLS condition or a type to make a condition for (Monster, Item, Skill, etc.)
140
+ * @returns {string} The BALLS condition string
141
+ */
142
+ static makeBALLSPredicate(condition: PreBALLSPredicate): string;
138
143
  /**
139
144
  * Add an "if" statement to this macro.
140
145
  *
@@ -170,19 +175,19 @@ export declare class Macro {
170
175
  /**
171
176
  * Add a "while" statement to this macro.
172
177
  *
173
- * @param condition The BALLS condition for the if statement.
178
+ * @param condition The BALLS condition for the while statement.
174
179
  * @param contents Loop to repeat while the condition is true.
175
180
  * @returns {Macro} This object itself.
176
181
  */
177
- while_(condition: string, contents: string | Macro): this;
182
+ while_(condition: PreBALLSPredicate, contents: string | Macro): this;
178
183
  /**
179
184
  * Create a new macro with a "while" statement.
180
185
  *
181
- * @param condition The BALLS condition for the if statement.
186
+ * @param condition The BALLS condition for the while statement.
182
187
  * @param contents Loop to repeat while the condition is true.
183
188
  * @returns {Macro} This object itself.
184
189
  */
185
- static while_<T extends Macro>(this: Constructor<T>, condition: string, contents: string | Macro): T;
190
+ static while_<T extends Macro>(this: Constructor<T>, condition: PreBALLSPredicate, contents: string | Macro): T;
186
191
  /**
187
192
  * Conditionally add a step to a macro based on a condition evaluated at the time of building the macro.
188
193
  *
@@ -204,9 +209,10 @@ export declare class Macro {
204
209
  /**
205
210
  * Add a repeat step to the macro.
206
211
  *
212
+ * @param condition The BALLS condition for the repeat statement, optional.
207
213
  * @returns {Macro} This object itself.
208
214
  */
209
- repeat(): this;
215
+ repeat(condition?: PreBALLSPredicate): this;
210
216
  /**
211
217
  * Add one or more skill cast steps to the macro.
212
218
  *
package/dist/combat.js CHANGED
@@ -246,7 +246,7 @@ export class Macro {
246
246
  * Create a new macro with an "abort" step to this macro, with a warning message to print
247
247
  *
248
248
  * @param warning The warning message to print
249
- * @returns {Macro} This object itself.
249
+ * @returns {Macro} This object itself.
250
250
  */
251
251
  static abortWithWarning(warning) {
252
252
  return new this().abortWithWarning(warning);
@@ -267,49 +267,49 @@ export class Macro {
267
267
  static runaway() {
268
268
  return new this().runaway();
269
269
  }
270
+ /**
271
+ *
272
+ * @param condition The BALLS condition or a type to make a condition for (Monster, Item, Skill, etc.)
273
+ * @returns {string} The BALLS condition string
274
+ */
270
275
  static makeBALLSPredicate(condition) {
271
- let ballsCondition = "";
272
276
  if (condition instanceof Monster) {
273
- ballsCondition = `monsterid ${condition.id}`;
277
+ return `monsterid ${condition.id}`;
274
278
  }
275
279
  else if (condition instanceof Array) {
276
- ballsCondition = condition
277
- .map((mon) => `monsterid ${mon.id}`)
278
- .join(" || ");
279
- ballsCondition = `(${ballsCondition})`;
280
+ return `(${condition
281
+ .map((entry) => Macro.makeBALLSPredicate(entry))
282
+ .join(" || ")})`;
280
283
  }
281
284
  else if (condition instanceof Effect) {
282
- ballsCondition = `haseffect ${condition.id}`;
285
+ return `haseffect ${condition.id}`;
283
286
  }
284
287
  else if (condition instanceof Skill) {
285
- ballsCondition = `hasskill ${skillBallsMacroName(condition)}`;
288
+ return `hasskill ${skillBallsMacroName(condition)}`;
286
289
  }
287
290
  else if (condition instanceof Item) {
288
291
  if (!condition.combat) {
289
292
  throw new InvalidMacroError(`Item ${condition} cannot be made a valid BALLS predicate (it is not combat-usable)`);
290
293
  }
291
- ballsCondition = `hascombatitem ${itemOrItemsBallsMacroName(condition)}`;
294
+ return `hascombatitem ${itemOrItemsBallsMacroName(condition)}`;
292
295
  }
293
296
  else if (condition instanceof Location) {
294
297
  const snarfblat = condition.id;
295
298
  if (snarfblat < 1) {
296
299
  throw new InvalidMacroError(`Location ${condition} cannot be made a valid BALLS predicate (it has no location id)`);
297
300
  }
298
- ballsCondition = `snarfblat ${snarfblat}`;
301
+ return `snarfblat ${snarfblat}`;
299
302
  }
300
303
  else if (condition instanceof Class) {
301
304
  if (condition.id > 6) {
302
305
  throw new InvalidMacroError(`Class ${condition} cannot be made a valid BALLS predicate (it is not a standard class)`);
303
306
  }
304
- ballsCondition = condition.toString().replaceAll(" ", "").toLowerCase();
307
+ return condition.toString().replaceAll(" ", "").toLowerCase();
305
308
  }
306
309
  else if (condition instanceof Stat) {
307
- ballsCondition = `${condition.toString().toLowerCase()}class`;
310
+ return `${condition.toString().toLowerCase()}class`;
308
311
  }
309
- else {
310
- ballsCondition = condition;
311
- }
312
- return ballsCondition;
312
+ return condition;
313
313
  }
314
314
  /**
315
315
  * Add an "if" statement to this macro.
@@ -358,17 +358,19 @@ export class Macro {
358
358
  /**
359
359
  * Add a "while" statement to this macro.
360
360
  *
361
- * @param condition The BALLS condition for the if statement.
361
+ * @param condition The BALLS condition for the while statement.
362
362
  * @param contents Loop to repeat while the condition is true.
363
363
  * @returns {Macro} This object itself.
364
364
  */
365
365
  while_(condition, contents) {
366
- return this.step(`while ${condition}`).step(contents).step("endwhile");
366
+ return this.step(`while ${Macro.makeBALLSPredicate(condition)}`)
367
+ .step(contents)
368
+ .step("endwhile");
367
369
  }
368
370
  /**
369
371
  * Create a new macro with a "while" statement.
370
372
  *
371
- * @param condition The BALLS condition for the if statement.
373
+ * @param condition The BALLS condition for the while statement.
372
374
  * @param contents Loop to repeat while the condition is true.
373
375
  * @returns {Macro} This object itself.
374
376
  */
@@ -405,10 +407,13 @@ export class Macro {
405
407
  /**
406
408
  * Add a repeat step to the macro.
407
409
  *
410
+ * @param condition The BALLS condition for the repeat statement, optional.
408
411
  * @returns {Macro} This object itself.
409
412
  */
410
- repeat() {
411
- return this.step("repeat");
413
+ repeat(condition) {
414
+ return condition === undefined
415
+ ? this.step("repeat")
416
+ : this.step(`repeat ${Macro.makeBALLSPredicate(condition)}`);
412
417
  }
413
418
  /**
414
419
  * Add one or more skill cast steps to the macro.
@@ -457,8 +462,10 @@ export class Macro {
457
462
  * @returns {Macro} This object itself.
458
463
  */
459
464
  trySkillRepeat(...skills) {
460
- return this.step(...skills.map((skill) => {
461
- return Macro.if_(`hasskill ${skillBallsMacroName(skill)}`, Macro.skill(skill).repeat());
465
+ return this.step(...skills
466
+ .map((skillOrName) => skillOrNameToSkill(skillOrName))
467
+ .map((skill) => {
468
+ return Macro.if_(Macro.makeBALLSPredicate(skill), Macro.skill(skill).repeat(skill));
462
469
  }));
463
470
  }
464
471
  /**
package/dist/lib.d.ts CHANGED
@@ -388,16 +388,18 @@ export declare function examine(thing: Item | Familiar | Effect | Skill): string
388
388
  * Picks an option based on your primestat
389
389
  *
390
390
  * @param options An object keyed by stat; it must either contain all stats, or have a `default` parameter.
391
+ * @param alternateSource An optional alternate way of determining which Stat to choose by.
391
392
  * @returns The option corresponding to your primestat.
392
393
  */
393
- export declare const byStat: <S>(options: import("./utils").Switch<import("kolmafia").StatType, S>) => S;
394
+ export declare const byStat: <S>(options: import("./utils").Switch<import("kolmafia").StatType, S>, alternateSource?: import("kolmafia").StatType | ((...args: never[]) => import("kolmafia").StatType) | undefined) => S;
394
395
  /**
395
396
  * Picks an option based on your player class
396
397
  *
397
398
  * @param options An object keyed by player class; it must either contain all classes, or have a `default` parameter.
399
+ * @param alternateSource An optional anternate way of determining which Class to choose by.
398
400
  * @returns The option corresponding to your player class.
399
401
  */
400
- export declare const byClass: <S>(options: import("./utils").Switch<import("kolmafia").ClassType, S>) => S;
402
+ export declare const byClass: <S>(options: import("./utils").Switch<import("kolmafia").ClassType, S>, alternateSource?: import("kolmafia").ClassType | ((...args: never[]) => import("kolmafia").ClassType) | undefined) => S;
401
403
  /**
402
404
  * Use an item with visitUrl instead of `use`; this is sometimes useful
403
405
  *
package/dist/lib.js CHANGED
@@ -771,6 +771,7 @@ export function examine(thing) {
771
771
  * Picks an option based on your primestat
772
772
  *
773
773
  * @param options An object keyed by stat; it must either contain all stats, or have a `default` parameter.
774
+ * @param alternateSource An optional alternate way of determining which Stat to choose by.
774
775
  * @returns The option corresponding to your primestat.
775
776
  */
776
777
  export const byStat = makeByXFunction(() => myPrimestat().toString());
@@ -778,6 +779,7 @@ export const byStat = makeByXFunction(() => myPrimestat().toString());
778
779
  * Picks an option based on your player class
779
780
  *
780
781
  * @param options An object keyed by player class; it must either contain all classes, or have a `default` parameter.
782
+ * @param alternateSource An optional anternate way of determining which Class to choose by.
781
783
  * @returns The option corresponding to your player class.
782
784
  */
783
785
  export const byClass = makeByXFunction(() => myClass().toString());
@@ -68,9 +68,10 @@ export declare function rifts(): Location[];
68
68
  * Picks an option based on your current shadow rift ingress
69
69
  *
70
70
  * @param options An object keyed by shadow rift ingress; it must either contain all possible ingresses, or have a `default` parameter.
71
+ * @param alternateSource An optional alternate way of determining which Ingress to choose by.
71
72
  * @returns The option corresponding to your current shadow rift ingress.
72
73
  */
73
- export declare const byIngress: <S>(options: import("../../utils").Switch<Ingress, S>) => S;
74
+ export declare const byIngress: <S>(options: import("../../utils").Switch<Ingress, S>, alternateSource?: Ingress | ((...args: never[]) => Ingress) | undefined) => S;
74
75
  /**
75
76
  * Submit your Rufus quest
76
77
  *
@@ -112,6 +112,7 @@ export function rifts() {
112
112
  * Picks an option based on your current shadow rift ingress
113
113
  *
114
114
  * @param options An object keyed by shadow rift ingress; it must either contain all possible ingresses, or have a `default` parameter.
115
+ * @param alternateSource An optional alternate way of determining which Ingress to choose by.
115
116
  * @returns The option corresponding to your current shadow rift ingress.
116
117
  */
117
118
  export const byIngress = makeByXFunction(currentIngress);
package/dist/utils.d.ts CHANGED
@@ -156,7 +156,7 @@ export type Switch<T extends string, S> = Record<T, S> | (Partial<{
156
156
  * @param source A method for finding your stat, or class, or whatever X is in this context
157
157
  * @returns A function akin to byStat or byClass; it accepts an object that either is "complete" in the sense that it has a key for every conceivable value, or contains a `default` parameter. If an inappropriate input is provided, returns undefined.
158
158
  */
159
- export declare function makeByXFunction<T extends string>(source: Delayed<T>): <S>(options: Switch<T, S>) => S;
159
+ export declare function makeByXFunction<T extends string>(source: Delayed<T>): <S>(options: Switch<T, S>, alternateSource?: Delayed<T>) => S;
160
160
  /**
161
161
  * Flattens an array. Basically replacing Array.prototype.flat for which Rhino doesn't yet have an implementation
162
162
  *
package/dist/utils.js CHANGED
@@ -221,8 +221,8 @@ export function undelay(delayedObject, ...args) {
221
221
  * @returns A function akin to byStat or byClass; it accepts an object that either is "complete" in the sense that it has a key for every conceivable value, or contains a `default` parameter. If an inappropriate input is provided, returns undefined.
222
222
  */
223
223
  export function makeByXFunction(source) {
224
- return function (options) {
225
- const val = undelay(source);
224
+ return function (options, alternateSource) {
225
+ const val = undelay(alternateSource ?? source);
226
226
  if ("default" in options)
227
227
  return options[val] ?? options.default;
228
228
  return options[val];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "libram",
3
- "version": "0.8.35",
3
+ "version": "0.8.36",
4
4
  "description": "JavaScript helper library for KoLmafia",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",