Skip to content

Commit

Permalink
imp: Ready for v2.0.0-rc.1.
Browse files Browse the repository at this point in the history
  • Loading branch information
Byloth committed Aug 30, 2024
1 parent 7080e2c commit 57af8c0
Show file tree
Hide file tree
Showing 10 changed files with 236 additions and 207 deletions.
16 changes: 8 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@byloth/core",
"version": "1.5.3",
"version": "2.0.0-rc.1",
"description": "An unopinionated collection of useful functions and classes that I use widely in all my projects. 🔧",
"keywords": [
"Core",
Expand Down Expand Up @@ -56,14 +56,14 @@
"ci": "pnpm install --frozen-lockfile"
},
"devDependencies": {
"@byloth/eslint-config-typescript": "^2.8.1",
"@types/node": "^20.14.11",
"@typescript-eslint/eslint-plugin": "^7.16.1",
"@typescript-eslint/parser": "^7.16.1",
"@byloth/eslint-config-typescript": "^2.8.2",
"@types/node": "^20.16.2",
"@typescript-eslint/eslint-plugin": "^7.18.0",
"@typescript-eslint/parser": "^7.18.0",
"eslint": "^8.57.0",
"husky": "^9.1.1",
"typescript": "^5.5.3",
"vite": "^5.3.4"
"husky": "^9.1.5",
"typescript": "^5.5.4",
"vite": "^5.4.2"
},
"packageManager": "[email protected]+sha512.ee7b93e0c2bd11409c6424f92b866f31d3ea1bef5fbe47d3c7500cdc3c9668833d2e55681ad66df5b640c61fa9dc25d546efa54d76d7f8bf54b13614ac293631"
}
375 changes: 189 additions & 186 deletions pnpm-lock.yaml

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export const VERSION = "1.5.3";
export const VERSION = "2.0.0-rc.1";

export type { Constructor, Interval, Timeout } from "./core/types.js";

Expand All @@ -17,6 +17,7 @@ export {
FileException,
FileExistsException,
FileNotFoundException,
GameLoop,
JSONStorage,
KeyException,
NotImplementedException,
Expand Down
4 changes: 2 additions & 2 deletions src/models/aggregators/reduced-iterator.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { TypeException } from "../exceptions/index.js";
import { ValueException } from "../exceptions/index.js";
import { SmartIterator } from "../iterators/index.js";
import type { GeneratorFunction } from "../iterators/types.js";

Expand Down Expand Up @@ -62,7 +62,7 @@ export default class ReducedIterator<K extends PropertyKey, T>
const firstElement = this._elements.next();
if (firstElement.done)
{
throw new TypeException("Reduce of empty iterator with no initial value");
throw new ValueException("Cannot reduce an empty iterator without an initial value.");
}

index += 1;
Expand Down
8 changes: 5 additions & 3 deletions src/models/game-loop.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { isBrowser } from "../helpers.js";
import { TimeUnit } from "../utils/date.js";

import { FatalErrorException, RuntimeException } from "./exceptions/index.js";

export default class GameLoop
{
protected _handle?: number;
Expand Down Expand Up @@ -62,7 +64,7 @@ export default class GameLoop

public start(elapsedTime = 0): void
{
if (this._isRunning) { return; }
if (this._isRunning) { throw new RuntimeException("The game loop has already been started."); }

this._startTime = performance.now() - elapsedTime;
this._start();
Expand All @@ -71,8 +73,8 @@ export default class GameLoop

public stop(): void
{
if (!(this._isRunning)) { return; }
if (!(this._handle)) { return; }
if (!(this._isRunning)) { throw new RuntimeException("The game loop hadn't yet started."); }
if (!(this._handle)) { throw new FatalErrorException(); }

this._stop();
this._handle = undefined;
Expand Down
5 changes: 4 additions & 1 deletion src/models/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,14 @@ export {

} from "./exceptions/index.js";

import GameLoop from "./game-loop.js";

export { SmartIterator, SmartAsyncIterator } from "./iterators/index.js";
export { JSONStorage } from "./json/index.js";
export { DeferredPromise, SmartPromise, TimedPromise } from "./promises/index.js";

import Publisher from "./publisher.js";

export { Publisher };
export { Clock, Countdown } from "./timers/index.js";

export { GameLoop, Publisher };
4 changes: 3 additions & 1 deletion src/models/iterators/smart-async-iterator.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { ValueException } from "../exceptions/index.js";

import type {
AsyncGeneratorFunction,
GeneratorFunction,
Expand Down Expand Up @@ -168,7 +170,7 @@ export default class SmartAsyncIterator<T, R = void, N = undefined> implements A
if (accumulator === undefined)
{
const result = await this._iterator.next();
if (result.done) { throw new TypeError("Reduce of empty iterator with no initial value"); }
if (result.done) { throw new ValueException("Cannot reduce an empty iterator without an initial value."); }

accumulator = (result.value as unknown) as A;
index += 1;
Expand Down
4 changes: 3 additions & 1 deletion src/models/iterators/smart-iterator.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { ValueException } from "../exceptions/index.js";

import type { GeneratorFunction, Iteratee, TypeGuardIteratee, Reducer, IterLike } from "./types.js";

export default class SmartIterator<T, R = void, N = undefined> implements Iterator<T, R, N>
Expand Down Expand Up @@ -110,7 +112,7 @@ export default class SmartIterator<T, R = void, N = undefined> implements Iterat
if (accumulator === undefined)
{
const result = this._iterator.next();
if (result.done) { throw new TypeError("Reduce of empty iterator with no initial value"); }
if (result.done) { throw new ValueException("Cannot reduce an empty iterator without an initial value."); }

accumulator = (result.value as unknown) as A;
index += 1;
Expand Down
16 changes: 15 additions & 1 deletion src/models/timers/clock.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { TimeUnit } from "../../utils/date.js";

import { RangeException } from "../exceptions/index.js";
import { RangeException, RuntimeException } from "../exceptions/index.js";
import GameLoop from "../game-loop.js";
import Publisher from "../publisher.js";

Expand All @@ -15,6 +15,20 @@ export default class Clock extends GameLoop
this._publisher = new Publisher();
}

public start(elapsedTime = 0): void
{
if (this._isRunning) { throw new RuntimeException("The clock has already been started."); }

super.start(elapsedTime);
}

public stop(): void
{
if (!(this._isRunning)) { throw new RuntimeException("The clock hadn't yet started."); }

super.stop();
}

public onTick(callback: (elapsedTime: number) => void, tickStep = 0): () => void
{
if (tickStep < 0) { throw new RangeException("The tick step must be a non-negative number."); }
Expand Down
8 changes: 5 additions & 3 deletions src/models/timers/countdown.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { TimeUnit } from "../../utils/date.js";

import { RangeException } from "../exceptions/index.js";
import { FatalErrorException, RangeException, RuntimeException } from "../exceptions/index.js";
import { DeferredPromise } from "../promises/index.js";

import GameLoop from "../game-loop.js";
Expand Down Expand Up @@ -42,7 +42,8 @@ export default class Countdown extends GameLoop

public start(remainingTime: number = this.duration): DeferredPromise<void>
{
if (!(this._isRunning)) { return; }
if (this._isRunning) { throw new RuntimeException("The countdown has already been started."); }
if (this._deferrer) { throw new FatalErrorException(); }

this._deferrer = new DeferredPromise(() => this.stop());
super.start(this.duration - remainingTime);
Expand All @@ -51,7 +52,8 @@ export default class Countdown extends GameLoop
}
public stop(reason?: unknown): void
{
if (!(this._deferrer)) { return; }
if (!(this._isRunning)) { throw new RuntimeException("The countdown hadn't yet started."); }
if (!(this._deferrer)) { throw new FatalErrorException(); }

super.stop();

Expand Down

0 comments on commit 57af8c0

Please sign in to comment.