Merge branch 'main' of https://code.incremental.social/escapee/profectus-template
All checks were successful
Build and Deploy / build-and-deploy (push) Successful in 55s
Run Tests / test (push) Successful in 1m53s

This commit is contained in:
escapee 2024-02-21 16:37:16 -08:00
commit 2e946203fa
3 changed files with 133 additions and 5 deletions

View file

@ -1,3 +1,4 @@
import Node from "components/Node.vue";
import Spacer from "components/layout/Spacer.vue"; import Spacer from "components/layout/Spacer.vue";
import { jsx } from "features/feature"; import { jsx } from "features/feature";
import { createResource, trackBest, trackOOMPS, trackTotal } from "features/resources/resource"; import { createResource, trackBest, trackOOMPS, trackTotal } from "features/resources/resource";
@ -48,19 +49,35 @@ export const main = createLayer("main", function (this: BaseLayer) {
links: tree.links, links: tree.links,
display: jsx(() => ( display: jsx(() => (
<> <>
{player.devSpeed === 0 ? <div>Game Paused</div> : null} {player.devSpeed === 0 ? (
<div>
Game Paused
<Node id="paused" />
</div>
) : null}
{player.devSpeed != null && player.devSpeed !== 0 && player.devSpeed !== 1 ? ( {player.devSpeed != null && player.devSpeed !== 0 && player.devSpeed !== 1 ? (
<div>Dev Speed: {format(player.devSpeed)}x</div> <div>
Dev Speed: {format(player.devSpeed)}x
<Node id="devspeed" />
</div>
) : null} ) : null}
{player.offlineTime != null && player.offlineTime !== 0 ? ( {player.offlineTime != null && player.offlineTime !== 0 ? (
<div>Offline Time: {formatTime(player.offlineTime)}</div> <div>
Offline Time: {formatTime(player.offlineTime)}
<Node id="offline" />
</div>
) : null} ) : null}
<div> <div>
{Decimal.lt(points.value, "1e1000") ? <span>You have </span> : null} {Decimal.lt(points.value, "1e1000") ? <span>You have </span> : null}
<h2>{format(points.value)}</h2> <h2>{format(points.value)}</h2>
{Decimal.lt(points.value, "1e1e6") ? <span> points</span> : null} {Decimal.lt(points.value, "1e1e6") ? <span> points</span> : null}
</div> </div>
{Decimal.gt(pointGain.value, 0) ? <div>({oomps.value})</div> : null} {Decimal.gt(pointGain.value, 0) ? (
<div>
({oomps.value})
<Node id="oomps" />
</div>
) : null}
<Spacer /> <Spacer />
{render(tree)} {render(tree)}
</> </>

View file

@ -224,7 +224,7 @@ export interface BaseTree {
id: string; id: string;
/** The link objects for each of the branches of the tree. */ /** The link objects for each of the branches of the tree. */
links: Ref<Link[]>; links: Ref<Link[]>;
/** Cause a reset on this node and propagate it through the tree according to {@link resetPropagation}. */ /** Cause a reset on this node and propagate it through the tree according to {@link TreeOptions.resetPropagation}. */
reset: (node: GenericTreeNode) => void; reset: (node: GenericTreeNode) => void;
/** A flag that is true while the reset is still propagating through the tree. */ /** A flag that is true while the reset is still propagating through the tree. */
isResetting: Ref<boolean>; isResetting: Ref<boolean>;

111
tests/features/tree.test.ts Normal file
View file

@ -0,0 +1,111 @@
import { beforeAll, beforeEach, describe, expect, test, vi } from "vitest";
import { Ref, ref } from "vue";
import "../utils";
import {
createTree,
createTreeNode,
defaultResetPropagation,
invertedResetPropagation,
branchedResetPropagation
} from "features/trees/tree";
import { createReset, GenericReset } from "features/reset";
describe("Reset propagation", () => {
let shouldReset: Ref<boolean>, shouldNotReset: Ref<boolean>;
let goodReset: GenericReset, badReset: GenericReset;
beforeAll(() => {
shouldReset = ref(false);
shouldNotReset = ref(false);
goodReset = createReset(() => ({
thingsToReset: [],
onReset() {
shouldReset.value = true;
}
}));
badReset = createReset(() => ({
thingsToReset: [],
onReset() {
shouldNotReset.value = true;
}
}));
});
beforeEach(() => {
shouldReset.value = false;
shouldNotReset.value = false;
});
test("No resets", () => {
expect(() => {
const a = createTreeNode(() => ({}));
const b = createTreeNode(() => ({}));
const c = createTreeNode(() => ({}));
const tree = createTree(() => ({
nodes: [[a], [b], [c]]
}));
tree.reset(a);
}).not.toThrowError();
});
test("Do not propagate resets", () => {
const a = createTreeNode(() => ({ reset: badReset }));
const b = createTreeNode(() => ({ reset: badReset }));
const c = createTreeNode(() => ({ reset: badReset }));
const tree = createTree(() => ({
nodes: [[a], [b], [c]]
}));
tree.reset(b);
expect(shouldNotReset.value).toBe(false);
});
test("Default propagation", () => {
const a = createTreeNode(() => ({ reset: goodReset }));
const b = createTreeNode(() => ({}));
const c = createTreeNode(() => ({ reset: badReset }));
const tree = createTree(() => ({
nodes: [[a], [b], [c]],
resetPropagation: defaultResetPropagation
}));
tree.reset(b);
expect(shouldReset.value).toBe(true);
expect(shouldNotReset.value).toBe(false);
});
test("Inverted propagation", () => {
const a = createTreeNode(() => ({ reset: badReset }));
const b = createTreeNode(() => ({}));
const c = createTreeNode(() => ({ reset: goodReset }));
const tree = createTree(() => ({
nodes: [[a], [b], [c]],
resetPropagation: invertedResetPropagation
}));
tree.reset(b);
expect(shouldReset.value).toBe(true);
expect(shouldNotReset.value).toBe(false);
});
test("Branched propagation", () => {
const a = createTreeNode(() => ({ reset: badReset }));
const b = createTreeNode(() => ({}));
const c = createTreeNode(() => ({ reset: goodReset }));
const tree = createTree(() => ({
nodes: [[a, b, c]],
resetPropagation: branchedResetPropagation,
branches: [{ startNode: b, endNode: c }]
}));
tree.reset(b);
expect(shouldReset.value).toBe(true);
expect(shouldNotReset.value).toBe(false);
});
test("Branched propagation not bi-directional", () => {
const a = createTreeNode(() => ({ reset: badReset }));
const b = createTreeNode(() => ({}));
const c = createTreeNode(() => ({ reset: badReset }));
const tree = createTree(() => ({
nodes: [[a, b, c]],
resetPropagation: branchedResetPropagation,
branches: [{ startNode: c, endNode: b }]
}));
tree.reset(b);
expect(shouldNotReset.value).toBe(false);
});
});