Added notifications to actions

This commit is contained in:
thepaperpilot 2021-08-27 00:18:34 -05:00
parent 9313748f21
commit 029cd534b1
5 changed files with 49 additions and 16 deletions

15
package-lock.json generated
View file

@ -16,6 +16,7 @@
"vue-panzoom": "^1.1.6",
"vue-sortable": "github:Netbel/vue-sortable#master-fix",
"vue-textarea-autosize": "^1.1.1",
"vue-toastification": "^2.0.0-rc.1",
"vue-transition-expand": "^0.1.0"
},
"devDependencies": {
@ -27325,6 +27326,14 @@
"deprecated": "core-js@<3.3 is no longer maintained and not recommended for usage due to the number of issues. Because of the V8 engine whims, feature detection in old core-js versions could cause a slowdown up to 100x even if nothing is polyfilled. Please, upgrade your dependencies to the actual version of core-js.",
"hasInstallScript": true
},
"node_modules/vue-toastification": {
"version": "2.0.0-rc.1",
"resolved": "https://registry.npmjs.org/vue-toastification/-/vue-toastification-2.0.0-rc.1.tgz",
"integrity": "sha512-hjauv/FyesNZdwcr5m1SCyvu1JmlB+Ts5bTptDLDmsYYlj6Oqv8NYakiElpCF+Abwkn9J/AChh6FwkTL1HOb7Q==",
"peerDependencies": {
"vue": "^3.0.2"
}
},
"node_modules/vue-transition-expand": {
"version": "0.1.0",
"resolved": "https://registry.npmjs.org/vue-transition-expand/-/vue-transition-expand-0.1.0.tgz",
@ -41121,6 +41130,12 @@
}
}
},
"vue-toastification": {
"version": "2.0.0-rc.1",
"resolved": "https://registry.npmjs.org/vue-toastification/-/vue-toastification-2.0.0-rc.1.tgz",
"integrity": "sha512-hjauv/FyesNZdwcr5m1SCyvu1JmlB+Ts5bTptDLDmsYYlj6Oqv8NYakiElpCF+Abwkn9J/AChh6FwkTL1HOb7Q==",
"requires": {}
},
"vue-transition-expand": {
"version": "0.1.0",
"resolved": "https://registry.npmjs.org/vue-transition-expand/-/vue-transition-expand-0.1.0.tgz",

View file

@ -16,6 +16,7 @@
"vue-panzoom": "^1.1.6",
"vue-sortable": "github:Netbel/vue-sortable#master-fix",
"vue-textarea-autosize": "^1.1.1",
"vue-toastification": "^2.0.0-rc.1",
"vue-transition-expand": "^0.1.0"
},
"devDependencies": {

View file

@ -2,12 +2,14 @@
// which will allow us to use them in any template strings anywhere in the project
import CollapseTransition from "@ivanv/vue-collapse-transition/src/CollapseTransition.vue";
import VueTextareaAutosize from "vue-textarea-autosize";
import Sortable from "vue-sortable";
import { App } from "vue";
import VueNextSelect from "vue-next-select";
import "vue-next-select/dist/index.css";
import panZoom from "vue-panzoom";
import { App } from "vue";
import Sortable from "vue-sortable";
import VueTextareaAutosize from "vue-textarea-autosize";
import Toast from "vue-toastification";
import "vue-toastification/dist/index.css";
export function registerComponents(vue: App): void {
/* from files */
@ -25,4 +27,5 @@ export function registerComponents(vue: App): void {
vue.use(Sortable);
vue.component("vue-select", VueNextSelect);
vue.use(panZoom);
vue.use(Toast);
}

View file

@ -16,9 +16,12 @@ import { format, formatWhole } from "@/util/break_eternity";
import { camelToTitle } from "@/util/common";
import { getUniqueNodeID } from "@/util/features";
import { computed, watch } from "vue";
import { useToast } from "vue-toastification";
import themes from "../themes";
import Main from "./Main.vue";
const toast = useToast();
type ResourceNodeData = {
resourceType: string;
amount: DecimalSource;
@ -129,7 +132,7 @@ export type LogEntry = {
export type WeightedEvent = {
event: () => LogEntry;
weight: number;
weight: number | (() => number);
};
function createItem(resource: string, amount: DecimalSource, display?: string) {
@ -148,10 +151,7 @@ type Action = {
icon?: string;
fillColor?: string;
tooltip?: string;
events?: Array<{
event: () => LogEntry;
weight: number;
}>;
events?: Array<WeightedEvent>;
baseChanges?: Array<{
resource: string;
amount: DecimalSource;
@ -258,7 +258,7 @@ const actions = {
};
},
weight() {
return Decimal.sub(100, resources.mental.amount || 100);
return Decimal.sub(100, resources.mental.amount);
}
},
{
@ -272,7 +272,7 @@ const actions = {
};
},
weight() {
return Decimal.sub(resources.mental.amount || 100, 75).max(5);
return Decimal.sub(resources.mental.amount, 75).max(5);
}
}
],
@ -431,13 +431,22 @@ function getRandomEvent(events: WeightedEvent[]): LogEntry | null {
if (events.length === 0) {
return null;
}
const totalWeight = events.reduce((acc, curr) => acc + curr.weight, 0);
const random = Math.random() * totalWeight;
const totalWeight = events.reduce((acc, curr) => {
let weight = curr.weight;
if (typeof weight === "function") {
weight = weight();
}
return Decimal.add(acc, weight);
}, new Decimal(0));
const random = Decimal.times(Math.random(), totalWeight);
let weight = 0;
let weight = new Decimal(0);
for (const outcome of events) {
weight += outcome.weight;
if (random <= weight) {
weight = Decimal.add(
weight,
typeof outcome.weight === "function" ? outcome.weight() : outcome.weight
);
if (Decimal.lte(random, weight)) {
return outcome.event();
}
}
@ -613,6 +622,7 @@ function performAction(id: string, action: Action, node: BoardNode) {
if (action.events) {
const logEntry = getRandomEvent(action.events);
if (logEntry) {
toast.info(logEntry.description);
(node.data as ActionNodeData).log.push(logEntry);
}
}

View file

@ -62,3 +62,7 @@ a:hover,
ul {
list-style-type: none;
}
.Vue-Toastification__toast {
margin: unset;
}