This commit is contained in:
Daniel Mills 2020-09-08 21:46:08 -04:00
parent 55fde2d3fb
commit 9f1b66fb91
4 changed files with 115 additions and 24 deletions

View File

@ -1031,6 +1031,7 @@ public class ProjectManager
public JSONObject getSchemaFor(Class<?> i, int step, KMap<String, JSONObject> def, IrisDataManager dat) public JSONObject getSchemaFor(Class<?> i, int step, KMap<String, JSONObject> def, IrisDataManager dat)
{ {
Object dummy = tryCreate(i);
if(step <= 0) if(step <= 0)
{ {
JSONObject m = new JSONObject(); JSONObject m = new JSONObject();
@ -1047,7 +1048,8 @@ public class ProjectManager
schema.put("type", "object"); schema.put("type", "object");
Desc d = i.getAnnotation(Desc.class); Desc d = i.getAnnotation(Desc.class);
schema.put("description", d.value()); String dsc = i.getSimpleName().replaceAll("\\QIris\\E", "") + "\n\n" + d.value();
schema.put("description", dsc);
JSONObject properties = new JSONObject(); JSONObject properties = new JSONObject();
JSONArray req = new JSONArray(); JSONArray req = new JSONArray();
@ -1055,6 +1057,7 @@ public class ProjectManager
for(java.lang.reflect.Field k : i.getDeclaredFields()) for(java.lang.reflect.Field k : i.getDeclaredFields())
{ {
k.setAccessible(true);
JSONObject prop = new JSONObject(); JSONObject prop = new JSONObject();
if(k.isAnnotationPresent(Desc.class)) if(k.isAnnotationPresent(Desc.class))
{ {
@ -1279,7 +1282,7 @@ public class ProjectManager
JSONObject items = new JSONObject(); JSONObject items = new JSONObject();
items.put("$ref", "#/definitions/" + name); items.put("$ref", "#/definitions/" + name);
prop.put("items", items); prop.put("items", items);
prop.put("description", k.getAnnotation(Desc.class).value()); prop.put("description", tp + "\n\n" + k.getAnnotation(Desc.class).value());
prop.put("type", tp); prop.put("type", tp);
properties.put(k.getName(), prop); properties.put(k.getName(), prop);
continue; continue;
@ -1299,7 +1302,7 @@ public class ProjectManager
JSONObject items = new JSONObject(); JSONObject items = new JSONObject();
items.put("$ref", "#/definitions/" + name); items.put("$ref", "#/definitions/" + name);
prop.put("items", items); prop.put("items", items);
prop.put("description", k.getAnnotation(Desc.class).value()); prop.put("description", tp + "\n\n" + k.getAnnotation(Desc.class).value());
prop.put("type", tp); prop.put("type", tp);
properties.put(k.getName(), prop); properties.put(k.getName(), prop);
continue; continue;
@ -1319,7 +1322,7 @@ public class ProjectManager
JSONObject items = new JSONObject(); JSONObject items = new JSONObject();
items.put("$ref", "#/definitions/" + name); items.put("$ref", "#/definitions/" + name);
prop.put("items", items); prop.put("items", items);
prop.put("description", k.getAnnotation(Desc.class).value()); prop.put("description", tp + "\n\n" + k.getAnnotation(Desc.class).value());
prop.put("type", tp); prop.put("type", tp);
properties.put(k.getName(), prop); properties.put(k.getName(), prop);
continue; continue;
@ -1339,7 +1342,7 @@ public class ProjectManager
JSONObject items = new JSONObject(); JSONObject items = new JSONObject();
items.put("$ref", "#/definitions/" + name); items.put("$ref", "#/definitions/" + name);
prop.put("items", items); prop.put("items", items);
prop.put("description", k.getAnnotation(Desc.class).value()); prop.put("description", tp + "\n\n" + k.getAnnotation(Desc.class).value());
prop.put("type", tp); prop.put("type", tp);
properties.put(k.getName(), prop); properties.put(k.getName(), prop);
continue; continue;
@ -1359,7 +1362,7 @@ public class ProjectManager
JSONObject items = new JSONObject(); JSONObject items = new JSONObject();
items.put("$ref", "#/definitions/" + name); items.put("$ref", "#/definitions/" + name);
prop.put("items", items); prop.put("items", items);
prop.put("description", k.getAnnotation(Desc.class).value()); prop.put("description", tp + "\n\n" + k.getAnnotation(Desc.class).value());
prop.put("type", tp); prop.put("type", tp);
properties.put(k.getName(), prop); properties.put(k.getName(), prop);
continue; continue;
@ -1379,7 +1382,7 @@ public class ProjectManager
JSONObject items = new JSONObject(); JSONObject items = new JSONObject();
items.put("$ref", "#/definitions/" + name); items.put("$ref", "#/definitions/" + name);
prop.put("items", items); prop.put("items", items);
prop.put("description", k.getAnnotation(Desc.class).value()); prop.put("description", tp + "\n\n" + k.getAnnotation(Desc.class).value());
prop.put("type", tp); prop.put("type", tp);
properties.put(k.getName(), prop); properties.put(k.getName(), prop);
continue; continue;
@ -1399,7 +1402,7 @@ public class ProjectManager
JSONObject items = new JSONObject(); JSONObject items = new JSONObject();
items.put("$ref", "#/definitions/" + name); items.put("$ref", "#/definitions/" + name);
prop.put("items", items); prop.put("items", items);
prop.put("description", k.getAnnotation(Desc.class).value()); prop.put("description", tp + "\n\n" + k.getAnnotation(Desc.class).value());
prop.put("type", tp); prop.put("type", tp);
properties.put(k.getName(), prop); properties.put(k.getName(), prop);
continue; continue;
@ -1419,7 +1422,7 @@ public class ProjectManager
JSONObject items = new JSONObject(); JSONObject items = new JSONObject();
items.put("$ref", "#/definitions/" + name); items.put("$ref", "#/definitions/" + name);
prop.put("items", items); prop.put("items", items);
prop.put("description", k.getAnnotation(Desc.class).value()); prop.put("description", tp + "\n\n" + k.getAnnotation(Desc.class).value());
prop.put("type", tp); prop.put("type", tp);
properties.put(k.getName(), prop); properties.put(k.getName(), prop);
continue; continue;
@ -1439,7 +1442,7 @@ public class ProjectManager
JSONObject items = new JSONObject(); JSONObject items = new JSONObject();
items.put("$ref", "#/definitions/" + name); items.put("$ref", "#/definitions/" + name);
prop.put("items", items); prop.put("items", items);
prop.put("description", k.getAnnotation(Desc.class).value()); prop.put("description", tp + "\n\n" + k.getAnnotation(Desc.class).value());
prop.put("type", tp); prop.put("type", tp);
properties.put(k.getName(), prop); properties.put(k.getName(), prop);
continue; continue;
@ -1469,7 +1472,7 @@ public class ProjectManager
JSONObject items = new JSONObject(); JSONObject items = new JSONObject();
items.put("$ref", "#/definitions/" + name); items.put("$ref", "#/definitions/" + name);
prop.put("items", items); prop.put("items", items);
prop.put("description", k.getAnnotation(Desc.class).value()); prop.put("description", tp + "\n\n" + k.getAnnotation(Desc.class).value());
prop.put("type", tp); prop.put("type", tp);
properties.put(k.getName(), prop); properties.put(k.getName(), prop);
continue; continue;
@ -1498,7 +1501,7 @@ public class ProjectManager
JSONObject deff = new JSONObject(); JSONObject deff = new JSONObject();
JSONObject scv = getSchemaFor(t.type(), step - 1, def, Iris.globaldata); JSONObject scv = getSchemaFor(t.type(), step - 1, def, Iris.globaldata);
deff.put("type", tx); deff.put("type", tx);
deff.put("description", t.type().getDeclaredAnnotation(Desc.class).value()); deff.put("description", tx + "\n\n" + t.type().getDeclaredAnnotation(Desc.class).value());
deff.put("additionalProperties", false); deff.put("additionalProperties", false);
deff.put("properties", scv.getJSONObject("properties")); deff.put("properties", scv.getJSONObject("properties"));
if(scv.has("required")) if(scv.has("required"))
@ -1531,7 +1534,58 @@ public class ProjectManager
} }
} }
prop.put("description", k.getAnnotation(Desc.class).value()); String tpx = tp;
if(tp.equals("array") || tp.equals("enum"))
{
tpx = "List of " + k.getDeclaredAnnotation(ArrayType.class).type().getSimpleName().replaceAll("\\QIris\\E", "") + "s";
}
prop.put("description", tpx + "\n\n" + k.getAnnotation(Desc.class).value());
if(tp.equals("integer"))
{
if(k.isAnnotationPresent(MinNumber.class))
{
prop.put("description", prop.getString("description") + "\n" + "Min: " + (int) k.getDeclaredAnnotation(MinNumber.class).value());
}
if(k.isAnnotationPresent(MaxNumber.class))
{
prop.put("description", prop.getString("description") + "\n" + "Max: " + (int) k.getDeclaredAnnotation(MaxNumber.class).value());
}
}
if(tp.equals("number"))
{
if(k.isAnnotationPresent(MinNumber.class))
{
prop.put("description", prop.getString("description") + "\n" + "Min: " + k.getDeclaredAnnotation(MinNumber.class).value());
}
if(k.isAnnotationPresent(MaxNumber.class))
{
prop.put("description", prop.getString("description") + "\n" + "Max: " + k.getDeclaredAnnotation(MaxNumber.class).value());
}
}
if(!tp.equals("array") && !tp.equals("object") && !tp.equals("enum"))
{
if(dummy != null)
{
try
{
prop.put("description", prop.getString("description") + "\n" + "Default Value: " + k.get(dummy));
}
catch(Throwable e)
{
prop.put("description", prop.getString("description") + "\n" + "Default Value: NONE");
}
}
}
prop.put("type", tp); prop.put("type", tp);
properties.put(k.getName(), prop); properties.put(k.getName(), prop);
} }
@ -1546,6 +1600,21 @@ public class ProjectManager
return schema; return schema;
} }
private Object tryCreate(Class<?> i)
{
try
{
return i.newInstance();
}
catch(Throwable e)
{
}
return null;
}
private String[] getFontList() private String[] getFontList()
{ {
return GraphicsEnvironment.getLocalGraphicsEnvironment().getAvailableFontFamilyNames(); return GraphicsEnvironment.getLocalGraphicsEnvironment().getAvailableFontFamilyNames();

View File

@ -15,37 +15,37 @@ import com.volmit.iris.util.Required;
import lombok.Data; import lombok.Data;
@Desc("Represents an attribute modifier") @Desc("Represents an attribute modifier for an item or an entity. This allows you to create modifications to basic game attributes such as MAX_HEALTH or ARMOR_VALUE.")
@Data @Data
public class IrisAttributeModifier public class IrisAttributeModifier
{ {
@Required @Required
@DontObfuscate @DontObfuscate
@Desc("The Attribute type") @Desc("The Attribute type. This type is pulled from the game attributes. Zombie & Horse attributes will not work on non-zombie/horse entities.\nUsing an attribute on an item will have affects when held, or worn. There is no way to specify further granularity as the game picks this depending on the item type.")
private Attribute attribute = null; private Attribute attribute = null;
@MinNumber(2) @MinNumber(2)
@Required @Required
@DontObfuscate @DontObfuscate
@Desc("The Attribute Name") @Desc("The Attribute Name is used internally only for the game. This value should be unique to all other attributes applied to this item/entity. It is not shown in game.")
private String name = ""; private String name = "";
@DontObfuscate @DontObfuscate
@Desc("The application operation (add number is default)") @Desc("The application operation (add number is default). Add Number adds to the default value. \nAdd scalar_1 will multiply by 1 for example if the health is 20 and you multiply_scalar_1 by 0.5, the health will result in 30, not 10. Use negative values to achieve that.")
private Operation operation = Operation.ADD_NUMBER; private Operation operation = Operation.ADD_NUMBER;
@DontObfuscate @DontObfuscate
@Desc("Minimum amount for this modifier") @Desc("Minimum amount for this modifier. Iris randomly chooses an amount, this is the minimum it can choose randomly for this attribute.")
private double minAmount = 1; private double minAmount = 1;
@DontObfuscate @DontObfuscate
@Desc("Maximum amount for this modifier") @Desc("Maximum amount for this modifier Iris randomly chooses an amount, this is the maximum it can choose randomly for this attribute.")
private double maxAmount = 1; private double maxAmount = 1;
@MinNumber(0) @MinNumber(0)
@MaxNumber(1) @MaxNumber(1)
@DontObfuscate @DontObfuscate
@Desc("The chance that this attribute is applied (0 to 1)") @Desc("The chance that this attribute is applied (0 to 1). If the chance is 0.5 (50%), then Iris will only apply this attribute 50% of the time.")
private double chance = 1; private double chance = 1;
public IrisAttributeModifier() public IrisAttributeModifier()

View File

@ -26,7 +26,7 @@ import lombok.Data;
import lombok.EqualsAndHashCode; import lombok.EqualsAndHashCode;
@DontObfuscate @DontObfuscate
@Desc("Represents a biome in iris. Biomes are placed inside of regions and hold objects.") @Desc("Represents a biome in iris. Biomes are placed inside of regions and hold objects.\nA biome consists of layers (block palletes), decorations, objects & generators.")
@Data @Data
@EqualsAndHashCode(callSuper = false) @EqualsAndHashCode(callSuper = false)
public class IrisBiome extends IrisRegistrant implements IRare public class IrisBiome extends IrisRegistrant implements IRare
@ -38,16 +38,16 @@ public class IrisBiome extends IrisRegistrant implements IRare
private String name = "A Biome"; private String name = "A Biome";
@DontObfuscate @DontObfuscate
@Desc("Place text on terrain") @Desc("Place text on terrain. Iris will render text into block schematics and randomly place them in this biome.")
@ArrayType(min = 1, type = IrisTextPlacement.class) @ArrayType(min = 1, type = IrisTextPlacement.class)
private KList<IrisTextPlacement> text = new KList<>(); private KList<IrisTextPlacement> text = new KList<>();
@DontObfuscate @DontObfuscate
@Desc("The type of fluid if this biome is underwater") @Desc("The type of fluid if this biome is underwater. To 'defer' this value to whatever the parent dimension fluid type is, use an emtpy string.")
private String fluidType = ""; private String fluidType = "";
@DontObfuscate @DontObfuscate
@Desc("Entity spawns to override or add to this biome") @Desc("Entity spawns to override or add to this biome. Anytime an entity spawns, it has a chance to be replaced as one of these overrides.")
@ArrayType(min = 1, type = IrisEntitySpawnOverride.class) @ArrayType(min = 1, type = IrisEntitySpawnOverride.class)
private KList<IrisEntitySpawnOverride> entitySpawnOverrides = new KList<>(); private KList<IrisEntitySpawnOverride> entitySpawnOverrides = new KList<>();

View File

@ -0,0 +1,22 @@
package com.volmit.iris.object;
import com.volmit.iris.util.Desc;
import com.volmit.iris.util.DontObfuscate;
import com.volmit.iris.util.MinNumber;
import com.volmit.iris.util.Required;
import lombok.Data;
@Desc("Represents a cave fluid")
@Data
public class IrisCaveFluid
{
@DontObfuscate
@Desc("If set to true, this cave layer can break the surface")
private boolean canBreakSurface = false;
public IrisCaveFluid()
{
}
}