initial commit
This commit is contained in:
parent
3c9ee26b06
commit
22186c33b9
1458 changed files with 282792 additions and 0 deletions
84
java/src/game/entity/attributes/Attribute.java
Executable file
84
java/src/game/entity/attributes/Attribute.java
Executable file
|
@ -0,0 +1,84 @@
|
|||
package game.entity.attributes;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import game.ExtMath;
|
||||
import game.collect.Maps;
|
||||
|
||||
public class Attribute
|
||||
{
|
||||
private static final Map<String, Attribute> ATTRIBUTES = Maps.newHashMap();
|
||||
|
||||
private final String name;
|
||||
private final String display;
|
||||
private final double defValue;
|
||||
private final double minValue;
|
||||
private final double maxValue;
|
||||
private final boolean shouldWatch;
|
||||
|
||||
public static Attribute getAttribute(String name) {
|
||||
return ATTRIBUTES.get(name);
|
||||
}
|
||||
|
||||
public Attribute(String name, String display, double def, double min, double max, boolean watch)
|
||||
{
|
||||
this.name = name;
|
||||
this.display = display;
|
||||
this.defValue = def;
|
||||
if(name == null)
|
||||
throw new IllegalArgumentException("Name cannot be null!");
|
||||
this.minValue = min;
|
||||
this.maxValue = max;
|
||||
this.shouldWatch = watch;
|
||||
|
||||
if (min > max)
|
||||
{
|
||||
throw new IllegalArgumentException("Minimum value cannot be bigger than maximum value!");
|
||||
}
|
||||
else if (def < min)
|
||||
{
|
||||
throw new IllegalArgumentException("Default value cannot be lower than minimum value!");
|
||||
}
|
||||
else if (def > max)
|
||||
{
|
||||
throw new IllegalArgumentException("Default value cannot be bigger than maximum value!");
|
||||
}
|
||||
|
||||
ATTRIBUTES.put(name, this);
|
||||
}
|
||||
|
||||
public String getUnlocalizedName()
|
||||
{
|
||||
return this.name;
|
||||
}
|
||||
|
||||
public String getDisplayName()
|
||||
{
|
||||
return this.display;
|
||||
}
|
||||
|
||||
public double getDefaultValue()
|
||||
{
|
||||
return this.defValue;
|
||||
}
|
||||
|
||||
public boolean getShouldWatch()
|
||||
{
|
||||
return this.shouldWatch;
|
||||
}
|
||||
|
||||
public double clampValue(double value)
|
||||
{
|
||||
return ExtMath.clampd(value, this.minValue, this.maxValue);
|
||||
}
|
||||
|
||||
public int hashCode()
|
||||
{
|
||||
return this.name.hashCode();
|
||||
}
|
||||
|
||||
public boolean equals(Object obj)
|
||||
{
|
||||
return obj instanceof Attribute && this.name.equals(((Attribute)obj).getUnlocalizedName());
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue