2025-02-24 16:08:22 -05:00
|
|
|
package noppes.npcs.attribute;
|
|
|
|
|
|
|
|
|
|
import java.util.Collection;
|
|
|
|
|
import java.util.HashMap;
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
|
|
/**
|
2025-02-24 20:07:32 -05:00
|
|
|
* AttributeController is the central registry for attribute definitions.
|
|
|
|
|
* It ensures that keys are unique.
|
2025-02-24 16:08:22 -05:00
|
|
|
*/
|
|
|
|
|
public class AttributeController {
|
2025-02-26 12:51:22 -05:00
|
|
|
|
|
|
|
|
public AttributeController Instance;
|
|
|
|
|
public ModAttributes attributes;
|
|
|
|
|
|
2025-02-24 16:08:22 -05:00
|
|
|
private static final Map<String, AttributeDefinition> definitions = new HashMap<>();
|
|
|
|
|
|
2025-02-26 12:51:22 -05:00
|
|
|
public AttributeController(){
|
|
|
|
|
this.Instance = this;
|
|
|
|
|
definitions.clear();
|
|
|
|
|
attributes = new ModAttributes();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2025-02-24 20:07:32 -05:00
|
|
|
public static AttributeDefinition registerAttribute(String key, String displayName, AttributeValueType valueType) {
|
2025-02-24 16:08:22 -05:00
|
|
|
if (definitions.containsKey(key)) {
|
2025-02-24 20:07:32 -05:00
|
|
|
throw new IllegalArgumentException("Attribute already registered with key: " + key);
|
2025-02-24 16:08:22 -05:00
|
|
|
}
|
2025-02-24 20:07:32 -05:00
|
|
|
AttributeDefinition def = new AttributeDefinition(key, displayName, valueType);
|
2025-02-24 16:08:22 -05:00
|
|
|
definitions.put(key, def);
|
|
|
|
|
return def;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static AttributeDefinition getAttribute(String key) {
|
|
|
|
|
return definitions.get(key);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static Collection<AttributeDefinition> getAllAttributes() {
|
|
|
|
|
return definitions.values();
|
|
|
|
|
}
|
|
|
|
|
}
|