Merge remote-tracking branch 'template/main'

This commit is contained in:
thepaperpilot 2022-03-20 14:06:47 -05:00
commit 2563ab7471
20 changed files with 672 additions and 610 deletions

View file

@ -6,6 +6,17 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased] ## [Unreleased]
## [0.1.4] - 2022-03-13
### Added
- You can now access this.on() from within a createLayer function (and other BaseLayer properties)
- Support for passing non-persistent refs to createResource
- dontMerge class to allow features to ignore mergeAdjacent
### Fixed
- Clickables would not merge adjacent
- onClick and onHold functions would not be bound to their object when being called
- Refs passed to a components style prop would be ignored
- Fixed z-index issue when stopping hovering over features with .can class
## [0.1.3] - 2022-03-11 ## [0.1.3] - 2022-03-11
### Added ### Added
- Milestone.complete - Milestone.complete

1111
package-lock.json generated

File diff suppressed because it is too large Load diff

View file

@ -1,6 +1,6 @@
{ {
"name": "profectus", "name": "profectus",
"version": "0.1.3", "version": "0.1.4",
"private": true, "private": true,
"scripts": { "scripts": {
"start": "vue-cli-service serve", "start": "vue-cli-service serve",
@ -26,10 +26,10 @@
"@rushstack/eslint-patch": "^1.1.0", "@rushstack/eslint-patch": "^1.1.0",
"@types/lodash.clonedeep": "^4.5.6", "@types/lodash.clonedeep": "^4.5.6",
"@vue/babel-plugin-jsx": "^1.1.1", "@vue/babel-plugin-jsx": "^1.1.1",
"@vue/cli-plugin-babel": "~5.0.0-rc.1", "@vue/cli-plugin-babel": "^5.0.3",
"@vue/cli-plugin-eslint": "~5.0.0-rc.1", "@vue/cli-plugin-eslint": "^5.0.3",
"@vue/cli-plugin-typescript": "~5.0.0-rc.1", "@vue/cli-plugin-typescript": "^5.0.3",
"@vue/cli-service": "~5.0.0-rc.1", "@vue/cli-service": "^5.0.3",
"@vue/compiler-sfc": "^3.2.26", "@vue/compiler-sfc": "^3.2.26",
"@vue/eslint-config-prettier": "^7.0.0", "@vue/eslint-config-prettier": "^7.0.0",
"@vue/eslint-config-typescript": "^10.0.0", "@vue/eslint-config-typescript": "^10.0.0",

View file

@ -7,6 +7,8 @@
margin: var(--feature-margin); margin: var(--feature-margin);
box-sizing: border-box; box-sizing: border-box;
color: var(--feature-foreground); color: var(--feature-foreground);
z-index: 0;
transition: all 0.5s, z-index 0s 0.5s;
} }
.can, .can,
@ -20,6 +22,7 @@
transform: scale(1.15, 1.15); transform: scale(1.15, 1.15);
box-shadow: 0 0 20px var(--points); box-shadow: 0 0 20px var(--points);
z-index: 1; z-index: 1;
transition: all 0.5s, z-index 0s;
} }
.locked, .locked,

View file

