Skip to content

Commit

Permalink
Move contextTypeName to ScriptHolder
Browse files Browse the repository at this point in the history
  • Loading branch information
zbx1425 committed Feb 7, 2024
1 parent 461bcb1 commit 4f299eb
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ MtrModelRegistryUtil.resourceManager, new ResourceLocation(obj.get("atlasIndex"
ResourceLocation scriptLocation = new ResourceLocation(scriptFiles.get(i).getAsString());
scripts.put(scriptLocation, ResourceUtil.readResource(resourceManager, scriptLocation));
}
scriptContext.load("EyeCandy " + key, resourceManager, scripts);
scriptContext.load("EyeCandy " + key, "Block", resourceManager, scripts);

return new EyeCandyProperties(Text.translatable(obj.get("name").getAsString()), scriptContext);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public static void init(ResourceManager resourceManager) {
scripts.put(scriptLocation, null);
}
}
scriptContext.load("Train " + entry.getKey(), resourceManager, scripts);
scriptContext.load("Train " + entry.getKey(), "Train", resourceManager, scripts);

boolean dummyBaseTrain = jsonObject.has("base_type");
String baseTrainType = dummyBaseTrain ? jsonObject.get("base_type").getAsString() : prevTrainProp.baseTrainType;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ public abstract class AbstractScriptContext {

public abstract Object getWrapperObject();

public abstract String getContextTypeName();

public abstract boolean isBearerAlive();

public void setDebugInfo(String key, Object value) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,12 @@ public class ScriptHolder {
public Exception failException = null;

public String name;
public String contextTypeName;
private Map<ResourceLocation, String> scripts;

public void load(String name, ResourceManager resourceManager, Map<ResourceLocation, String> scripts) throws Exception {
public void load(String name, String contextTypeName, ResourceManager resourceManager, Map<ResourceLocation, String> scripts) throws Exception {
this.name = name;
this.contextTypeName = contextTypeName;
this.scripts = scripts;
Context rhinoCtx = Context.enter();
rhinoCtx.setLanguageVersion(Context.VERSION_ES6);
Expand Down Expand Up @@ -105,8 +107,11 @@ public void load(String name, ResourceManager resourceManager, Map<ResourceLocat
? ResourceUtil.readResource(resourceManager, entry.getKey()) : entry.getValue();
ScriptResourceUtil.executeScript(rhinoCtx, scope, entry.getKey(), scriptStr);
acquireFunction("create", createFunctions);
acquireFunction("create" + contextTypeName, createFunctions);
acquireFunction("render", renderFunctions);
acquireFunction("render" + contextTypeName, renderFunctions);
acquireFunction("dispose", disposeFunctions);
acquireFunction("dispose" + contextTypeName, disposeFunctions);
}
ScriptResourceUtil.activeContext = null;
ScriptResourceUtil.activeScope = null;
Expand All @@ -116,7 +121,7 @@ public void load(String name, ResourceManager resourceManager, Map<ResourceLocat
}

public void reload(ResourceManager resourceManager) throws Exception {
load(name, resourceManager, scripts);
load(name, contextTypeName, resourceManager, scripts);
}

private void acquireFunction(String functionName, List<Function> target) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,6 @@ public Object getWrapperObject() {
return entity;
}

@Override
public String getContextTypeName() {
return "Block";
}

@Override
public boolean isBearerAlive() {
return !entity.isRemoved();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,6 @@ public Object getWrapperObject() {
return trainExtra;
}

@Override
public String getContextTypeName() {
return "Train";
}

@Override
public boolean isBearerAlive() {
return !train.isRemoved && ClientData.TRAINS.contains(train);
Expand Down

0 comments on commit 4f299eb

Please sign in to comment.