Skip to content

Commit

Permalink
adjust command: slightly stabler logic
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Oct 22, 2020
1 parent df10cb4 commit 2db11bb
Showing 1 changed file with 24 additions and 18 deletions.
Expand Up @@ -117,25 +117,29 @@ public ObjectTag adjust(ObjectTag object, ElementTag mechanismName, ElementTag v
}

public ObjectTag adjust(ObjectTag object, Mechanism mechanism, ScriptEntry entry) {
String objectString = object.toString();
String lowerObjectString = CoreUtilities.toLowerCase(objectString);
Consumer<Mechanism> specialAdjustable = specialAdjustables.get(lowerObjectString);
if (specialAdjustable != null) {
specialAdjustable.accept(mechanism);
return object;
if (object == null) {
Debug.echoError("Cannot adjust null object.");
return null;
}
if (lowerObjectString.startsWith("def:")) {
String defName = lowerObjectString.substring("def:".length());
ObjectTag def = entry.getResidingQueue().getDefinitionObject(defName);
if (def == null) {
Debug.echoError("Invalid definition name '" + defName + "', cannot adjust");
if (object instanceof ElementTag) {
String objectString = object.toString();
String lowerObjectString = CoreUtilities.toLowerCase(objectString);
Consumer<Mechanism> specialAdjustable = specialAdjustables.get(lowerObjectString);
if (specialAdjustable != null) {
specialAdjustable.accept(mechanism);
return object;
}
def = adjust(def, mechanism, entry);
entry.getResidingQueue().addDefinition(defName, def);
return def;
}
if (object instanceof ElementTag) {
if (lowerObjectString.startsWith("def:")) {
String defName = lowerObjectString.substring("def:".length());
ObjectTag def = entry.getResidingQueue().getDefinitionObject(defName);
if (def == null) {
Debug.echoError("Invalid definition name '" + defName + "', cannot adjust");
return object;
}
def = adjust(def, mechanism, entry);
entry.getResidingQueue().addDefinition(defName, def);
return def;
}
object = ObjectFetcher.pickObjectFor(objectString, entry.entryData.getTagContext());
if (object instanceof ElementTag) {
Debug.echoError("Unable to determine what object to adjust (missing object notation?), for: " + objectString);
Expand All @@ -151,9 +155,11 @@ public ObjectTag adjust(ObjectTag object, Mechanism mechanism, ScriptEntry entry
}
return result;
}
object = ObjectFetcher.pickObjectFor(objectString, mechanism.context); // Create duplicate of object, instead of adjusting original
if (!object.isUnique()) {
object = ObjectFetcher.pickObjectFor(object.identify(), mechanism.context); // Create duplicate of object, instead of adjusting original
}
if (!(object instanceof Adjustable)) {
Debug.echoError("'" + objectString + "' is not an adjustable object type.");
Debug.echoError("'" + object + "' is not an adjustable object type.");
return object;
}
if (entry.getResidingQueue().procedural && object.isUnique()) {
Expand Down

0 comments on commit 2db11bb

Please sign in to comment.