@ -34,57 +34,57 @@
margin: 10px 0; margin: 10px 0;
} }
.row.mergeAdjacent > .feature, .row.mergeAdjacent > .feature:not(.dontMerge),
.row.mergeAdjacent > .tooltip-container > .feature { .row.mergeAdjacent > .tooltip-container > .feature:not(.dontMerge) {
margin-left: 0; margin-left: 0;
margin-right: 0; margin-right: 0;
border-radius: 0; border-radius: 0;
} }
.row.mergeAdjacent > .feature:first-child, .row.mergeAdjacent > .feature:not(.dontMerge):first-child,
.row.mergeAdjacent > .tooltip-container:first-child > .feature { .row.mergeAdjacent > .tooltip-container:first-child > .feature:not(.dontMerge) {
border-radius: var(--border-radius) 0 0 var(--border-radius); border-radius: var(--border-radius) 0 0 var(--border-radius);
} }
.row.mergeAdjacent > .feature:last-child, .row.mergeAdjacent > .feature:not(.dontMerge):last-child,
.row.mergeAdjacent > .tooltip-container:last-child > .feature { .row.mergeAdjacent > .tooltip-container:last-child > .feature:not(.dontMerge) {
border-radius: 0 var(--border-radius) var(--border-radius) 0; border-radius: 0 var(--border-radius) var(--border-radius) 0;
} }
.row.mergeAdjacent > .feature:first-child:last-child, .row.mergeAdjacent > .feature:not(.dontMerge):first-child:last-child,
.row.mergeAdjacent > .tooltip-container:first-child:last-child > .feature { .row.mergeAdjacent > .tooltip-container:first-child:last-child > .feature:not(.dontMerge) {
border-radius: var(--border-radius); border-radius: var(--border-radius);
} }
/* /*
TODO how to implement mergeAdjacent for grids? TODO how to implement mergeAdjacent for grids?
.row.mergeAdjacent + .row.mergeAdjacent > .feature { .row.mergeAdjacent + .row.mergeAdjacent > .feature:not(.dontMerge) {
border-top-left-radius: 0; border-top-left-radius: 0;
border-top-right-radius: 0; border-top-right-radius: 0;
} }
*/ */
.col.mergeAdjacent .feature { .col.mergeAdjacent .feature:not(.dontMerge) {
margin-top: 0; margin-top: 0;
margin-bottom: 0; margin-bottom: 0;
border-radius: 0; border-radius: 0;
} }
.col.mergeAdjacent .feature:first-child { .col.mergeAdjacent .feature:not(.dontMerge):first-child {
border-radius: var(--border-radius) var(--border-radius) 0 0; border-radius: var(--border-radius) var(--border-radius) 0 0;
} }
.col.mergeAdjacent .feature:last-child { .col.mergeAdjacent .feature:not(.dontMerge):last-child {
border-radius: 0 0 var(--border-radius) var(--border-radius); border-radius: 0 0 var(--border-radius) var(--border-radius);
} }
.col.mergeAdjacent .feature:first-child:last-child { .col.mergeAdjacent .feature:not(.dontMerge):first-child:last-child {
border-radius: var(--border-radius); border-radius: var(--border-radius);
} }
/* /*
TODO how to implement mergeAdjacent for grids? TODO how to implement mergeAdjacent for grids?
.col.mergeAdjacent + .col.mergeAdjacent > .feature { .col.mergeAdjacent + .col.mergeAdjacent > .feature:not(.dontMerge) {
border-top-left-radius: 0; border-top-left-radius: 0;
border-bottom-left-radius: 0; border-bottom-left-radius: 0;
} }

View file

@ -91,7 +91,7 @@ export function createAchievement<T extends AchievementOptions>(
achievement[GatherProps] = function (this: GenericAchievement) { achievement[GatherProps] = function (this: GenericAchievement) {
const { visibility, display, earned, image, style, classes, mark, id } = this; const { visibility, display, earned, image, style, classes, mark, id } = this;
return { visibility, display, earned, image, style, classes, mark, id }; return { visibility, display, earned, image, style: unref(style), classes, mark, id };
}; };
if (achievement.shouldEarn) { if (achievement.shouldEarn) {

View file

@ -18,6 +18,7 @@ import {
ProcessedComputable ProcessedComputable
} from "util/computed"; } from "util/computed";
import { createLazyProxy } from "util/proxies"; import { createLazyProxy } from "util/proxies";
import { unref } from "vue";
export const BarType = Symbol("Bar"); export const BarType = Symbol("Bar");
@ -124,7 +125,7 @@ export function createBar<T extends BarOptions>(optionsFunc: () => T & ThisType<
direction, direction,
display, display,
visibility, visibility,
style, style: unref(style),
classes, classes,
borderStyle, borderStyle,
textStyle, textStyle,

View file

@ -316,7 +316,7 @@ export function createBoard<T extends BoardOptions>(
visibility, visibility,
width, width,
height, height,
style, style: unref(style),
classes, classes,
links, links,
selectedAction, selectedAction,

View file

@ -162,12 +162,11 @@ export function createBuyable<T extends BuyableOptions>(
buyable.display = jsx(() => { buyable.display = jsx(() => {
// TODO once processComputable types correctly, remove this "as X" // TODO once processComputable types correctly, remove this "as X"
const currDisplay = unref(display) as BuyableDisplay; const currDisplay = unref(display) as BuyableDisplay;
if ( if (isCoercableComponent(currDisplay)) {
currDisplay != null && const CurrDisplay = coerceComponent(currDisplay);
!isCoercableComponent(currDisplay) && return <CurrDisplay />;
buyable.cost != null && }
buyable.resource != null if (currDisplay != null && buyable.cost != null && buyable.resource != null) {
) {
const genericBuyable = buyable as GenericBuyable; const genericBuyable = buyable as GenericBuyable;
const Title = coerceComponent(currDisplay.title || "", "h3"); const Title = coerceComponent(currDisplay.title || "", "h3");
const Description = coerceComponent(currDisplay.description); const Description = coerceComponent(currDisplay.description);
@ -226,7 +225,17 @@ export function createBuyable<T extends BuyableOptions>(
buyable[GatherProps] = function (this: GenericBuyable) { buyable[GatherProps] = function (this: GenericBuyable) {
const { display, visibility, style, classes, onClick, canClick, small, mark, id } = const { display, visibility, style, classes, onClick, canClick, small, mark, id } =
this; this;
return { display, visibility, style, classes, onClick, canClick, small, mark, id }; return {
display,
visibility,
style: unref(style),
classes,
onClick,
canClick,
small,
mark,
id
};
}; };
return buyable as unknown as Buyable<T>; return buyable as unknown as Buyable<T>;

View file

@ -247,7 +247,7 @@ export function createChallenge<T extends ChallengeOptions>(
canComplete, canComplete,
display, display,
visibility, visibility,
style, style: unref(style),
classes, classes,
completed, completed,
canStart, canStart,

View file

@ -1,10 +1,10 @@
<template> <template>
<div
v-if="unref(visibility) !== Visibility.None"
:style="{ visibility: unref(visibility) === Visibility.Hidden ? 'hidden' : undefined }"
>
<button <button
:style="unref(style)" v-if="unref(visibility) !== Visibility.None"
:style="[
{ visibility: unref(visibility) === Visibility.Hidden ? 'hidden' : undefined },
unref(style) ?? []
]"
@click="onClick" @click="onClick"
@mousedown="start" @mousedown="start"
@mouseleave="stop" @mouseleave="stop"
@ -25,7 +25,6 @@
<MarkNode :mark="unref(mark)" /> <MarkNode :mark="unref(mark)" />
<LinkNode :id="id" /> <LinkNode :id="id" />
</button> </button>
</div>
</template> </template>
<script lang="tsx"> <script lang="tsx">

View file

@ -87,7 +87,7 @@ export function createClickable<T extends ClickableOptions>(
processComputable(clickable as T, "display"); processComputable(clickable as T, "display");
if (clickable.onClick) { if (clickable.onClick) {
const onClick = clickable.onClick; const onClick = clickable.onClick.bind(clickable);
clickable.onClick = function () { clickable.onClick = function () {
if (unref(clickable.canClick)) { if (unref(clickable.canClick)) {
onClick(); onClick();
@ -95,7 +95,7 @@ export function createClickable<T extends ClickableOptions>(
}; };
} }
if (clickable.onHold) { if (clickable.onHold) {
const onHold = clickable.onHold; const onHold = clickable.onHold.bind(clickable);
clickable.onHold = function () { clickable.onHold = function () {
if (unref(clickable.canClick)) { if (unref(clickable.canClick)) {
onHold(); onHold();
@ -119,7 +119,7 @@ export function createClickable<T extends ClickableOptions>(
return { return {
display, display,
visibility, visibility,
style, style: unref(style),
classes, classes,
onClick, onClick,
onHold, onHold,

View file

@ -279,7 +279,7 @@ export function createGrid<T extends GridOptions>(
processComputable(grid as T, "getDisplay"); processComputable(grid as T, "getDisplay");
if (grid.onClick) { if (grid.onClick) {
const onClick = grid.onClick; const onClick = grid.onClick.bind(grid);
grid.onClick = function (id, state) { grid.onClick = function (id, state) {
if (unref((grid as GenericGrid).cells[id].canClick)) { if (unref((grid as GenericGrid).cells[id].canClick)) {
onClick(id, state); onClick(id, state);
@ -287,7 +287,7 @@ export function createGrid<T extends GridOptions>(
}; };
} }
if (grid.onHold) { if (grid.onHold) {
const onHold = grid.onHold; const onHold = grid.onHold.bind(grid);
grid.onHold = function (id, state) { grid.onHold = function (id, state) {
if (unref((grid as GenericGrid).cells[id].canClick)) { if (unref((grid as GenericGrid).cells[id].canClick)) {
onHold(id, state); onHold(id, state);

View file

@ -17,7 +17,7 @@ import {
ProcessedComputable ProcessedComputable
} from "util/computed"; } from "util/computed";
import { createLazyProxy } from "util/proxies"; import { createLazyProxy } from "util/proxies";
import { Ref } from "vue"; import { Ref, unref } from "vue";
import { Persistent, makePersistent, PersistentState } from "game/persistence"; import { Persistent, makePersistent, PersistentState } from "game/persistence";
export const InfoboxType = Symbol("Infobox"); export const InfoboxType = Symbol("Infobox");
@ -103,7 +103,7 @@ export function createInfobox<T extends InfoboxOptions>(
title, title,
color, color,
collapsed, collapsed,
style, style: unref(style),
titleStyle, titleStyle,
bodyStyle, bodyStyle,
classes, classes,

View file

@ -134,7 +134,7 @@ export function createMilestone<T extends MilestoneOptions>(
milestone[GatherProps] = function (this: GenericMilestone) { milestone[GatherProps] = function (this: GenericMilestone) {
const { visibility, display, style, classes, earned, id } = this; const { visibility, display, style, classes, earned, id } = this;
return { visibility, display, style, classes, earned, id }; return { visibility, display, style: unref(style), classes, earned, id };
}; };
if (milestone.shouldEarn) { if (milestone.shouldEarn) {

View file

@ -1,5 +1,5 @@
import Decimal, { DecimalSource, format, formatWhole } from "util/bignum"; import Decimal, { DecimalSource, format, formatWhole } from "util/bignum";
import { computed, ComputedRef, ref, Ref, watch } from "vue"; import { computed, ComputedRef, isRef, ref, Ref, watch } from "vue";
import { globalBus } from "game/events"; import { globalBus } from "game/events";
import { State, persistent } from "game/persistence"; import { State, persistent } from "game/persistence";
@ -15,7 +15,9 @@ export function createResource<T extends State>(
precision = 0, precision = 0,
small = undefined small = undefined
): Resource<T> { ): Resource<T> {
const resource: Partial<Resource<T>> = persistent(defaultValue); const resource: Partial<Resource<T>> = isRef(defaultValue)
? defaultValue
: persistent(defaultValue);
resource.displayName = displayName; resource.displayName = displayName;
resource.precision = precision; resource.precision = precision;
resource.small = small; resource.small = small;

View file

@ -145,7 +145,7 @@ export function createTabFamily<T extends TabFamilyOptions>(
tabFamily[GatherProps] = function (this: GenericTabFamily) { tabFamily[GatherProps] = function (this: GenericTabFamily) {
const { visibility, activeTab, selected, tabs, style, classes } = this; const { visibility, activeTab, selected, tabs, style, classes } = this;
return { visibility, activeTab, selected, tabs, style, classes }; return { visibility, activeTab, selected, tabs, style: unref(style), classes };
}; };
// This is necessary because board.types is different from T and TabFamily // This is necessary because board.types is different from T and TabFamily

View file

@ -101,7 +101,7 @@ export function createTreeNode<T extends TreeNodeOptions>(
processComputable(treeNode as T, "mark"); processComputable(treeNode as T, "mark");
if (treeNode.onClick) { if (treeNode.onClick) {
const onClick = treeNode.onClick; const onClick = treeNode.onClick.bind(treeNode);
treeNode.onClick = function () { treeNode.onClick = function () {
if (unref(treeNode.canClick)) { if (unref(treeNode.canClick)) {
onClick(); onClick();
@ -109,7 +109,7 @@ export function createTreeNode<T extends TreeNodeOptions>(
}; };
} }
if (treeNode.onHold) { if (treeNode.onHold) {
const onHold = treeNode.onHold; const onHold = treeNode.onHold.bind(treeNode);
treeNode.onHold = function () { treeNode.onHold = function () {
if (unref(treeNode.canClick)) { if (unref(treeNode.canClick)) {
onHold(); onHold();

View file

@ -154,7 +154,7 @@ export function createUpgrade<T extends UpgradeOptions>(
return { return {
display, display,
visibility, visibility,
style, style: unref(style),
classes, classes,
resource, resource,
cost, cost,

View file

@ -89,15 +89,19 @@ export type GenericLayer = Replace<
} }
>; >;
export function createLayer<T extends LayerOptions>(optionsFunc: () => T): Layer<T> { export function createLayer<T extends LayerOptions>(
optionsFunc: (() => T) & ThisType<BaseLayer>
): Layer<T> {
return createLazyProxy(() => { return createLazyProxy(() => {
const layer = optionsFunc() as T & Partial<BaseLayer>; const layer = {} as T & Partial<BaseLayer>;
const emitter = (layer.emitter = createNanoEvents<LayerEvents>()); const emitter = (layer.emitter = createNanoEvents<LayerEvents>());
layer.on = emitter.on.bind(emitter); layer.on = emitter.on.bind(emitter);
layer.emit = emitter.emit.bind(emitter); layer.emit = emitter.emit.bind(emitter);
layer.minimized = persistent(false); layer.minimized = persistent(false);
Object.assign(layer, optionsFunc.call(layer));
processComputable(layer as T, "color"); processComputable(layer as T, "color");
processComputable(layer as T, "display"); processComputable(layer as T, "display");
processComputable(layer as T, "name"); processComputable(layer as T, "name");