Rogue: Savage Rats, a retro-themed dungeon crawler
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
rogue-savage-rats/src/mightypork/gamecore/core/config/KeyStrokeProperty.java

54 lines
1.2 KiB

package mightypork.gamecore.core.config;
import mightypork.gamecore.input.KeyStroke;
import mightypork.gamecore.input.Keys;
import mightypork.utils.config.propmgr.Property;
/**
* Key property.<br>
* The stored value must stay the same instance ({@link KeyStroke} is mutable).<br>
* That ensures that bindings based on this keystroke are automatically updated
* when the settings change.
*
* @author Ondřej Hruška (MightyPork)
*/
public class KeyStrokeProperty extends Property<KeyStroke> {
public KeyStrokeProperty(String key, KeyStroke defaultValue, String comment) {
super(key, defaultValue, comment);
}
@Override
public void fromString(String string)
{
if (string != null) {
// keep the same instance
final int backup_key = value.getKey();
final int backup_mod = value.getMod();
value.fromDataString(string);
if (value.getKey() == Keys.NONE) {
value.setTo(backup_key, backup_mod);
}
}
}
@Override
public String toString()
{
return value.toDataString();
}
@Override
public void setValue(Object value)
{
// keep the same instance
this.value.setTo(((KeyStroke) value).getKey(), ((KeyStroke) value).getMod());
}
}