Skip to content

Commit

Permalink
Added Events System
Browse files Browse the repository at this point in the history
  • Loading branch information
gizomo committed Apr 17, 2021
1 parent 85bcb2f commit 61e07e7
Show file tree
Hide file tree
Showing 14 changed files with 215 additions and 18 deletions.
5 changes: 5 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"lint": "vue-cli-service lint"
},
"dependencies": {
"@dafcoe/vue-notification": "^0.1.5",
"core-js": "^3.6.5",
"material-design-icons-iconfont": "^6.1.0",
"svg.js": "^2.7.1",
Expand Down
48 changes: 43 additions & 5 deletions src/components/DiplomacyGame.vue
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,20 @@
</template>
<template #footer></template>
</modal>

<vue-notification-list position="top-right"></vue-notification-list>
</template>
<script>
import { useNotificationStore } from "@dafcoe/vue-notification";
import "@dafcoe/vue-notification/dist/vue-notification.css";
import Modal from "./Modal";
import WorldMap from "./WorldMap";
import GameData from "../assets/gameData";
import WorldMapData from "../assets/worldRussiaCrimeaLow";
import Country from "../models/Country";
import Vote from "../models/Vote";
import ScriptsCreator from "../models/ScriptsCreator";
import Modal from "./Modal";
import EventsCreator from "../models/EventsCreator";
export default {
name: "DiplomacyGame",
Expand All @@ -93,6 +98,7 @@ export default {
Countries: [],
Scripts: [],
Events: [],
Votes: [],
stages: 9,
Expand Down Expand Up @@ -124,13 +130,16 @@ export default {
this.Scripts,
scriptLauncher.createAllScripts()
);
// this.Scripts.push(scriptLauncher.createScript("bitcoin"));
// this.Scripts.push(scriptLauncher.createScript("space"));
const eventLauncher = new EventsCreator();
Array.prototype.push.apply(this.Events, eventLauncher.createAllEvents());
this.launchEvents(2);
},
endStage() {
if (this.currentStage % 3 == 0) {
this.vote(this.selectedResolution);
this.selectedResolution = null;
if (this.selectedResolution) {
this.vote(this.selectedResolution);
this.selectedResolution = null;
}
}
this.currentStage++;
},
Expand Down Expand Up @@ -178,13 +187,42 @@ export default {
},
closeModalWindow() {
this.isModalVisible = false;
this.isResolutionVisible = false;
},
setEvent(gameEvent) {
const notification = {
message: gameEvent.description,
type: "info",
showIcon: true,
dismiss: {
manually: true,
automatically: true,
},
duration: 5000,
showDurationProgress: true,
appearance: "light",
};
const { setNotification } = useNotificationStore();
setNotification(notification);
},
launchEvents(qty) {
this.Events.filter((eItem) => eItem.active == false)
.sort(() => 0.5 - Math.random())
.slice(0, qty)
.forEach((filteredE) => {
this.Events[
this.Events.findIndex((n) => n.name == filteredE.name)
].activateEvent();
this.setEvent(filteredE);
});
},
},
watch: {
currentStage(stage) {
if ((stage + 1) % 3 == 0) {
this.isResolutionVisible = true;
}
this.launchEvents(3);
},
},
};
Expand Down
3 changes: 3 additions & 0 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@ import { createApp } from "vue";
import Root from "./App.vue";
import svgJs from "./plugins/svgJs";
import panZoom from "vue-panzoom";
import VueNotificationList from "@dafcoe/vue-notification";

import "material-design-icons-iconfont";

const app = createApp(Root);
app.use(svgJs);
app.use(panZoom);
app.use(VueNotificationList);
app.mount("#app");
20 changes: 20 additions & 0 deletions src/models/EventsCreator.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// import Bitcoin from "./scripts/Bitcoin";
// import Space from "./scripts/Space";
import * as EventModules from "./events";

export default class EventsCreator {
constructor() {
this.events = [];
}

createEvent(type) {
return new EventModules[type]();
}

createAllEvents() {
Object.values(EventModules).forEach((Module) =>
this.events.push(new Module())
);
return this.events;
}
}
15 changes: 3 additions & 12 deletions src/models/ScriptsCreator.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,9 @@ export default class ScriptsCreator {
this.scripts = [];
}

// createScript(type) {
// let script;
// switch (type) {
// case "bitcoin":
// script = new ScriptModules.Bitcoin();
// break;
// case "space":
// script = new ScriptModules.Space();
// break;
// }
// return script;
// }
createScript(type) {
return new ScriptModules[type]();
}

createAllScripts() {
Object.values(ScriptModules).forEach((Module) =>
Expand Down
12 changes: 12 additions & 0 deletions src/models/events/Cars.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
export default class Cars {
constructor() {
this.name = "cars";
this.description =
"Крупнейшие мировые автоконцерны объявили о конце эры автомобилей с двигателями внутреннего сгорания. С этого года они начнут массовый выпуск электрокаров.";
this.active = false;
}

activateEvent() {
this.active = true;
}
}
40 changes: 40 additions & 0 deletions src/models/events/Dollar.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import WorldMap from "../../assets/worldRussiaCrimeaLow.json";

export default class Dollar {
constructor() {
this.name = "dollar";
this.description =
"Ряд стран отказалось от доллара США при заключении междуанродных сделок в пользу своих национальных валют.";
this.active = false;
this.countries = [];
this.excludedCountries = ["RU", "US"];
}

activateEvent() {
Array.prototype.push.apply(this.excludedCountries, this.countries);
if (this.countries.length) {
Array.prototype.push.apply(
this.countries,
this.getRandomCountries(this.getRandom(3, 10))
);
} else {
this.countries = this.getRandomCountries(this.getRandom(3, 10));
}
}

getRandomCountries(qty) {
return WorldMap.countries
.map((country) => {
return country.id;
})
.filter((country) => !this.excludedCountries.includes(country))
.sort(() => 0.5 - Math.random())
.slice(0, qty);
}

getRandom(min, max) {
min = Math.ceil(min);
max = Math.floor(max);
return Math.floor(Math.random() * (max - min + 1)) + min;
}
}
12 changes: 12 additions & 0 deletions src/models/events/EconomicCrysis.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
export default class EconomicCrysis {
constructor() {
this.name = "economic-crysis";
this.description =
"Мир снова охватил экономический кризис. Мировая валютная система в упадке. Доллар США и Евро резко падают в цене.";
this.active = false;
}

activateEvent() {
this.active = true;
}
}
12 changes: 12 additions & 0 deletions src/models/events/Opec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
export default class Opec {
constructor() {
this.name = "opec";
this.description =
"Страны ОПЕК отказываются удерживать квоты на добычу углеводородов. Цены на мировом рынке нефти и природного газа снова бьют истоический минимум.";
this.active = false;
}

activateEvent() {
this.active = true;
}
}
12 changes: 12 additions & 0 deletions src/models/events/Sanctions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
export default class Sanctions {
constructor() {
this.name = "sanctions";
this.description =
"Страны Европейского Союза отказались продлевать экономиеские санкции против России. Они снова высказывают интерес к сотрудничеству в высокотехнологичных отраслях экономики.";
this.active = false;
}

activateEvent() {
this.active = true;
}
}
12 changes: 12 additions & 0 deletions src/models/events/SpaceX.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
export default class SpaceX {
constructor() {
this.name = "space-x";
this.description =
"Компания Space-X терпит колоссальные убытки. Ни один из ее коммерческих проектов не окупился. Частные инвесторы больше не хотят вкладыать деньги в космические программы.";
this.active = false;
}

activateEvent() {
this.active = true;
}
}
40 changes: 40 additions & 0 deletions src/models/events/WorkingDay.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import WorldMap from "../../assets/worldRussiaCrimeaLow.json";

export default class WorkignDay {
constructor() {
this.name = "working-day";
this.description =
"В ряде стран правительства вводят под давлением общественности законы о сокращении рабочего дня до шести часов.";
this.active = false;
this.countries = [];
this.excludedCountries = ["RU"];
}

activateEvent() {
Array.prototype.push.apply(this.excludedCountries, this.countries);
if (this.countries.length) {
Array.prototype.push.apply(
this.countries,
this.getRandomCountries(this.getRandom(3, 10))
);
} else {
this.countries = this.getRandomCountries(this.getRandom(3, 10));
}
}

getRandomCountries(qty) {
return WorldMap.countries
.map((country) => {
return country.id;
})
.filter((country) => !this.excludedCountries.includes(country))
.sort(() => 0.5 - Math.random())
.slice(0, qty);
}

getRandom(min, max) {
min = Math.ceil(min);
max = Math.floor(max);
return Math.floor(Math.random() * (max - min + 1)) + min;
}
}
1 change: 0 additions & 1 deletion src/models/scripts/Carbon.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ export default class Carbon {
new Date(),
new Date(today.setMonth(today.getMonth() - 1)),
].map((date) => {
console.log(date);
return (
date.getFullYear() + "-0" + (date.getMonth() + 1) + "-" + date.getDate()
);
Expand Down

0 comments on commit 61e07e7

Please sign in to comment.