Skip to content

Commit

Permalink
* Updated BuildCarrier and ShipTransfer components:
Browse files Browse the repository at this point in the history
    - Added functionality to ensure that the values of starShips and carrierShips are parsed ints.  This fixes the issue where, if the user entered a manual value for the number of ships, subsequent use of the ship transfer buttons would appear to append the values the numbers were supposed to be adding to the ships as a string, instead of adding them like numbers.
    - Prevented the modals from allowing the user to submit the panel when 0 ships are assigned to the carrier.  This fixes the issue where, if the user entered a value of 0 for the number of carrier ships, the Transfer/Build buttons would still be clickable but nothing would happen.
    - Updated to respond immediately to user input to allow for a smoother experience when specifying the number of ships to be transferred.
* Updated LedgerRow component to use the correct property in the response object to assign to the value of ledger.debt.  This fixes the issue where ledger row would sometimes show $undefined instead of the debt value when settling or forgiving debt.
* Updated SelectAlias (and EnterPassword, for consistency) component to use `@change` for handling input events instead of v-on:keyup.  This fixes that pesky issue where, when joining a game from a phone (eg an Android phone), if you had a name with spaces, the game would sometimes not pick up the part after the last space.  There's no keyup event for it to pick up, so it would only pick up changes when there were spaces.
  • Loading branch information
Metritutus committed Mar 4, 2024
1 parent cbf2275 commit d47b380
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 20 deletions.
26 changes: 19 additions & 7 deletions client/src/views/game/components/carrier/BuildCarrier.vue
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@

<div class="row mb-1">
<div class="col">
<input v-model.lazy="starShips" type="number" class="form-control" @change="onStarShipsChanged">
<input v-model="starShips" type="number" class="form-control" @input="onStarShipsChanged">
</div>
<div class="col">
<input v-model.lazy="carrierShips" type="number" class="form-control" @change="onCarrierShipsChanged">
<input v-model="carrierShips" type="number" class="form-control" @input="onCarrierShipsChanged">
</div>
</div>

Expand Down Expand Up @@ -67,7 +67,7 @@
</div>
<div class="col-auto">
<div class="d-grid gap-2">
<button type="button" class="btn btn-info" :disabled="$isHistoricalMode() || isBuildingCarrier || starShips < 0 || carrierShips < 0" @click="saveTransfer">
<button type="button" class="btn btn-info" :disabled="$isHistoricalMode() || isBuildingCarrier || starShips < 0 || carrierShips < 1" @click="saveTransfer">
<i class="fas fa-rocket"></i>
Build for ${{star.upgradeCosts.carriers}}
</button>
Expand Down Expand Up @@ -108,12 +108,24 @@ export default {
onCloseRequested (e) {
this.$emit('onCloseRequested', e)
},
onStarShipsChanged (e) {
let difference = parseInt(this.starShips) - this.star.ships
onStarShipsChanged(e) {
this.starShips = parseInt(this.starShips);
if (isNaN(this.starShips)) {
this.starShips = 0;
}
let difference = this.starShips - this.star.ships
this.carrierShips = Math.abs(difference)
},
onCarrierShipsChanged (e) {
let difference = parseInt(this.carrierShips)
onCarrierShipsChanged(e) {
this.carrierShips = parseInt(this.carrierShips);
if (isNaN(this.carrierShips)) {
this.carrierShips = 1;
}
let difference = this.carrierShips;
this.starShips = this.star.ships - difference
},
onMinShipsClicked (e) {
Expand Down
30 changes: 21 additions & 9 deletions client/src/views/game/components/carrier/ShipTransfer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@

<div class="row mb-1">
<div class="col">
<input v-model.lazy="starShips" type="number" class="form-control" @change="onStarShipsChanged">
<input v-model="starShips" type="number" class="form-control" @input="onStarShipsChanged">
</div>
<div class="col">
<input v-model.lazy="carrierShips" type="number" class="form-control" @change="onCarrierShipsChanged">
<input v-model="carrierShips" type="number" class="form-control" @input="onCarrierShipsChanged">
</div>
</div>

Expand Down Expand Up @@ -68,7 +68,7 @@
<div class="col-6"></div>
<div class="col pe-0">
<div class="d-grid gap-2">
<button type="button" class="btn btn-success me-1" :disabled="$isHistoricalMode() || isTransferringShips || starShips < 0 || carrierShips < 0" @click="saveTransfer">
<button type="button" class="btn btn-success me-1" :disabled="$isHistoricalMode() || isTransferringShips || starShips < 0 || carrierShips < 1" @click="saveTransfer">
<i class="fas fa-check"></i>
Transfer
</button>
Expand Down Expand Up @@ -150,12 +150,24 @@ export default {
this.onStarShipsChanged()
}
},
onStarShipsChanged (e) {
let difference = parseInt(this.starShips) - this.star.ships
onStarShipsChanged(e) {
this.starShips = parseInt(this.starShips);
if (isNaN(this.starShips)) {
this.starShips = 0;
}
let difference = this.starShips - this.star.ships
this.carrierShips = this.carrier.ships - difference
},
onCarrierShipsChanged (e) {
let difference = parseInt(this.carrierShips) - this.carrier.ships
onCarrierShipsChanged(e) {
this.carrierShips = parseInt(this.carrierShips);
if (isNaN(this.carrierShips)) {
this.carrierShips = 1;
}
let difference = this.carrierShips - this.carrier.ships
this.starShips = this.star.ships - difference
},
onMinShipsClicked (e) {
Expand Down Expand Up @@ -194,8 +206,8 @@ export default {
try {
this.isTransferringShips = true
let cShips = parseInt(this.carrierShips)
let sShips = parseInt(this.starShips)
let cShips = this.carrierShips;
let sShips = this.starShips;
let response = await CarrierApiService.transferShips(
this.$store.state.game._id,
Expand Down
4 changes: 2 additions & 2 deletions client/src/views/game/components/ledger/LedgerRow.vue
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export default {
this.$toasted.show(`The debt ${playerAlias} owes you has been forgiven.`, { type: 'success' })
}
ledger.debt = response.data.debt
ledger.debt = response.data.ledger.debt
} catch (err) {
console.error(err)
}
Expand Down Expand Up @@ -89,7 +89,7 @@ export default {
gameHelper.getUserPlayer(this.$store.state.game).ledger.creditsSpecialists -= Math.abs(ledger.debt)
}
ledger.debt = response.data.debt
ledger.debt = response.data.ledger.debt;
} catch (err) {
console.error(err)
}
Expand Down
2 changes: 1 addition & 1 deletion client/src/views/game/components/welcome/EnterPassword.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<div class="col">
<form @submit.prevent>
<div class="mb-2 mt-3">
<input class="form-control" required="required" placeholder="Password" type="password" v-model="password" v-on:keyup="onPasswordChanged">
<input class="form-control" required="required" placeholder="Password" type="password" v-model="password" @change="onPasswordChanged">
</div>
</form>
</div>
Expand Down
2 changes: 1 addition & 1 deletion client/src/views/game/components/welcome/SelectAlias.vue
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<p v-if="avatar"><small class="linebreaks">{{avatar.description}}</small></p>

<div class="mb-2">
<input name="alias" class="form-control" required="required" placeholder="Enter your alias here" type="text" minlength="3" maxlength="24" v-model="alias" v-on:keyup="onAliasChanged">
<input name="alias" class="form-control" required="required" placeholder="Enter your alias here" type="text" minlength="3" maxlength="24" v-model="alias" @change="onAliasChanged">
</div>

<!-- <div class="mb-2 text-center small">
Expand Down

0 comments on commit d47b380

Please sign in to comment.