Skip to content

Commit

Permalink
Change cdn to match .mjs exports, update docs
Browse files Browse the repository at this point in the history
Add docs for Attribute, numericalAnalysis, and Upgrade
  • Loading branch information
xShadowBlade committed Apr 27, 2024
1 parent d75aa93 commit c21ac7e
Show file tree
Hide file tree
Showing 20 changed files with 485 additions and 204 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,17 @@ eMath.js is a JavaScript library designed to provide tools for incremental game

## Abstract

This project started when I was trying to create my first incremental game. I found it difficult to implement certain systems like upgrades and saving. When I eventually made those systems, I wanted to make a package so I could streamline those tools. After a few months of development, I have finally developed it into a presentable state (I should have started it with v0.1.0 instead of v1.0.0).
This project started when I was trying to create my first incremental game. I found it difficult to implement certain systems like upgrades and saving. When I eventually made those systems, I wanted to make a package so I could streamline those tools. After a few months of development, I have finally developed it into a presentable state (I should have started it with v0.1.0 instead of v1.0.0 . . .).

## Example Usage

```js
import { E } from "emath.js";
import { Game } from "emath.js/game";

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

// Initialize game
const coinGame = new Game();

Expand Down
2 changes: 1 addition & 1 deletion dist/game/eMath.game.js
Original file line number Diff line number Diff line change
Expand Up @@ -6145,7 +6145,7 @@ var DataManager = class {
const hasedData = (0, import_md5.default)(`${this.gameRef.config.name.id}/${JSON.stringify(gameDataString)}`);
let version;
try {
version = "8.0.0-rc.2";
version = "8.0.0";
} catch (error) {
version = "8.0.0";
}
Expand Down
2 changes: 1 addition & 1 deletion dist/game/eMath.game.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/game/eMath.game.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -6112,7 +6112,7 @@ var DataManager = class {
const hasedData = (0, import_md5.default)(`${this.gameRef.config.name.id}/${JSON.stringify(gameDataString)}`);
let version;
try {
version = "8.0.0-rc.2";
version = "8.0.0";
} catch (error) {
version = "8.0.0";
}
Expand Down
2 changes: 1 addition & 1 deletion dist/main/eMath.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/pixiGame/eMath.pixiGame.js
Original file line number Diff line number Diff line change
Expand Up @@ -6144,7 +6144,7 @@ var DataManager = class {
const hasedData = (0, import_md5.default)(`${this.gameRef.config.name.id}/${JSON.stringify(gameDataString)}`);
let version;
try {
version = "8.0.0-rc.2";
version = "8.0.0";
} catch (error) {
version = "8.0.0";
}
Expand Down
2 changes: 1 addition & 1 deletion dist/pixiGame/eMath.pixiGame.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -6116,7 +6116,7 @@ var DataManager = class {
const hasedData = (0, import_md5.default)(`${this.gameRef.config.name.id}/${JSON.stringify(gameDataString)}`);
let version;
try {
version = "8.0.0-rc.2";
version = "8.0.0";
} catch (error) {
version = "8.0.0";
}
Expand Down
8 changes: 7 additions & 1 deletion dist/types/E/e.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1298,7 +1298,13 @@ declare const formats: {
formatTimeLong: (ex: DecimalSource, ms?: boolean, acc?: number, max?: number, type?: FormatType) => string;
formatReduction: (ex: DecimalSource) => string;
formatPercent: (ex: DecimalSource) => string;
formatMult: (ex: DecimalSource, acc?: number) => string;
formatMult: (ex: DecimalSource, acc?: number) => string; /**
* Returns true if 'value' is greater than or equal to 'other'.
* However, the two Decimals are considered equal if they're approximately equal up to a certain tolerance.
* Tolerance is a relative tolerance, multiplied by the greater of the magnitudes of the two arguments.
* For example, if you put in 1e-9, then any number closer to the
* larger number than (larger number)*1e-9 will be considered equal.
*/
expMult: (a: DecimalSource, b: DecimalSource, base?: number) => Decimal;
metric: (num: DecimalSource, type?: 0 | 1 | 2 | 3) => string;
ev: (num: DecimalSource, c2?: boolean) => string;
Expand Down
110 changes: 89 additions & 21 deletions dist/types/game/hookGame.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,96 @@
* @file Declares a function that hooks the game to the window object.
*/
import "reflect-metadata";
import { Game } from "./Game";
import { KeyManager } from "./managers/KeyManager";
import { EventManager } from "./managers/EventManager";
import { DataManager } from "./managers/DataManager";
import { eMath } from "../hookMain";
import * as eMathGame from "./index";
declare const eMathGameWeb: {
game: typeof Game;
managers: {
keyManager: typeof KeyManager;
eventManager: typeof EventManager;
dataManager: typeof DataManager;
};
E: ((x?: import("..").ESource | undefined) => import("../E/e").Decimal) & typeof import("../E/e").Decimal;
classes: {
boost: typeof import("..").Boost;
currency: typeof import("..").Currency;
currencyStatic: typeof import("..").CurrencyStatic;
attribute: typeof import("..").Attribute;
grid: typeof import("..").Grid;
gridCell: typeof import("..").GridCell;
Game: typeof eMathGame.Game;
gameDefaultConfig: import("./managers/ConfigManager").RequiredDeep<eMathGame.GameConfigOptions>;
GameCurrency: typeof eMathGame.GameCurrency;
GameAttribute: typeof eMathGame.GameAttribute;
GameReset: typeof eMathGame.GameReset;
KeyManager: typeof eMathGame.KeyManager;
keys: string[];
EventManager: typeof eMathGame.EventManager;
EventTypes: typeof eMathGame.EventTypes;
DataManager: typeof eMathGame.DataManager;
LRUCache: typeof eMath.LRUCache;
ListNode: typeof eMath.ListNode;
E: ((x?: eMath.ESource | undefined) => import("../E/e").Decimal) & typeof import("../E/e").Decimal;
FORMATS: {
omega: {
config: {
greek: string;
infinity: string;
};
format(value: eMath.ESource): string;
};
omega_short: {
config: {
greek: string;
infinity: string;
};
format(value: eMath.ESource): string;
};
elemental: {
config: {
element_lists: string[][];
};
getOffset(group: number): number;
getAbbreviation(group: number, progress: number): string;
beyondOg(x: number): string;
abbreviationLength(group: number): number;
getAbbreviationAndValue(x: import("../E/e").Decimal): (string | import("../E/e").Decimal)[];
formatElementalPart(abbreviation: string, n: import("../E/e").Decimal): string;
format(value: import("../E/e").Decimal, acc?: number): string;
};
old_sc: {
format(ex: eMath.ESource, acc: number): string;
};
eng: {
format(ex: eMath.ESource, acc?: number): string;
};
mixed_sc: {
format(ex: eMath.ESource, acc?: number | undefined, max?: number): string;
};
layer: {
layers: string[];
format(ex: eMath.ESource, acc?: number, max?: number | undefined): string;
};
standard: {
tier1(x: number): string;
tier2(x: number): string;
};
inf: {
format(ex: eMath.ESource, acc?: number | undefined, max?: number | undefined): string;
};
alphabet: {
config: {
alphabet: string;
};
getAbbreviation(ex: eMath.ESource, start?: eMath.ESource, startDouble?: boolean, abbStart?: number): string;
format(ex: eMath.ESource, acc?: number, max?: number, type?: eMath.FormatType, start?: eMath.ESource, startDouble?: boolean, abbStart?: number | undefined): string;
};
};
FormatTypeList: eMath.FormatType[];
Boost: typeof eMath.Boost;
BoostObject: typeof eMath.BoostObject;
UpgradeData: typeof eMath.UpgradeData;
UpgradeStatic: typeof eMath.UpgradeStatic;
calculateUpgrade: typeof eMath.calculateUpgrade;
decimalToJSONString: typeof eMath.decimalToJSONString;
upgradeToCacheNameEL: typeof eMath.upgradeToCacheNameEL;
Currency: typeof eMath.Currency;
CurrencyStatic: typeof eMath.CurrencyStatic;
Attribute: typeof eMath.Attribute;
AttributeStatic: typeof eMath.AttributeStatic;
GridCell: typeof eMath.GridCell;
Grid: typeof eMath.Grid;
inverseFunctionApprox: typeof eMath.inverseFunctionApprox;
calculateSumLoop: typeof eMath.calculateSumLoop;
calculateSumApprox: typeof eMath.calculateSumApprox;
calculateSum: typeof eMath.calculateSum;
roundingBase: typeof eMath.roundingBase;
DEFAULT_ITERATIONS: 25;
};
/**
* Hooks the game to the window object.
*/
export { eMathGameWeb as eMath };
41 changes: 1 addition & 40 deletions dist/types/hookMain.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,43 +2,4 @@
* @file Declares a function that hooks the game to the window object.
*/
import "reflect-metadata";
import { Boost } from "./classes/Boost";
import { Currency, CurrencyStatic } from "./classes/Currency";
import { Attribute } from "./classes/Attribute";
import { Grid, GridCell } from "./classes/Grid";
declare const eMathWeb: {
/**
* @deprecated Use `import { E } from "emath.js"` instead.
*/
E: ((x?: import("./E/e").DecimalSource | undefined) => import("./E/e").Decimal) & typeof import("./E/e").Decimal;
classes: {
/**
* @deprecated Use `import { boost } from "emath.js"` instead.
*/
boost: typeof Boost;
/**
* @deprecated Use `import { currency } from "emath.js"` instead.
*/
currency: typeof Currency;
/**
* @deprecated Use `import { currencyStatic } from "emath.js"` instead.
*/
currencyStatic: typeof CurrencyStatic;
/**
* @deprecated Use `import { attribute } from "emath.js"` instead.
*/
attribute: typeof Attribute;
/**
* @deprecated Use `import { grid } from "emath.js"` instead.
*/
grid: typeof Grid;
/**
* @deprecated Use `import { gridCell } from "emath.js"` instead.
*/
gridCell: typeof GridCell;
};
};
/**
* Attach eMath to the window object
*/
export { eMathWeb as eMath };
export * as eMath from "./index";
13 changes: 10 additions & 3 deletions documentation/docs/game/game-class.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
id: game
id: game-class
title: Game
sidebar_label: Game
---
Expand Down Expand Up @@ -35,14 +35,21 @@ There are various managers/methods. Here are some examples:
import { myGame } from "./game.js";

// See <GameCurrency>
const myCurrency = myGame.add
const myCurrency = myGame.addCurrency("myCurrency");

// See <EventManager>
myGame.eventManager.addEvent("IntervalEvent", "interval", 2000, () => {
console.log("Interval event that is executed every two seconds.");
});

// See <KeyManager>
myGame.keyManager.addKey([
{
name: "Gain Coins",
key: "g",
onDownContinuous: () => myCurrency.static.gain(),
},
]);
```

For for information on constructor parameters, see the interface [`GameConfigOptions`](https://xshadowblade.github.io/emath.js/typedoc/interfaces/game_Game.GameConfigOptions.html).
For for information on constructor parameters, see the interface [`GameConfigOptions`](https://xshadowblade.github.io/emath.js/typedoc/interfaces/game_Game.GameConfigOptions.html).
28 changes: 28 additions & 0 deletions documentation/docs/main/attribute.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
---
id: attribute
title: Attribute
sidebar_label: Attribute
---

[Link to auto generated docs](https://xshadowblade.github.io/emath.js/typedoc/classes/classes_Attribute.AttributeStatic.html)

The `Attribute` class represents an attribute that can be affected by boosts. It is essentially a wrapper around the `Boost` class, and is used to store the value of the attribute and apply boosts to it.

## Usage

To create an attribute, use the `AttributeStatic` class:

```js title="attribute.js"
import { AttributeStatic } from "emath.js";

// Create a new attribute with an initial value of 100
const health = new AttributeStatic(100);

// Set a health boost that multiplies the health by 1.1 (See <Boost> for more information)
health.boost.setBoost({
id: "healthBoost",
value: (e) => e.mul(1.1),
});

console.log(health.value); // 110
```
2 changes: 1 addition & 1 deletion documentation/docs/main/boost.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
id: boost
title: Boost Guide
title: Boost
sidebar_label: Boost
---

Expand Down
10 changes: 6 additions & 4 deletions documentation/docs/main/currency.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
id: currency
title: Currency Guide
title: Currency
sidebar_label: Currency
---

Expand All @@ -16,8 +16,8 @@ To create a currency, do either of the following:

1. Using `Game` class (recommended)

```js
// myGame: Game
```js title="currency.js"
import { myGame } from "./game.js";

// 1 parameter - `name` is required. It must be unique,
// as it is used for saving/loading to identify the currnecy.
Expand All @@ -31,7 +31,9 @@ To create a currency, do either of the following:

2. Using without `Game` class

```js
```js title="currency.js"
import { CurrencyStatic } from "emath.js";
const myCurrency = new CurrencyStatic();
myCurrency.gain();
console.log(myCurrency.value); // E(1)
Expand Down
9 changes: 4 additions & 5 deletions documentation/docs/main/main.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,13 @@ title: Main
sidebar_label: Main
---

This category lists the primary exports of the package `emath.js`
This category lists the primary exports of the package `emath.js`.

## Table of Contents

- Attribute (work in progress)
- [Attribute](./attribute)
- [Boost](./boost)
- [Currency](./currency)
- Grid (work in progress)
- Numerical Analysis (work in progress)
- SkillTree (work in progress, unfinished)
- Upgrade (work in progress)
- [Numerical Analysis](./numerical-analysis)
- [Upgrade](./upgrade)
Loading

0 comments on commit c21ac7e

Please sign in to comment.