mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2025-07-18 18:23:06 +00:00
Fixes for scripts
This commit is contained in:
parent
8e032fa26a
commit
afd4820713
@ -20,6 +20,7 @@ package com.volmit.iris.core.project;
|
||||
|
||||
import com.volmit.iris.Iris;
|
||||
import com.volmit.iris.core.project.loader.IrisData;
|
||||
import com.volmit.iris.core.project.loader.IrisRegistrant;
|
||||
import com.volmit.iris.core.project.loader.ResourceLoader;
|
||||
import com.volmit.iris.engine.object.annotations.*;
|
||||
import com.volmit.iris.util.collection.KList;
|
||||
@ -91,6 +92,26 @@ public class SchemaBuilder {
|
||||
o.put("type", getType(c));
|
||||
JSONArray required = new JSONArray();
|
||||
|
||||
if(c.isAssignableFrom(IrisRegistrant.class) || IrisRegistrant.class.isAssignableFrom(c))
|
||||
{
|
||||
for (Field k : IrisRegistrant.class.getDeclaredFields()) {
|
||||
k.setAccessible(true);
|
||||
|
||||
if (Modifier.isStatic(k.getModifiers()) || Modifier.isFinal(k.getModifiers()) || Modifier.isTransient(k.getModifiers())) {
|
||||
continue;
|
||||
}
|
||||
|
||||
JSONObject property = buildProperty(k, c);
|
||||
|
||||
if (property.getBoolean("!required")) {
|
||||
required.put(k.getName());
|
||||
}
|
||||
|
||||
property.remove("!required");
|
||||
properties.put(k.getName(), property);
|
||||
}
|
||||
}
|
||||
|
||||
for (Field k : c.getDeclaredFields()) {
|
||||
k.setAccessible(true);
|
||||
|
||||
|
@ -36,6 +36,9 @@ import com.volmit.iris.engine.object.objects.IrisObject;
|
||||
import com.volmit.iris.engine.object.regional.IrisRegion;
|
||||
import com.volmit.iris.engine.object.spawners.IrisSpawner;
|
||||
import com.volmit.iris.util.collection.KMap;
|
||||
import com.volmit.iris.util.context.IrisContext;
|
||||
import com.volmit.iris.util.format.C;
|
||||
import com.volmit.iris.util.format.Form;
|
||||
import com.volmit.iris.util.math.RNG;
|
||||
import lombok.Data;
|
||||
|
||||
@ -78,6 +81,54 @@ public class IrisData {
|
||||
hotloaded();
|
||||
}
|
||||
|
||||
public void preprocessObject(IrisRegistrant t)
|
||||
{
|
||||
try
|
||||
{
|
||||
IrisContext ctx = IrisContext.get();
|
||||
Engine engine = this.engine;
|
||||
|
||||
if(engine == null && ctx != null && ctx.getEngine() != null)
|
||||
{
|
||||
engine = ctx.getEngine();
|
||||
}
|
||||
|
||||
if(engine == null && t.getPreprocessors().isNotEmpty())
|
||||
{
|
||||
Iris.error("Failed to preprocess object " + t.getLoadKey() + " because there is no engine context here. (See stack below)");
|
||||
try
|
||||
{
|
||||
throw new RuntimeException();
|
||||
}
|
||||
|
||||
catch(Throwable ex)
|
||||
{
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
if(engine != null && t.getPreprocessors().isNotEmpty())
|
||||
{
|
||||
synchronized (this)
|
||||
{
|
||||
engine.getExecution().getAPI().setPreprocessorObject(t);
|
||||
|
||||
for(String i : t.getPreprocessors())
|
||||
{
|
||||
engine.getExecution().execute(i);
|
||||
Iris.debug("Loader<" + C.GREEN + t.getTypeName() + C.LIGHT_PURPLE + "> iprocess " + C.YELLOW + t.getLoadKey() + C.LIGHT_PURPLE + " in <rainbow>" + i);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
catch(Throwable e)
|
||||
{
|
||||
Iris.error("Failed to preprocess object!");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void close() {
|
||||
closed = true;
|
||||
dump();
|
||||
|
@ -178,10 +178,11 @@ public class ResourceLoader<T extends IrisRegistrant> {
|
||||
try {
|
||||
PrecisionStopwatch p = PrecisionStopwatch.start();
|
||||
T t = new Gson().fromJson(IO.readAll(j), objectClass);
|
||||
loadCache.put(key, t);
|
||||
t.setLoadKey(name);
|
||||
t.setLoadFile(j);
|
||||
t.setLoader(manager);
|
||||
getManager().preprocessObject(t);
|
||||
loadCache.put(key, t);
|
||||
logLoad(j, t);
|
||||
lock.unlock();
|
||||
tlt.addAndGet(p.getMilliseconds());
|
||||
|
@ -81,15 +81,15 @@ public class ScriptResourceLoader extends ResourceLoader<IrisScript> {
|
||||
for (File i : getFolders()) {
|
||||
for (File j : i.listFiles()) {
|
||||
if (j.isFile() && j.getName().endsWith(".js")) {
|
||||
m.add(j.getName().replaceAll("\\Q.iob\\E", ""));
|
||||
m.add(j.getName().replaceAll("\\Q.js\\E", ""));
|
||||
} else if (j.isDirectory()) {
|
||||
for (File k : j.listFiles()) {
|
||||
if (k.isFile() && k.getName().endsWith(".js")) {
|
||||
m.add(j.getName() + "/" + k.getName().replaceAll("\\Q.iob\\E", ""));
|
||||
m.add(j.getName() + "/" + k.getName().replaceAll("\\Q.js\\E", ""));
|
||||
} else if (k.isDirectory()) {
|
||||
for (File l : k.listFiles()) {
|
||||
if (l.isFile() && l.getName().endsWith(".js")) {
|
||||
m.add(j.getName() + "/" + k.getName() + "/" + l.getName().replaceAll("\\Q.iob\\E", ""));
|
||||
m.add(j.getName() + "/" + k.getName() + "/" + l.getName().replaceAll("\\Q.js\\E", ""));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -101,6 +101,7 @@ public class IrisEngine extends BlockPopulator implements Engine {
|
||||
private final AtomicCache<IrisEngineData> engineData = new AtomicCache<>();
|
||||
|
||||
public IrisEngine(EngineTarget target, EngineCompound compound, int index) {
|
||||
execution = new IrisExecutionEnvironment(this);
|
||||
Iris.info("Initializing Engine: " + target.getWorld().name() + "/" + target.getDimension().getLoadKey() + " (" + target.getHeight() + " height)");
|
||||
metrics = new EngineMetrics(32);
|
||||
this.target = target;
|
||||
@ -120,7 +121,6 @@ public class IrisEngine extends BlockPopulator implements Engine {
|
||||
Iris.callEvent(new IrisEngineHotloadEvent(this));
|
||||
context = new IrisContext(this);
|
||||
context.touch();
|
||||
execution = new IrisExecutionEnvironment(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -49,6 +49,11 @@ public class IrisExecutionEnvironment implements EngineExecutionEnvironment {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public IrisScriptingAPI getAPI() {
|
||||
return api;
|
||||
}
|
||||
|
||||
public void execute(String script)
|
||||
{
|
||||
try {
|
||||
@ -68,20 +73,4 @@ public class IrisExecutionEnvironment implements EngineExecutionEnvironment {
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(String script, double x, double y, double z) {
|
||||
api.setX(x);
|
||||
api.setY(y);
|
||||
api.setZ(z);
|
||||
execute(script);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object evaluate(String script, double x, double y, double z) {
|
||||
api.setX(x);
|
||||
api.setY(y);
|
||||
api.setZ(z);
|
||||
return evaluate(script);
|
||||
}
|
||||
}
|
||||
|
@ -25,16 +25,14 @@ public interface EngineExecutionEnvironment
|
||||
{
|
||||
Engine getEngine();
|
||||
|
||||
IrisScriptingAPI getAPI();
|
||||
|
||||
BSFManager getManager();
|
||||
|
||||
void execute(String script);
|
||||
|
||||
Object evaluate(String script);
|
||||
|
||||
void execute(String script, double x, double y, double z);
|
||||
|
||||
Object evaluate(String script, double x, double y, double z);
|
||||
|
||||
default void close()
|
||||
{
|
||||
|
||||
|
@ -20,6 +20,7 @@ package com.volmit.iris.engine.scripting;
|
||||
|
||||
import com.volmit.iris.Iris;
|
||||
import com.volmit.iris.core.project.loader.IrisData;
|
||||
import com.volmit.iris.core.project.loader.IrisRegistrant;
|
||||
import com.volmit.iris.engine.IrisComplex;
|
||||
import com.volmit.iris.engine.framework.Engine;
|
||||
import com.volmit.iris.engine.framework.EngineFramework;
|
||||
@ -31,6 +32,7 @@ import lombok.Data;
|
||||
@Data
|
||||
public class IrisScriptingAPI {
|
||||
private final Engine engine;
|
||||
private IrisRegistrant preprocessorObject;
|
||||
private double x = 0;
|
||||
private double y = 0;
|
||||
private double z = 0;
|
||||
|
Loading…
x
Reference in New Issue
Block a user