Skip to content

Commit

Permalink
Change docs from E to Decimal
Browse files Browse the repository at this point in the history
  • Loading branch information
xShadowBlade committed Jun 7, 2024
1 parent 8082040 commit c0edd7c
Show file tree
Hide file tree
Showing 11 changed files with 57 additions and 50 deletions.
4 changes: 2 additions & 2 deletions documentation/docs/install.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ You can install ``eMath.js`` via [npm](#install-via-npm-recommended) or include

> Note: For advanced usage, using npm and Node.js is prefered.
> Warning: HTML CDN as well as nodejs(?) is possibly bugged, causing unexpected behavior when working with the E instance. Typescript usage is prefered.
> Warning: HTML CDN as well as nodejs(?) is possibly bugged, causing unexpected behavior when working with the Decimal instance. Typescript usage is prefered.
### Install via npm (recommended)

Expand All @@ -26,7 +26,7 @@ import { Boost, Currency } from "emath.js";
import { Game } from "emath.js";
```

> Warning (experimental): If you are using typescript with webpack, you could import from ``"emath.js/ts"``, ``"emath.js/ts/game"``, or ``"emath.js/ts/pixiGame"`` and compile from source instead. This fixes a bug that causes unexpected behavior when working with the E instance.
> Warning (experimental): If you are using typescript with webpack, you could import from ``"emath.js/ts"``, ``"emath.js/ts/game"``, or ``"emath.js/ts/pixiGame"`` and compile from source instead. This fixes a bug that causes unexpected behavior when working with the Decimal instance.
### Include using CDN

Expand Down
2 changes: 1 addition & 1 deletion documentation/docs/main/boost.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,5 @@ myBoost.setBoost({
value: (input) => input.mul(2),
});

console.log(myBoost.calculate()); // E(2)
console.log(myBoost.calculate()); // new Decimal(2)
```
4 changes: 2 additions & 2 deletions documentation/docs/main/currency.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ To create a currency, do either of the following:
// All the methods are in `<GameCurrency>.static`, which contains the same methods as <CurrencyStatic>
myCurrency.static.gain();

console.log(myCurrency.static.value); // E(1)
console.log(myCurrency.static.value); // new Decimal(1)
```

2. Using without `Game` class
Expand All @@ -36,5 +36,5 @@ To create a currency, do either of the following:
const myCurrency = new CurrencyStatic();
myCurrency.gain();
console.log(myCurrency.value); // E(1)
console.log(myCurrency.value); // new Decimal(1)
```
44 changes: 22 additions & 22 deletions documentation/docs/main/upgrade.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ sidebar_label: Upgrade
* @param mode - The mode/mean method to use. See {@link MeanMode}
* @param iterations - The amount of iterations to perform. Defaults to `15`.
* @param el - ie Endless: Flag to exclude the sum calculation and only perform binary search. (DEPRECATED, use `el` in the upgrade object instead)
* @returns [amount, cost] - Returns the amount of upgrades you can buy and the cost of the upgrades. If you can't afford any, it returns [E(0), E(0)].
* @returns [amount, cost] - Returns the amount of upgrades you can buy and the cost of the upgrades. If you can't afford any, it returns [new Decimal(0), new Decimal(0)].
*/
declare function calculateUpgrade(value: ESource, upgrade: UpgradeStatic<string>, start?: ESource, end?: ESource, mode?: MeanMode, iterations?: number, el?: boolean): [amount: E, cost: E];
declare function calculateUpgrade(value: DecimalSource, upgrade: UpgradeStatic<string>, start?: DecimalSource, end?: DecimalSource, mode?: MeanMode, iterations?: number, el?: boolean): [amount: Decimal, cost: Decimal];
/**
* Interface for initializing an upgrade.
* @template N - The ID of the upgrade.
Expand Down Expand Up @@ -60,32 +60,32 @@ interface UpgradeInit<N extends string = string> {
* // A cost function that returns twice the level.
* (level) => level.mul(2)
*/
cost: (level: E) => E;
cost: (level: Decimal) => Decimal;
/**
* The cost of buying a bulk of upgrades at a certain level. (inverse of cost function).
* EL is automatically applied to the cost.
* WARNING: In v8.x.x and above, the return order is [amount, cost] instead of [cost, amount].
* @param level - The current level of the upgrade.
* @param target - The target level of the upgrade.
* @returns [cost, amount] - The cost of the upgrades and the amount of upgrades you can buy. If you can't afford any, it returns [E(0), E(0)].
* @returns [cost, amount] - The cost of the upgrades and the amount of upgrades you can buy. If you can't afford any, it returns [new Decimal(0), new Decimal(0)].
* @example
* // A cost function that returns the sum of the levels and the target.
* // In this example, the cost function is twice the level. The cost bulk function is the sum of the levels and the target.
* // -target^2 + target + level^2 + level
* (level, target) => target.pow(2).mul(-1).add(target).add(level.pow(2)).add(level)
*/
costBulk?: (currencyValue: E, level: E, target: E) => [amount: E, cost: E];
costBulk?: (currencyValue: Decimal, level: Decimal, target: Decimal) => [amount: Decimal, cost: Decimal];
/**
* The maximum level of the upgrade.
* Warning: If not set, the upgrade will not have a maximum level and can continue to increase indefinitely.
*/
maxLevel?: E;
maxLevel?: Decimal;
/**
* The effect of the upgrade. This runs when the upgrade is bought, and instantly if `runEffectInstantly` is true.
* @param level - The current level of the upgrade.
* @param context - The upgrade object.
*/
effect?: (level: E, context: UpgradeStatic<N>) => void;
effect?: (level: Decimal, context: UpgradeStatic<N>) => void;
/**
* Endless / Everlasting: Flag to exclude the sum calculation and only perform binary search.
* Note: A function value is also allowed, and will be evaluated when the upgrade is bought or calculated.
Expand All @@ -96,14 +96,14 @@ interface UpgradeInit<N extends string = string> {
* The default level of the upgrade.
* Automatically set to `1` if not provided.
*/
level?: E;
level?: Decimal;
}
/**
* Interface for an upgrade.
* @template N - The ID of the upgrade. See {@link UpgradeInit}
*/
interface IUpgradeStatic<N extends string = string> extends Omit<UpgradeInit<N>, "level"> {
maxLevel?: E;
maxLevel?: Decimal;
name: string;
description: string;
/**
Expand Down Expand Up @@ -142,14 +142,14 @@ type UpgradeCachedSumName = `sum/${DecimalJSONString}/${DecimalJSONString}`;
* @param n - The decimal number to convert.
* @returns The decimal number in the form of a string. `sign/mag/layer` See {@link DecimalJSONString}
*/
declare function decimalToJSONString(n: ESource): DecimalJSONString;
declare function decimalToJSONString(n: DecimalSource): DecimalJSONString;
/**
* Converts an upgrade to a cache name (EL)
* @deprecated Use an object index instead.
* @param level - The level of the upgrade.
* @returns The name of the upgrade (EL) that is cached. See {@link UpgradeCachedELName}
*/
declare function upgradeToCacheNameEL(level: ESource): UpgradeCachedELName;
declare function upgradeToCacheNameEL(level: DecimalSource): UpgradeCachedELName;
/**
* Interface for an upgrade that is cached.
* @template EL - Whether the upgrade is EL or not.
Expand All @@ -159,18 +159,18 @@ interface UpgradeCached<EL extends boolean = false> extends Pick<UpgradeInit, "i
}
/** Interface for an upgrade that is cached. (EL) */
interface UpgradeCachedEL extends UpgradeCached<true>, Pick<UpgradeInit, "level"> {
level: E;
level: Decimal;
/** The cost of the upgrade at level (el) */
cost: E;
cost: Decimal;
}
/** Interface for an upgrade that is cached. (Not EL) */
interface UpgradeCachedSum extends UpgradeCached<false> {
start: E;
end: E;
start: Decimal;
end: Decimal;
/**
* The cost of the upgrade from start to end. (summation)
*/
cost: E;
cost: Decimal;
}
/**
* Represents the frontend for an upgrade.
Expand Down Expand Up @@ -211,8 +211,8 @@ declare class UpgradeStatic<N extends string = string> implements IUpgradeStatic
* The current level of the upgrade.
* @returns The current level of the upgrade.
*/
get level(): E;
set level(n: ESource);
get level(): Decimal;
set level(n: DecimalSource);
/**
* Constructs a new static upgrade object.
* @param init - The upgrade object to initialize.
Expand All @@ -227,17 +227,17 @@ declare class UpgradeStatic<N extends string = string> implements IUpgradeStatic
* @param end - The ending level or quantity to reach for the upgrade.
* @returns The data of the upgrade.
*/
getCached(type: "sum", start: ESource, end: ESource): UpgradeCachedSum | undefined;
getCached(type: "el", start: ESource): UpgradeCachedEL | undefined;
getCached(type: "sum", start: DecimalSource, end: DecimalSource): UpgradeCachedSum | undefined;
getCached(type: "el", start: DecimalSource): UpgradeCachedEL | undefined;
/**
* Sets the cached data of the upgrade.
* @param type - The type of the cache. "sum" or "el"
* @param start - The starting level of the upgrade.
* @param end - The ending level or quantity to reach for the upgrade.
* @param cost - The cost of the upgrade.
*/
setCached(type: "sum", start: ESource, end: ESource, cost: ESource): UpgradeCachedSum;
setCached(type: "el", level: ESource, cost: ESource): UpgradeCachedEL;
setCached(type: "sum", start: DecimalSource, end: DecimalSource, cost: DecimalSource): UpgradeCachedSum;
setCached(type: "el", level: DecimalSource, cost: DecimalSource): UpgradeCachedEL;
}
-->

