mirror of
https://github.com/thepaperpilot/Planar-Pioneers.git
synced 2024-12-01 04:12:24 +00:00
Added notifications to actions
This commit is contained in:
parent
9313748f21
commit
029cd534b1
5 changed files with 49 additions and 16 deletions
15
package-lock.json
generated
15
package-lock.json
generated
|
@ -16,6 +16,7 @@
|
||||||
"vue-panzoom": "^1.1.6",
|
"vue-panzoom": "^1.1.6",
|
||||||
"vue-sortable": "github:Netbel/vue-sortable#master-fix",
|
"vue-sortable": "github:Netbel/vue-sortable#master-fix",
|
||||||
"vue-textarea-autosize": "^1.1.1",
|
"vue-textarea-autosize": "^1.1.1",
|
||||||
|
"vue-toastification": "^2.0.0-rc.1",
|
||||||
"vue-transition-expand": "^0.1.0"
|
"vue-transition-expand": "^0.1.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"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.",
|
"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
|
"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": {
|
"node_modules/vue-transition-expand": {
|
||||||
"version": "0.1.0",
|
"version": "0.1.0",
|
||||||
"resolved": "https://registry.npmjs.org/vue-transition-expand/-/vue-transition-expand-0.1.0.tgz",
|
"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": {
|
"vue-transition-expand": {
|
||||||
"version": "0.1.0",
|
"version": "0.1.0",
|
||||||
"resolved": "https://registry.npmjs.org/vue-transition-expand/-/vue-transition-expand-0.1.0.tgz",
|
"resolved": "https://registry.npmjs.org/vue-transition-expand/-/vue-transition-expand-0.1.0.tgz",
|
||||||
|
|
|
@ -16,6 +16,7 @@
|
||||||
"vue-panzoom": "^1.1.6",
|
"vue-panzoom": "^1.1.6",
|
||||||
"vue-sortable": "github:Netbel/vue-sortable#master-fix",
|
"vue-sortable": "github:Netbel/vue-sortable#master-fix",
|
||||||
"vue-textarea-autosize": "^1.1.1",
|
"vue-textarea-autosize": "^1.1.1",
|
||||||
|
"vue-toastification": "^2.0.0-rc.1",
|
||||||
"vue-transition-expand": "^0.1.0"
|
"vue-transition-expand": "^0.1.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
|
|
@ -2,12 +2,14 @@
|
||||||
// which will allow us to use them in any template strings anywhere in the project
|
// 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 CollapseTransition from "@ivanv/vue-collapse-transition/src/CollapseTransition.vue";
|
||||||
import VueTextareaAutosize from "vue-textarea-autosize";
|
import { App } from "vue";
|
||||||
import Sortable from "vue-sortable";
|
|
||||||
import VueNextSelect from "vue-next-select";
|
import VueNextSelect from "vue-next-select";
|
||||||
import "vue-next-select/dist/index.css";
|
import "vue-next-select/dist/index.css";
|
||||||
import panZoom from "vue-panzoom";
|
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 {
|
export function registerComponents(vue: App): void {
|
||||||
/* from files */
|
/* from files */
|
||||||
|
@ -25,4 +27,5 @@ export function registerComponents(vue: App): void {
|
||||||
vue.use(Sortable);
|
vue.use(Sortable);
|
||||||
vue.component("vue-select", VueNextSelect);
|
vue.component("vue-select", VueNextSelect);
|
||||||
vue.use(panZoom);
|
vue.use(panZoom);
|
||||||
|
vue.use(Toast);
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,9 +16,12 @@ import { format, formatWhole } from "@/util/break_eternity";
|
||||||
import { camelToTitle } from "@/util/common";
|
import { camelToTitle } from "@/util/common";
|
||||||
import { getUniqueNodeID } from "@/util/features";
|
import { getUniqueNodeID } from "@/util/features";
|
||||||
import { computed, watch } from "vue";
|
import { computed, watch } from "vue";
|
||||||
|
import { useToast } from "vue-toastification";
|
||||||
import themes from "../themes";
|
import themes from "../themes";
|
||||||
import Main from "./Main.vue";
|
import Main from "./Main.vue";
|
||||||
|
|
||||||
|
const toast = useToast();
|
||||||
|
|
||||||
type ResourceNodeData = {
|
type ResourceNodeData = {
|
||||||
resourceType: string;
|
resourceType: string;
|
||||||
amount: DecimalSource;
|
amount: DecimalSource;
|
||||||
|
@ -129,7 +132,7 @@ export type LogEntry = {
|
||||||
|
|
||||||
export type WeightedEvent = {
|
export type WeightedEvent = {
|
||||||
event: () => LogEntry;
|
event: () => LogEntry;
|
||||||
weight: number;
|
weight: number | (() => number);
|
||||||
};
|
};
|
||||||
|
|
||||||
function createItem(resource: string, amount: DecimalSource, display?: string) {
|
function createItem(resource: string, amount: DecimalSource, display?: string) {
|
||||||
|
@ -148,10 +151,7 @@ type Action = {
|
||||||
icon?: string;
|
icon?: string;
|
||||||
fillColor?: string;
|
fillColor?: string;
|
||||||
tooltip?: string;
|
tooltip?: string;
|
||||||
events?: Array<{
|
events?: Array<WeightedEvent>;
|
||||||
event: () => LogEntry;
|
|
||||||
weight: number;
|
|
||||||
}>;
|
|
||||||
baseChanges?: Array<{
|
baseChanges?: Array<{
|
||||||
resource: string;
|
resource: string;
|
||||||
amount: DecimalSource;
|
amount: DecimalSource;
|
||||||
|
@ -258,7 +258,7 @@ const actions = {
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
weight() {
|
weight() {
|
||||||
return Decimal.sub(100, resources.mental.amount || 100);
|
return Decimal.sub(100, resources.mental.amount);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -272,7 +272,7 @@ const actions = {
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
weight() {
|
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) {
|
if (events.length === 0) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
const totalWeight = events.reduce((acc, curr) => acc + curr.weight, 0);
|
const totalWeight = events.reduce((acc, curr) => {
|
||||||
const random = Math.random() * totalWeight;
|
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) {
|
for (const outcome of events) {
|
||||||
weight += outcome.weight;
|
weight = Decimal.add(
|
||||||
if (random <= weight) {
|
weight,
|
||||||
|
typeof outcome.weight === "function" ? outcome.weight() : outcome.weight
|
||||||
|
);
|
||||||
|
if (Decimal.lte(random, weight)) {
|
||||||
return outcome.event();
|
return outcome.event();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -613,6 +622,7 @@ function performAction(id: string, action: Action, node: BoardNode) {
|
||||||
if (action.events) {
|
if (action.events) {
|
||||||
const logEntry = getRandomEvent(action.events);
|
const logEntry = getRandomEvent(action.events);
|
||||||
if (logEntry) {
|
if (logEntry) {
|
||||||
|
toast.info(logEntry.description);
|
||||||
(node.data as ActionNodeData).log.push(logEntry);
|
(node.data as ActionNodeData).log.push(logEntry);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -62,3 +62,7 @@ a:hover,
|
||||||
ul {
|
ul {
|
||||||
list-style-type: none;
|
list-style-type: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.Vue-Toastification__toast {
|
||||||
|
margin: unset;
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue