aboutsummaryrefslogtreecommitdiff
path: root/diplomacy/web/src/gui
diff options
context:
space:
mode:
authornotoraptor <notoraptor@users.noreply.github.com>2019-07-18 14:48:29 -0400
committerPhilip Paquette <pcpaquette@gmail.com>2019-07-18 14:48:29 -0400
commit33105a895a0b3c2b266c66058f5a8ec930c88504 (patch)
tree76910adfc65c30e199e48785b5721291339dbd29 /diplomacy/web/src/gui
parentf8ee5f84abc5c9d0d56402f2943abad1dc74d3dd (diff)
Reset local orders for a power if we receive a power orders update.
- Does not allow to join a power which is eliminated. - When clicking on "reset", reset local orders only for current selected power.
Diffstat (limited to 'diplomacy/web/src/gui')
-rw-r--r--diplomacy/web/src/gui/forms/power_order_creation_form.jsx2
-rw-r--r--diplomacy/web/src/gui/pages/content_game.jsx39
2 files changed, 31 insertions, 10 deletions
diff --git a/diplomacy/web/src/gui/forms/power_order_creation_form.jsx b/diplomacy/web/src/gui/forms/power_order_creation_form.jsx
index f15fff8..346a5bf 100644
--- a/diplomacy/web/src/gui/forms/power_order_creation_form.jsx
+++ b/diplomacy/web/src/gui/forms/power_order_creation_form.jsx
@@ -55,7 +55,7 @@ export class PowerOrderCreationForm extends React.Component {
)));
header.push(Forms.createReset('reset', false, onReset));
} else if (this.props.power.order_is_set) {
- title = 'Unorderable power (already locked on server).';
+ title = 'Unorderable power.';
titleClass += ' neutral';
} else {
title = 'No orders available for this power.';
diff --git a/diplomacy/web/src/gui/pages/content_game.jsx b/diplomacy/web/src/gui/pages/content_game.jsx
index 7e7c7e9..2941b6b 100644
--- a/diplomacy/web/src/gui/pages/content_game.jsx
+++ b/diplomacy/web/src/gui/pages/content_game.jsx
@@ -363,7 +363,7 @@ export class ContentGame extends React.Component {
.catch(error => this.getPage().error('Error when updating possible orders: ' + error.toString()));
}
- notifiedLocalStateChange(networkGame) {
+ notifiedLocalStateChange(networkGame, notification) {
networkGame.getAllPossibleOrders()
.then(allPossibleOrders => {
networkGame.local.setPossibleOrders(allPossibleOrders);
@@ -373,6 +373,9 @@ export class ContentGame extends React.Component {
<ContentGame data={networkGame.local}/>,
{info: `Possible orders re-loaded.`}
);
+ if (notification.power_name) {
+ this.reloadPowerServerOrders(notification.power_name);
+ }
this.reloadDeadlineTimer(networkGame);
}
})
@@ -403,8 +406,8 @@ export class ContentGame extends React.Component {
networkGame.addOnGamePhaseUpdate(this.notifiedGamePhaseUpdated);
networkGame.addOnGameStatusUpdate(this.notifiedNetworkGame);
networkGame.addOnOmniscientUpdated(this.notifiedNetworkGame);
- networkGame.addOnPowerOrdersUpdate(this.notifiedNetworkGame);
- networkGame.addOnPowerOrdersFlag(this.notifiedNetworkGame);
+ networkGame.addOnPowerOrdersUpdate(this.notifiedLocalStateChange);
+ networkGame.addOnPowerOrdersFlag(this.notifiedLocalStateChange);
networkGame.addOnPowerVoteUpdated(this.notifiedNetworkGame);
networkGame.addOnPowerWaitFlag(this.notifiedNetworkGame);
networkGame.addOnVoteCountUpdated(this.notifiedNetworkGame);
@@ -530,13 +533,30 @@ export class ContentGame extends React.Component {
}
/**
- * Reset local orders and replace them with current server orders.
+ * Reset local orders and replace them with current server orders for given power.
+ * @param {string} powerName - name of power to update
*/
- reloadServerOrders() {
- // TODO: This method should reset orders to server version only for current powers, not for all powers as she currently does.
+ reloadPowerServerOrders(powerName) {
const serverOrders = this.props.data.getServerOrders();
- this.__store_orders(serverOrders);
- this.setState({orders: serverOrders});
+ const engine = this.props.data;
+ const allOrders = this.__get_orders(engine);
+ if (!allOrders.hasOwnProperty(powerName)) {
+ this.getPage().error(`Unknown power ${powerName}.`);
+ return;
+ }
+ allOrders[powerName] = serverOrders[powerName];
+ this.__store_orders(allOrders);
+ this.setState({orders: allOrders});
+ }
+
+ /**
+ * Reset local orders and replace them with current server orders for current selected power.
+ */
+ reloadServerOrders() {
+ const currentPowerName = this.getCurrentPowerName();
+ if (currentPowerName) {
+ this.reloadPowerServerOrders(currentPowerName);
+ }
}
/**
@@ -558,7 +578,8 @@ export class ContentGame extends React.Component {
}
/**
- * Remove all local orders for current selected power
+ * Remove all local orders for current selected power, including empty orders set.
+ * Equivalent request is clearOrders().
*/
onRemoveAllCurrentPowerOrders() {
const currentPowerName = this.getCurrentPowerName();