parent
							
								
									4bc4af553e
								
							
						
					
					
						commit
						7024fb4402
					
				@ -0,0 +1,11 @@ | 
				
			|||||||
 | 
					package mightypork.gamecore.core.config; | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import mightypork.utils.files.config.PropertyManager; | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/** | 
				
			||||||
 | 
					 * Config setup, class used to populate the config file. | 
				
			||||||
 | 
					 */ | 
				
			||||||
 | 
					public interface ConfigSetup { | 
				
			||||||
 | 
						 | 
				
			||||||
 | 
						void addOptions(PropertyManager prop); | 
				
			||||||
 | 
					} | 
				
			||||||
@ -0,0 +1,28 @@ | 
				
			|||||||
 | 
					package mightypork.gamecore.core.config; | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import mightypork.gamecore.input.KeyStroke; | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/** | 
				
			||||||
 | 
					 * Key options - restricted access to {@link Config} for keys | 
				
			||||||
 | 
					 */ | 
				
			||||||
 | 
					public class KeyOpts { | 
				
			||||||
 | 
						 | 
				
			||||||
 | 
						 | 
				
			||||||
 | 
						public void add(String cfgKey, String dataString) | 
				
			||||||
 | 
						{ | 
				
			||||||
 | 
							add(cfgKey, dataString, null); | 
				
			||||||
 | 
						} | 
				
			||||||
 | 
						 | 
				
			||||||
 | 
						 | 
				
			||||||
 | 
						/** | 
				
			||||||
 | 
						 * @param cfgKey key in config file | 
				
			||||||
 | 
						 * @param dataString string representing the keystroke (format for {@link KeyStroke}) | 
				
			||||||
 | 
						 * @param comment optional comment | 
				
			||||||
 | 
						 */ | 
				
			||||||
 | 
						public void add(String cfgKey, String dataString, String comment) | 
				
			||||||
 | 
						{ | 
				
			||||||
 | 
							final KeyProperty kprop = new KeyProperty(Config.prefixKey(cfgKey), KeyStroke.createFromDataString(dataString), comment); | 
				
			||||||
 | 
							Config.strokes.put(Config.prefixKey(cfgKey), kprop); | 
				
			||||||
 | 
							Config.cfg.putProperty(kprop); | 
				
			||||||
 | 
						} | 
				
			||||||
 | 
					} | 
				
			||||||
@ -0,0 +1,53 @@ | 
				
			|||||||
 | 
					package mightypork.gamecore.core.config; | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import mightypork.gamecore.input.KeyStroke; | 
				
			||||||
 | 
					import mightypork.gamecore.input.Keys; | 
				
			||||||
 | 
					import mightypork.utils.files.config.Property; | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/** | 
				
			||||||
 | 
					 * Key property.<br> | 
				
			||||||
 | 
					 * The stored value must be invariant ({@link KeyStroke} is mutable). | 
				
			||||||
 | 
					 *  | 
				
			||||||
 | 
					 * @author Ondřej Hruška (MightyPork) | 
				
			||||||
 | 
					 */ | 
				
			||||||
 | 
					public class KeyProperty extends Property<KeyStroke> { | 
				
			||||||
 | 
						 | 
				
			||||||
 | 
						public KeyProperty(String key, KeyStroke defaultValue, String comment) | 
				
			||||||
 | 
						{ | 
				
			||||||
 | 
							super(key, defaultValue, comment); | 
				
			||||||
 | 
						} | 
				
			||||||
 | 
						 | 
				
			||||||
 | 
						 | 
				
			||||||
 | 
						@Override | 
				
			||||||
 | 
						public KeyStroke decode(String string, KeyStroke defval) | 
				
			||||||
 | 
						{ | 
				
			||||||
 | 
							if (string != null) { | 
				
			||||||
 | 
								// keep it invariant
 | 
				
			||||||
 | 
								 | 
				
			||||||
 | 
								final int backup_key = getValue().getKey(); | 
				
			||||||
 | 
								final int backup_mod = getValue().getMod(); | 
				
			||||||
 | 
								 | 
				
			||||||
 | 
								getValue().fromDataString(string); | 
				
			||||||
 | 
								if (getValue().getKey() == Keys.NONE) { | 
				
			||||||
 | 
									getValue().setTo(backup_key, backup_mod); | 
				
			||||||
 | 
								} | 
				
			||||||
 | 
							} | 
				
			||||||
 | 
							 | 
				
			||||||
 | 
							return getValue(); | 
				
			||||||
 | 
						} | 
				
			||||||
 | 
						 | 
				
			||||||
 | 
						 | 
				
			||||||
 | 
						@Override | 
				
			||||||
 | 
						public String encode(KeyStroke value) | 
				
			||||||
 | 
						{ | 
				
			||||||
 | 
							return value.toDataString(); | 
				
			||||||
 | 
						} | 
				
			||||||
 | 
						 | 
				
			||||||
 | 
						 | 
				
			||||||
 | 
						@Override | 
				
			||||||
 | 
						public void setValue(Object value) | 
				
			||||||
 | 
						{ | 
				
			||||||
 | 
							// keep it invariant
 | 
				
			||||||
 | 
							getValue().setTo(((KeyStroke) value).getKey(), ((KeyStroke) value).getMod()); | 
				
			||||||
 | 
						} | 
				
			||||||
 | 
					} | 
				
			||||||
@ -0,0 +1,10 @@ | 
				
			|||||||
 | 
					package mightypork.gamecore.core.config; | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/** | 
				
			||||||
 | 
					 * Key configurator. Config access restricted to key options. | 
				
			||||||
 | 
					 */ | 
				
			||||||
 | 
					public interface KeySetup { | 
				
			||||||
 | 
						 | 
				
			||||||
 | 
						public void addKeys(KeyOpts keys); | 
				
			||||||
 | 
					} | 
				
			||||||
					Loading…
					
					
				
		Reference in new issue