Skip to content

Commit

Permalink
Adds compatibility code for adding 75% scaling options to stored clie…
Browse files Browse the repository at this point in the history
…nt options.
  • Loading branch information
stiangre committed Dec 27, 2023
1 parent c95425a commit 7e83f0c
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/net/sf/freecol/client/ClientOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -876,6 +876,10 @@ public void fixClientOptions() {
// end @compat 0.13.0
// @compat 1.1.0
remove("model.option.mapControls");
final RangeOption op = getOption(DISPLAY_SCALING, RangeOption.class);
if (!op.getItemValues().containsKey(75)) {
op.setItemValueAtIndex(1, 75, "model.option.displayScaling.75");
}
// end @compat 1.1.0
}

Expand Down
28 changes: 27 additions & 1 deletion src/net/sf/freecol/common/option/SelectOption.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,18 @@

package net.sf.freecol.common.option;

import static net.sf.freecol.common.model.Constants.INFINITY;

import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.logging.Logger;

import javax.xml.stream.XMLStreamException;

import net.sf.freecol.common.io.FreeColXMLReader;
import net.sf.freecol.common.io.FreeColXMLWriter;
import static net.sf.freecol.common.model.Constants.*;
import net.sf.freecol.common.model.Specification;


Expand Down Expand Up @@ -106,6 +108,30 @@ public Map<Integer, String> getItemValues() {
public void addItemValue(Integer key, String value) {
itemValues.put(key, value);
}

/**
* Add a new key,value pair to this option at the given index.
*
* @param index The index in the list of item values.
* @param key The key to add.
* @param value The value to add.
*/
public void setItemValueAtIndex(int index, Integer key, String value) {
final LinkedHashMap<Integer, String> oldItemValues = new LinkedHashMap<>(itemValues);

itemValues.clear();
int currentIndex = 0;
for (Entry<Integer, String> entry : oldItemValues.entrySet()) {
if (index == currentIndex) {
itemValues.put(key, value);
}
itemValues.put(entry.getKey(), entry.getValue());
currentIndex++;
}
if (index >= itemValues.size()) {
itemValues.put(key, value);
}
}

/**
* Clear the item values for this option.
Expand Down

0 comments on commit 7e83f0c

Please sign in to comment.