diff --git a/package-lock.json b/package-lock.json index 1871ec0..dbfe0eb 100644 --- a/package-lock.json +++ b/package-lock.json @@ -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", diff --git a/package.json b/package.json index f9fbcff..3100357 100644 --- a/package.json +++ b/package.json @@ -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": { diff --git a/src/components/index.ts b/src/components/index.ts index 408338f..bbc74f5 100644 --- a/src/components/index.ts +++ b/src/components/index.ts @@ -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); } diff --git a/src/data/layers/main.ts b/src/data/layers/main.ts index b0c7dc3..d404632 100644 --- a/src/data/layers/main.ts +++ b/src/data/layers/main.ts @@ -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; baseChanges?: Array<{ resource: string; amount: DecimalSource; @@ -254,11 +254,11 @@ const actions = { resources.energy.amount = 50; return { description: "You had a very restless sleep filled with nightmares :(", - effectDescription: `50% Energy` + effectDescription: `50% Energy ` }; }, 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); } } diff --git a/src/main.css b/src/main.css index 519e0e2..60188bd 100644 --- a/src/main.css +++ b/src/main.css @@ -62,3 +62,7 @@ a:hover, ul { list-style-type: none; } + +.Vue-Toastification__toast { + margin: unset; +}