From fccd9b999ba9afbca9b480efb6ee39fe63bb86a0 Mon Sep 17 00:00:00 2001 From: Artus Date: Wed, 31 Jul 2019 15:11:51 +0200 Subject: [PATCH] Starts refactor using a PlayerView renderless component for Player logic --- lootalot_front/package.json | 7 +- lootalot_front/src/App.vue | 26 +++- lootalot_front/src/AppStorage.js | 5 +- lootalot_front/src/components/HeaderBar.vue | 52 ++++++++ lootalot_front/src/components/Player.vue | 124 ------------------ lootalot_front/src/components/PlayerView.js | 32 +++++ lootalot_front/src/components/Wealth.vue | 18 ++- .../src/components/tests/NumberInput.spec.js | 18 +++ 8 files changed, 139 insertions(+), 143 deletions(-) create mode 100644 lootalot_front/src/components/HeaderBar.vue delete mode 100644 lootalot_front/src/components/Player.vue create mode 100644 lootalot_front/src/components/PlayerView.js create mode 100644 lootalot_front/src/components/tests/NumberInput.spec.js diff --git a/lootalot_front/package.json b/lootalot_front/package.json index 9e028e0..18f9bec 100644 --- a/lootalot_front/package.json +++ b/lootalot_front/package.json @@ -62,8 +62,11 @@ "vue" ], "transform": { - ".*\\.(vue)$": "vue-jest", - "^.+\\.js$": "/node_modules/babel-jest" + "^.*\\.(vue)$": "vue-jest", + "^.+\\.js$": "babel-jest" + }, + "moduleNameMapper": { + "^@/(.*)$": "/src/$1" } } } diff --git a/lootalot_front/src/App.vue b/lootalot_front/src/App.vue index d4b8da6..6382c79 100644 --- a/lootalot_front/src/App.vue +++ b/lootalot_front/src/App.vue @@ -1,11 +1,25 @@ diff --git a/lootalot_front/src/components/Player.vue b/lootalot_front/src/components/Player.vue deleted file mode 100644 index 733c8f6..0000000 --- a/lootalot_front/src/components/Player.vue +++ /dev/null @@ -1,124 +0,0 @@ - - - - - diff --git a/lootalot_front/src/components/PlayerView.js b/lootalot_front/src/components/PlayerView.js new file mode 100644 index 0000000..c88ec39 --- /dev/null +++ b/lootalot_front/src/components/PlayerView.js @@ -0,0 +1,32 @@ +import { AppStorage } from '../AppStorage' + +export default { + props: ["id"], + data () { return {}}, + methods: { + updateWealth (value) { + AppStorage.updatePlayerWealth(value) + .then(_ => {if (AppStorage.debug) console.log("Wealth updated")}) + .catch(e => {if (AppStorage.debug) console.error("wealthUpdate Error", e)}) + } + }, + computed: { + player () { + if (!AppStorage.state.initiated) { + return { name: "Loading", + id: 0, + cp: '-', sp: '-', gp: '-', pp: '-', + debt: 0 }; + } else { + console.log("Update player"); + return AppStorage.state.player_list[this.id]; + } + } + }, + render () { + return this.$scopedSlots.default({ + player: this.player, + updateWealth: this.updateWealth, + }) + } +} diff --git a/lootalot_front/src/components/Wealth.vue b/lootalot_front/src/components/Wealth.vue index a80f60a..ffc18ce 100644 --- a/lootalot_front/src/components/Wealth.vue +++ b/lootalot_front/src/components/Wealth.vue @@ -2,12 +2,11 @@
- - - + + +
-