Skip to content

Commit

Permalink
Fix various types
Browse files Browse the repository at this point in the history
  • Loading branch information
xShadowBlade committed May 7, 2024
1 parent 8950164 commit d75e7a5
Show file tree
Hide file tree
Showing 11 changed files with 37 additions and 24 deletions.
6 changes: 4 additions & 2 deletions dist/game/eMath.game.js
Original file line number Diff line number Diff line change
Expand Up @@ -7031,20 +7031,22 @@ var Game = class _Game {
* Adds a new currency section to the game. {@link GameCurrency} is the class.
* It automatically adds the currency and currencyStatic objects to the data and static objects for saving and loading.
* @template N - The name
* @template U - The upgrade names for the currency. See {@link CurrencyStatic} for more information.
* @param name - The name of the currency section. This is also the name of the data and static objects, so it must be unique.
* @param upgrades - The upgrades for the currency.
* @returns A new instance of the gameCurrency class.
* @example
* const currency = game.addCurrency("currency");
* currency.static.gain();
* console.log(currency.value); // E(1)
*/
addCurrency(name) {
addCurrency(name, upgrades = []) {
this.dataManager.setData(name, {
currency: new Currency()
});
this.dataManager.setStatic(name, {
// @ts-expect-error - fix this
currency: new CurrencyStatic(() => this.dataManager.getData(name).currency)
currency: new CurrencyStatic(() => this.dataManager.getData(name).currency, upgrades)
// attributes: {},
});
const classInstance = new GameCurrency(() => this.dataManager.getData(name).currency, () => this.dataManager.getStatic(name).currency, this, name);
Expand Down
2 changes: 1 addition & 1 deletion dist/game/eMath.game.min.js

Large diffs are not rendered by default.

6 changes: 4 additions & 2 deletions dist/game/eMath.game.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -6997,20 +6997,22 @@ var Game = class _Game {
* Adds a new currency section to the game. {@link GameCurrency} is the class.
* It automatically adds the currency and currencyStatic objects to the data and static objects for saving and loading.
* @template N - The name
* @template U - The upgrade names for the currency. See {@link CurrencyStatic} for more information.
* @param name - The name of the currency section. This is also the name of the data and static objects, so it must be unique.
* @param upgrades - The upgrades for the currency.
* @returns A new instance of the gameCurrency class.
* @example
* const currency = game.addCurrency("currency");
* currency.static.gain();
* console.log(currency.value); // E(1)
*/
addCurrency(name) {
addCurrency(name, upgrades = []) {
this.dataManager.setData(name, {
currency: new Currency()
});
this.dataManager.setStatic(name, {
// @ts-expect-error - fix this
currency: new CurrencyStatic(() => this.dataManager.getData(name).currency)
currency: new CurrencyStatic(() => this.dataManager.getData(name).currency, upgrades)
// attributes: {},
});
const classInstance = new GameCurrency(() => this.dataManager.getData(name).currency, () => this.dataManager.getStatic(name).currency, this, name);
Expand Down
6 changes: 4 additions & 2 deletions dist/pixiGame/eMath.pixiGame.js
Original file line number Diff line number Diff line change
Expand Up @@ -7029,20 +7029,22 @@ var Game = class _Game {
* Adds a new currency section to the game. {@link GameCurrency} is the class.
* It automatically adds the currency and currencyStatic objects to the data and static objects for saving and loading.
* @template N - The name
* @template U - The upgrade names for the currency. See {@link CurrencyStatic} for more information.
* @param name - The name of the currency section. This is also the name of the data and static objects, so it must be unique.
* @param upgrades - The upgrades for the currency.
* @returns A new instance of the gameCurrency class.
* @example
* const currency = game.addCurrency("currency");
* currency.static.gain();
* console.log(currency.value); // E(1)
*/
addCurrency(name) {
addCurrency(name, upgrades = []) {
this.dataManager.setData(name, {
currency: new Currency()
});
this.dataManager.setStatic(name, {
// @ts-expect-error - fix this
currency: new CurrencyStatic(() => this.dataManager.getData(name).currency)
currency: new CurrencyStatic(() => this.dataManager.getData(name).currency, upgrades)
// attributes: {},
});
const classInstance = new GameCurrency(() => this.dataManager.getData(name).currency, () => this.dataManager.getStatic(name).currency, this, name);
Expand Down
6 changes: 4 additions & 2 deletions dist/pixiGame/eMath.pixiGame.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -7001,20 +7001,22 @@ var Game = class _Game {
* Adds a new currency section to the game. {@link GameCurrency} is the class.
* It automatically adds the currency and currencyStatic objects to the data and static objects for saving and loading.
* @template N - The name
* @template U - The upgrade names for the currency. See {@link CurrencyStatic} for more information.
* @param name - The name of the currency section. This is also the name of the data and static objects, so it must be unique.
* @param upgrades - The upgrades for the currency.
* @returns A new instance of the gameCurrency class.
* @example
* const currency = game.addCurrency("currency");
* currency.static.gain();
* console.log(currency.value); // E(1)
*/
addCurrency(name) {
addCurrency(name, upgrades = []) {
this.dataManager.setData(name, {
currency: new Currency()
});
this.dataManager.setStatic(name, {
// @ts-expect-error - fix this
currency: new CurrencyStatic(() => this.dataManager.getData(name).currency)
currency: new CurrencyStatic(() => this.dataManager.getData(name).currency, upgrades)
// attributes: {},
});
const classInstance = new GameCurrency(() => this.dataManager.getData(name).currency, () => this.dataManager.getStatic(name).currency, this, name);
Expand Down
3 changes: 3 additions & 0 deletions dist/types/classes/Attribute.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ declare class Attribute {
}
/**
* Represents a static attribute, which is number that can affected by boosts.
*
* Note: This class is essentially a wrapper around {@link Boost}, and if you choose not to use boosts, you can use {@link Decimal} directly.
* It may be marked as deprecated in the future.
* @template B - Indicates whether the boost is enabled. Defaults to true.
* @example
* const health = new AttributeStatic(undefined, true, 100); // AttributeStatic<true>
Expand Down
2 changes: 1 addition & 1 deletion dist/types/classes/Currency.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { UpgradeData, UpgradeStatic, UpgradeInit } from "./Upgrade";
* IsPrimitiveString<"asdf">; // false
* IsPrimitiveString<number>; // false
*/
type IsPrimitiveString<T> = "" & T extends "random string that no one should ever get randomly" ? false : true;
type IsPrimitiveString<T> = "random string that no one should ever get randomly" & T extends "" ? false : true;
/**
* Represents the frontend READONLY for a currency. Useful for saving / data management.
* Note: This class is created by default when creating a {@link CurrencyStatic} class. Use that instead as there are no methods here.
Expand Down
6 changes: 4 additions & 2 deletions dist/types/game/Game.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,16 @@ declare class Game {
* Adds a new currency section to the game. {@link GameCurrency} is the class.
* It automatically adds the currency and currencyStatic objects to the data and static objects for saving and loading.
* @template N - The name
* @template U - The upgrade names for the currency. See {@link CurrencyStatic} for more information.
* @param name - The name of the currency section. This is also the name of the data and static objects, so it must be unique.
* @param upgrades - The upgrades for the currency.
* @returns A new instance of the gameCurrency class.
* @example
* const currency = game.addCurrency("currency");
* currency.static.gain();
* console.log(currency.value); // E(1)
*/
addCurrency<N extends string>(name: N): GameCurrency<N>;
addCurrency<N extends string, U extends string[] = string[]>(name: N, upgrades?: U): GameCurrency<N, U>;
/**
* Adds a new attribute to the game. {@link GameAttribute} is the class.
* It automatically adds the attribute and attributeStatic objects to the data and static objects for saving and loading.
Expand All @@ -103,7 +105,7 @@ declare class Game {
* @example
* const myAttribute = game.addAttribute("myAttribute");
*/
addAttribute(name: string, useBoost?: boolean, initial?: ESource): GameAttribute;
addAttribute<B extends boolean = true>(name: string, useBoost?: B, initial?: ESource): GameAttribute<B>;
/**
* Creates a new game reset object with the specified currencies to reset.
* @param currenciesToReset - The currencies to reset.
Expand Down
3 changes: 3 additions & 0 deletions src/classes/Attribute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ class Attribute {

/**
* Represents a static attribute, which is number that can affected by boosts.
*
* Note: This class is essentially a wrapper around {@link Boost}, and if you choose not to use boosts, you can use {@link Decimal} directly.
* It may be marked as deprecated in the future.
* @template B - Indicates whether the boost is enabled. Defaults to true.
* @example
* const health = new AttributeStatic(undefined, true, 100); // AttributeStatic<true>
Expand Down
3 changes: 1 addition & 2 deletions src/classes/Currency.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ import { UpgradeData, UpgradeStatic, UpgradeInit, calculateUpgrade } from "./Upg
* IsPrimitiveString<"asdf">; // false
* IsPrimitiveString<number>; // false
*/
type IsPrimitiveString<T> = "" & T extends "random string that no one should ever get randomly" ? false : true;

type IsPrimitiveString<T> = "random string that no one should ever get randomly" & T extends "" ? false : true;

/**
* Represents the frontend READONLY for a currency. Useful for saving / data management.
Expand Down
18 changes: 8 additions & 10 deletions src/game/Game.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,25 +132,27 @@ class Game {
* Adds a new currency section to the game. {@link GameCurrency} is the class.
* It automatically adds the currency and currencyStatic objects to the data and static objects for saving and loading.
* @template N - The name
* @template U - The upgrade names for the currency. See {@link CurrencyStatic} for more information.
* @param name - The name of the currency section. This is also the name of the data and static objects, so it must be unique.
* @param upgrades - The upgrades for the currency.
* @returns A new instance of the gameCurrency class.
* @example
* const currency = game.addCurrency("currency");
* currency.static.gain();
* console.log(currency.value); // E(1)
*/
public addCurrency<N extends string> (name: N): GameCurrency<N> {
public addCurrency<N extends string, U extends string[] = string[]> (name: N, upgrades: U = [] as unknown as U): GameCurrency<N, U> {
this.dataManager.setData(name, {
currency: new Currency(),
});
this.dataManager.setStatic(name, {
// @ts-expect-error - fix this
currency: new CurrencyStatic(() => this.dataManager.getData(name).currency as Currency),
currency: new CurrencyStatic(() => this.dataManager.getData(name).currency as Currency, upgrades),
// attributes: {},
});

// @ts-expect-error - fix this
const classInstance = new GameCurrency(() => this.dataManager.getData(name).currency as Currency, () => this.dataManager.getStatic(name).currency as Currency, this, name);
const classInstance = new GameCurrency(() => this.dataManager.getData(name).currency as Currency, () => this.dataManager.getStatic(name).currency as CurrencyStatic<U>, this, name);


// const dataRef = this.dataManager.setData(name, {
Expand All @@ -173,16 +175,12 @@ class Game {
* @example
* const myAttribute = game.addAttribute("myAttribute");
*/
public addAttribute (name: string, useBoost = true, initial: ESource = 0): GameAttribute {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
public addAttribute<B extends boolean = true> (name: string, useBoost: B = true as B, initial: ESource = 0): GameAttribute<B> {
const dataRef = this.dataManager.setData(name, new Attribute(initial));
// @ts-expect-error - fix this
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const staticRef = this.dataManager.setStatic(name, new AttributeStatic(this.dataManager.getData(name), useBoost, initial));
const staticRef = this.dataManager.setStatic(name, new AttributeStatic(this.dataManager.getData(name) as Attribute, useBoost, initial));
// const staticRef = this.dataManager.setStatic(name, new attributeStatic(dataRef, useBoost, initial));

// @ts-expect-error - fix this
const classInstance = new GameAttribute(this.dataManager.getData(name), this.dataManager.getStatic(name), this);
const classInstance = new GameAttribute(this.dataManager.getData(name) as Attribute, this.dataManager.getStatic(name) as AttributeStatic<B>, this);
// const classInstance = new gameAttribute(() => dataRef as attribute, () => staticRef as attributeStatic, this);
return classInstance;
}
Expand Down

0 comments on commit d75e7a5

Please sign in to comment.