Expand Down
17 changes: 12 additions & 5 deletions documentation/docs/migration/from-8-to-9.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,25 @@ Version 9 of eMath.js will release with a few changes. This guide will help you

The following changes have been made in version 9:
- Change from `E` to `Decimal` class from break_eternity.js
{/* - `E` class has been removed and replaced with `Decimal` class from `break_eternity.js`. */}
- `ESource` type has been renamed to `DecimalSource`, however you should import it from `break_eternity.js`
- Change from `ESource` type to `DecimalSource` type

You should still import from `"emath.js"` instead of `"break_eternity.js"`, but the `Decimal` class is now used instead of the `E` class.

{/* ## Change from `E` to `Decimal` class
In version 9, the `E` class has been removed and replaced with the `Decimal` class from `break_eternity.js`. You should import the `Decimal` class from `break_eternity.js` and use it instead of the `E` class. */}

## Change from `ESource` to `DecimalSource`

In version 9, the `ESource` type has been renamed to `DecimalSource`. You should import it from `break_eternity.js` and use it instead of `ESource`.
In version 9, the `ESource` type has been renamed to `DecimalSource`.

```ts title="script.ts"
import { DecimalSource } from "break_eternity.js";
import { DecimalSource } from "emath.js";
```

### Change from `E` to `Decimal`

In version 9, the `E` class has been removed and replaced with the `Decimal` class from `break_eternity.js`. You should still import the `Decimal` class from `emath.js` and use it instead of the `E` class.
In version 9, the `E` class has been removed and replaced with the `Decimal` class from `break_eternity.js`.

```ts title="script.ts"
// Before (v8)
Expand All @@ -47,10 +48,14 @@ const number = new Decimal(10);
const result = Decimal.add(number, new Decimal(5));
```

You could still use the `E` function, but it is deprecated and will be removed in future versions.

### Regexes

Here are some regexes that you can use to replace the `E` class with the `Decimal` class in your code:

(Tip: In VSCode you can use the `Ctrl + Shift + H` shortcut to open the search and replace panel for all files, then click the `.*` button to enable regex mode)

Search:

```regex
Expand Down Expand Up @@ -79,6 +84,8 @@ new Decimal($1)

---

(you should be careful with this one, as it might replace other instances of `E` that are not the `E` class)

Search:

```regex
Expand Down
4 changes: 2 additions & 2 deletions documentation/docs/tutorials/coinGame/code/script.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Note: This is a simple example, and you should npm with typescript for a better development experience
// Import from CDN
const { E, Game } = window.eMath;
const { Decimal, Game } = window.eMath;

// Initialize game with options
const gameOptions = {
Expand All @@ -21,7 +21,7 @@ const coinUpgrades = [
{
id: "upg1Coins", // Unique ID
cost: level => level.mul(10), // Cost of 10 times the level
maxLevel: E(1000),
maxLevel: new Decimal(1000),
effect: (level, upgradeContext, currencyContext) => {
// `currencyContext` is the context of the currency (coins in this case)

Expand Down
10 changes: 5 additions & 5 deletions documentation/docs/tutorials/coinGame/code/script.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
* @file Coin Game tutorial code (typescript)
*/
// Import from CDN
// const { E, Game } = window.eMath;
// const { Decimal, Game } = window.eMath;

// Import from NPM
// import { E } from "emath.js";
// import { Decimal } from "emath.js";
// import { Game } from "emath.js/game";

// Import from local build
// [projectRoot]/src/index is `emath.js`, [projectRoot]/src/game/index is `emath.js/game`
import { E } from "../../../../../src/index";
import { Decimal } from "../../../../../src/index";
import { Game } from "../../../../../src/game/index";
import type { UpgradeInit } from "../../../../../src/index";
import type { GameConfigOptions } from "../../../../../src/game/index";
Expand All @@ -33,8 +33,8 @@ const coinGame = new Game(gameOptions);
const coinUpgrades = [
{
id: "upg1Coins", // Unique ID
cost: (level): E => level.mul(10), // Cost of 10 times the level
maxLevel: E(1000), // Maximum level of 1000
cost: (level): Decimal => level.mul(10), // Cost of 10 times the level
maxLevel: new Decimal(1000), // Maximum level of 1000
effect: (level, upgradeContext, currencyContext): void => {
// `currencyContext` is the context of the currency (coins in this case)

Expand Down
6 changes: 3 additions & 3 deletions documentation/docs/tutorials/coinGame/currency.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const coinUpgrades = [
{
id: "upg1Coins", // Unique ID
cost: level => level.mul(10), // Cost of 10 times the level
maxLevel: E(1000),
maxLevel: new Decimal(1000),
effect: (level, upgradeContext, currencyContext) => {
// `currencyContext` is the context of the currency (coins in this case)

Expand All @@ -49,8 +49,8 @@ const coins = coinGame.addCurrency("coins", coinUpgrades);
const coinUpgrades = [
{
id: "upg1Coins", // Unique ID
cost: (level): E => level.mul(10), // Cost of 10 times the level
maxLevel: E(1000), // Maximum level of 1000
cost: (level): Decimal => level.mul(10), // Cost of 10 times the level
maxLevel: new Decimal(1000), // Maximum level of 1000
effect: (level, upgradeContext, currencyContext): void => {
// `currencyContext` is the context of the currency (coins in this case)

Expand Down
4 changes: 2 additions & 2 deletions documentation/docs/tutorials/coinGame/game.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ After you have set up the basics, now it's time to set up the game.
<Tabs groupId="jsOrTs" defaultValue="js" values={[{label: 'JavaScript', value: 'js'},{label: 'TypeScript', value: 'ts'}]}>
<TabItem value="js">
```js title="script.js"
const { E, Game } = window.eMath;
const { Decimal, Game } = window.eMath;

// Initialize game with options
const gameOptions = {
Expand All @@ -32,7 +32,7 @@ const coinGame = new Game(gameOptions);
</TabItem>
<TabItem value="ts">
```ts title="script.ts"
import { E } from "emath.js";
import { Decimal } from "emath.js";
import { Game } from "emath.js/game";

// Initialize game with options
Expand Down
4 changes: 2 additions & 2 deletions documentation/docs/tutorials/coinGame/setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ This code sets up the project and imports ``emath.js/game`` using jsDelivr. Alte
Now, create a js file named ``script.js`` and put the following code in it:

```js title="script.js"
const { E, Game } = window.eMath;
const { Decimal, Game } = window.eMath;
```

This code extracts and imports the ``E`` and ``Game`` classes from the ``eMath`` object. These classes are used to create the game.
This code extracts and imports the ``Decimal`` and ``Game`` classes from the ``eMath`` object. These classes are used to create the game.

### NodeJS setup

Expand Down
8 changes: 4 additions & 4 deletions documentation/docs/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ There are also corresponding typescript versions of those packages (`emath.js/ts
Here is an example usage:

```js title="index.js"
import { E } from "emath.js";
import { Decimal } from "emath.js";
import { Game } from "emath.js/game";

// For CDN usage:
// const { E, Game } = eMath;
// const { Decimal, Game } = eMath;

// Initialize game
const coinGame = new Game();
Expand All @@ -31,7 +31,7 @@ const coins = coinGame.addCurrency("coins", [
{
id: "upg1Coins", // Unique ID
cost: level => level.mul(10), // Cost of 10 times the level
maxLevel: E(1000),
maxLevel: new Decimal(1000),
effect: (level, upgradeContext, currencyContext) => {
// `currencyContext` is the context of the currency (coins in this case)

Expand Down Expand Up @@ -93,7 +93,7 @@ The package exports a variable ``eMath`` and sets it to the window, so you don't
This will set the `eMath` variable to the `window` object. You can then use it as follows:

```js title="index.js"
const { E, Currency, Game } = eMath;
const { Decimal, Currency, Game } = eMath;

// rest of code here ...
```
Expand Down

0 comments on commit c0edd7c

Please sign in to comment.