From f78580d898a0cdafc0f73ae72157680c39638f93 Mon Sep 17 00:00:00 2001 From: pemcne Date: Wed, 27 Jun 2018 00:24:50 -0400 Subject: [PATCH 01/17] WIP for store layout and two markets --- src/App.vue | 14 +++-- src/components/Inventory.vue | 40 +++++++++++++ src/components/Market.vue | 29 ++------- src/main.js | 4 +- src/store/index.js | 111 ++++++++++++----------------------- 5 files changed, 91 insertions(+), 107 deletions(-) create mode 100644 src/components/Inventory.vue diff --git a/src/App.vue b/src/App.vue index 53ea126..f10c93a 100644 --- a/src/App.vue +++ b/src/App.vue @@ -1,21 +1,23 @@ diff --git a/src/components/Inventory.vue b/src/components/Inventory.vue new file mode 100644 index 0000000..64eb826 --- /dev/null +++ b/src/components/Inventory.vue @@ -0,0 +1,40 @@ + + + + + diff --git a/src/Engine.js b/src/Engine.js index 3b48f18..d78a113 100644 --- a/src/Engine.js +++ b/src/Engine.js @@ -25,7 +25,7 @@ export default { } }, tick () { - EventBus.$emit('tick') + EventBus.$emit('tick', TIMESCALE) this.clock.increment() }, start () { diff --git a/src/components/Inventory.vue b/src/components/Inventory.vue deleted file mode 100644 index 1171d3b..0000000 --- a/src/components/Inventory.vue +++ /dev/null @@ -1,51 +0,0 @@ - - - - - diff --git a/src/components/MarketInventory.vue b/src/components/MarketInventory.vue deleted file mode 100644 index 99f5e6f..0000000 --- a/src/components/MarketInventory.vue +++ /dev/null @@ -1,63 +0,0 @@ - - - diff --git a/src/components/Player.vue b/src/components/Player.vue deleted file mode 100644 index cdb5c63..0000000 --- a/src/components/Player.vue +++ /dev/null @@ -1,25 +0,0 @@ - - - diff --git a/src/components/Train.vue b/src/components/Train.vue deleted file mode 100644 index 9434586..0000000 --- a/src/components/Train.vue +++ /dev/null @@ -1,18 +0,0 @@ - - - diff --git a/src/view/components/Train.vue b/src/view/components/Train.vue new file mode 100644 index 0000000..8696a77 --- /dev/null +++ b/src/view/components/Train.vue @@ -0,0 +1,88 @@ + + + From 2b95a1311ea78dd7c4089fa458bab2d6a97bea8d Mon Sep 17 00:00:00 2001 From: pemcne Date: Thu, 12 Jul 2018 00:07:03 -0400 Subject: [PATCH 15/17] Returns the nested inventory objects with the train --- src/store/modules/trains.js | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/store/modules/trains.js b/src/store/modules/trains.js index 24928ae..ee85c6d 100644 --- a/src/store/modules/trains.js +++ b/src/store/modules/trains.js @@ -23,13 +23,19 @@ export default { } }, getters: { - getTrain: (state, getters, _, rootGetters) => trainId => state[trainId], - getTrainCars: (state, getters, rootState, rootGetters) => trainId => { - state[trainId].cars.map(i => { - const invId = state[i].inventory - const inv = rootGetters['inventory/getInventory'](invId) - return inv + getTrain: (state, getters, _, rootGetters) => trainId => { + //Get a copy of the train object from the state + let train = Object.assign({}, state[trainId]) + // For all of the cars, get the inventory object + train.cars = train.cars.map(i => { + const carInventory = state[i].inventory + const inventory = rootGetters['inventory/getInventory'](carInventory) + return { + name: i, + inventory + } }) + return train } }, actions: { From ddc84d4db34fe251f57ea779741879e4451814f3 Mon Sep 17 00:00:00 2001 From: pemcne Date: Thu, 12 Jul 2018 00:07:18 -0400 Subject: [PATCH 16/17] Shows the current status of the train --- src/view/components/Train.vue | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/view/components/Train.vue b/src/view/components/Train.vue index 8696a77..2bc54a0 100644 --- a/src/view/components/Train.vue +++ b/src/view/components/Train.vue @@ -1,6 +1,7 @@ @@ -57,19 +58,23 @@ export default { } // Get the new speed through de/acceleration console.log('rate', rate) - const speed = this.accelerate(rate, this.train.currentSpeed, scale) + let speed = this.accelerate(rate, this.train.currentSpeed, scale) + // Round it to the nearest two decimals + speed = +(speed).toFixed(2) // distance = speed * time const travelDistance = speed * scale // Copy the position object so we can modify it and pass it back let position = Object.assign({}, this.train.position) let station = this.train.atStation // Calculate the new distance to the station - position.distanceTo -= travelDistance + position.distanceTo = (position.distanceTo - travelDistance).toFixed(2) if (position.distanceTo <= 0) { + // Made it to the station so we can set everything to zero + position.distanceTo = 0 + speed = 0 console.log('Arrived!') station = true } - console.log(speed, position.distanceTo) // Finally update all the stats this.update({ trainId: this.trainId, From 1ba03ad1aadf2fea44fb2b4dae7c85e0853b2143 Mon Sep 17 00:00:00 2001 From: pemcne Date: Thu, 12 Jul 2018 20:46:53 -0400 Subject: [PATCH 17/17] Departures working --- src/store/modules/trains.js | 15 +++++++++++++-- src/view/components/Train.vue | 21 +++++++++++++++------ 2 files changed, 28 insertions(+), 8 deletions(-) diff --git a/src/store/modules/trains.js b/src/store/modules/trains.js index ee85c6d..039b90c 100644 --- a/src/store/modules/trains.js +++ b/src/store/modules/trains.js @@ -16,7 +16,12 @@ export default { destination: 'city1', source: 'city2' }, - atStation: false + atStation: false, + route: [ + 'city1', + 'city2' + ], + routeIndex: 0 }, 'train1-car1': { inventory: 'asdf' @@ -24,7 +29,7 @@ export default { }, getters: { getTrain: (state, getters, _, rootGetters) => trainId => { - //Get a copy of the train object from the state + // Get a copy of the train object from the state let train = Object.assign({}, state[trainId]) // For all of the cars, get the inventory object train.cars = train.cars.map(i => { @@ -56,6 +61,12 @@ export default { trainId, currentSpeed }) + }, + depart ({commit}, {trainId}) { + commit('UPDATE_STATION', { + trainId, + atStation: false + }) } }, mutations: { diff --git a/src/view/components/Train.vue b/src/view/components/Train.vue index 2bc54a0..881ce78 100644 --- a/src/view/components/Train.vue +++ b/src/view/components/Train.vue @@ -1,7 +1,9 @@ @@ -24,8 +26,14 @@ export default { }, methods: { ...mapActions([ - 'update' + 'update', + 'depart' ]), + departStation (event) { + this.depart({ + trainId: this.trainId + }) + }, accelerate (rate, initial, time) { let speed speed = (rate * time) + initial @@ -50,14 +58,11 @@ export default { // First see if we need to accelerate let rate if (this.doAccelerate(this.train.deceleration, this.train.position.distanceTo, this.train.currentSpeed)) { - console.log('accelerating') rate = this.train.acceleration } else { - console.log('decelerating') rate = this.train.deceleration } // Get the new speed through de/acceleration - console.log('rate', rate) let speed = this.accelerate(rate, this.train.currentSpeed, scale) // Round it to the nearest two decimals speed = +(speed).toFixed(2) @@ -70,10 +75,14 @@ export default { position.distanceTo = (position.distanceTo - travelDistance).toFixed(2) if (position.distanceTo <= 0) { // Made it to the station so we can set everything to zero - position.distanceTo = 0 speed = 0 console.log('Arrived!') station = true + position = { + distanceTo: 300, + destination: 'city2', + source: 'city1' + } } // Finally update all the stats this.update({