Skip to content

Commit

Permalink
1.4.2 fixes state persistence
Browse files Browse the repository at this point in the history
  • Loading branch information
kagof committed Jan 24, 2021
1 parent ce33a0c commit ca89000
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 69 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ plugins {
}

group = "com.kagof"
version = "1.4.1"
version = "1.4.2"

repositories {
mavenCentral()
Expand Down
7 changes: 6 additions & 1 deletion changenotes.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
<ul>
<li><b><a href="https://github.com/kagof/intellij-pokemon-progress/releases/tag/1.4.1"></a></b>
<li><b><a href="https://github.com/kagof/intellij-pokemon-progress/releases/tag/1.4.1">1.4.2</a></b>
<ul>
<li>Yet another fix for configuration state persistence</li>
</ul>
</li>
<li><b><a href="https://github.com/kagof/intellij-pokemon-progress/releases/tag/1.4.1">1.4.1</a></b>
<ul>
<li>Fixes issue with config state deserialization (thanks @TheFreezingChicken for the bug report)</li>
</ul>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public static Pokemon get() {
}

private static List<String> getEnabledPokemonNumbers(final PokemonProgressState state) {
return state.getPokemonNumbersEnabled().entrySet().stream().filter(Map.Entry::getValue).map(Map.Entry::getKey).collect(Collectors.toList());
return state.pokemonNumbersEnabled.entrySet().stream().filter(Map.Entry::getValue).map(Map.Entry::getKey).collect(Collectors.toList());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public class PokemonProgressBarUi extends BasicProgressBarUI {
private volatile float velocity = 0;

public PokemonProgressBarUi(final Pokemon pokemon) {
this(pokemon, () -> PokemonProgressState.getInstance().getInitialVelocity(), () -> PokemonProgressState.getInstance().getAcceleration());
this(pokemon, () -> PokemonProgressState.getInstance().initialVelocity, () -> PokemonProgressState.getInstance().acceleration);
}

public PokemonProgressBarUi(final Pokemon pokemon, final Supplier<Float> initialVelocity, final Supplier<Float> acceleration) {
Expand Down Expand Up @@ -180,7 +180,7 @@ private void drawTypePaint(final int height, final int progress, final Graphics2
}

private void setToolTipText() {
if (PokemonProgressState.getInstance().isAddToolTips() && StringUtil.isEmptyOrSpaces(progressBar.getToolTipText())) {
if (PokemonProgressState.getInstance().addToolTips && StringUtil.isEmptyOrSpaces(progressBar.getToolTipText())) {
progressBar.setToolTipText(pokemon.getNameWithNumber());
}
}
Expand All @@ -198,7 +198,7 @@ private void drawBorder(final RoundRectangle2D rectangle, final Graphics2D graph
}

private void drawPokemonIcon(final int amountFull, final Graphics2D graphics2D, final Shape clip) {
if (!PokemonProgressState.getInstance().isDrawSprites()) {
if (!PokemonProgressState.getInstance().drawSprites) {
return;
}
final Shape previousClip = graphics2D.getClip();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,21 @@ public JComponent createComponent() {
@Override
public boolean isModified() {
final PokemonProgressState state = PokemonProgressState.getInstance();
return component != null && (!state.getPokemonNumbersEnabled().equals(component.getEnabledNumberMap())
|| state.isDrawSprites() != component.getDrawSprites().isSelected()
|| state.isAddToolTips() != component.getAddToolTips().isSelected()
|| state.getInitialVelocity() != component.getInitialVelocity().getValue() / 100f
|| state.getAcceleration() != component.getAcceleration().getValue() / 100f);
return component != null && (!state.pokemonNumbersEnabled.equals(component.getEnabledNumberMap())
|| state.drawSprites != component.getDrawSprites().isSelected()
|| state.addToolTips != component.getAddToolTips().isSelected()
|| state.initialVelocity != component.getInitialVelocity().getValue() / 100f
|| state.acceleration != component.getAcceleration().getValue() / 100f);
}

@Override
public void apply() {
final PokemonProgressState state = PokemonProgressState.getInstance();
state.setPokemonNumbersEnabled(component.getEnabledNumberMap());
state.setDrawSprites(component.getDrawSprites().isSelected());
state.setAddToolTips(component.getAddToolTips().isSelected());
state.setInitialVelocity(component.getInitialVelocity().getValue() / 100f);
state.setAcceleration(component.getAcceleration().getValue() / 100f);
state.pokemonNumbersEnabled = component.getEnabledNumberMap();
state.drawSprites = component.getDrawSprites().isSelected();
state.addToolTips = component.getAddToolTips().isSelected();
state.initialVelocity = component.getInitialVelocity().getValue() / 100f;
state.acceleration = component.getAcceleration().getValue() / 100f;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,11 @@ void createUi() {

void updateUi(final PokemonProgressState state) {
if (state != null) {
initialVelocity.setValue((int) (state.getInitialVelocity() * 100));
acceleration.setValue((int) (state.getAcceleration() * 100));
drawSprites.setSelected(state.isDrawSprites());
addToolTips.setSelected(state.isAddToolTips());
state.getPokemonNumbersEnabled()
initialVelocity.setValue((int) (state.initialVelocity * 100));
acceleration.setValue((int) (state.acceleration * 100));
drawSprites.setSelected(state.drawSprites);
addToolTips.setSelected(state.addToolTips);
state.pokemonNumbersEnabled
.forEach((pokemon, enabled) -> checkboxes.computeIfPresent(pokemon, (p, check) -> {
check.setSelected(enabled);
return check;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.kagof.intellij.plugins.pokeprogress.configuration;

import java.util.HashMap;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;
Expand All @@ -19,12 +18,12 @@
storages = {@Storage("PokemonProgress.xml")}
)
public class PokemonProgressState implements PersistentStateComponent<PokemonProgressState> {
private float initialVelocity = 1.0f;
private float acceleration = 0.4f;
private Map<String, Boolean> pokemonNumbersEnabled = Pokemon.DEFAULT_POKEMON.keySet().stream()
public float initialVelocity = 1.0f;
public float acceleration = 0.4f;
public Map<String, Boolean> pokemonNumbersEnabled = Pokemon.DEFAULT_POKEMON.keySet().stream()
.collect(Collectors.toMap(Function.identity(), p -> true));
private boolean drawSprites = true;
private boolean addToolTips = true;
public boolean drawSprites = true;
public boolean addToolTips = true;

public static PokemonProgressState getInstance() {
return ServiceManager.getService(PokemonProgressState.class);
Expand All @@ -38,45 +37,7 @@ public PokemonProgressState getState() {
@Override
public void loadState(@NotNull final PokemonProgressState state) {
XmlSerializerUtil.copyBean(state, this);
}

public float getInitialVelocity() {
return initialVelocity;
}

public void setInitialVelocity(final float initialVelocity) {
this.initialVelocity = initialVelocity;
}

public float getAcceleration() {
return acceleration;
}

public void setAcceleration(final float acceleration) {
this.acceleration = acceleration;
}

public Map<String, Boolean> getPokemonNumbersEnabled() {
return new HashMap<>(pokemonNumbersEnabled);
}

public void setPokemonNumbersEnabled(final Map<String, Boolean> pokemonNumbersEnabled) {
this.pokemonNumbersEnabled = pokemonNumbersEnabled;
}

public boolean isDrawSprites() {
return drawSprites;
}

public void setDrawSprites(final boolean drawSprites) {
this.drawSprites = drawSprites;
}

public boolean isAddToolTips() {
return addToolTips;
}

public void setAddToolTips(final boolean addToolTips) {
this.addToolTips = addToolTips;
System.out.print("loading state: ");
System.out.println(this);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ public TestProgressBar() {

private void setUpMockApplication() {
final PokemonProgressState state = new PokemonProgressState();
state.setDrawSprites(true);
state.setAddToolTips(false);
state.drawSprites = true;
state.addToolTips = false;
final Disposable parent = () -> { /*do nothing*/ };
final MockApplication application = MockApplication.setUp(parent);
application.registerService(PokemonProgressState.class, state);
Expand Down

0 comments on commit ca89000

Please sign in to comment.