Skip to content

Commit

Permalink
Make actions and events use queue-level context. Fix up context tag t…
Browse files Browse the repository at this point in the history
…o use queue-level context. Add save:<id> argument to save entries. Use that to reference scriptentry context with <s.<id_name>.whatever>.
  • Loading branch information
aufdemrand committed Aug 28, 2013
1 parent fd6416e commit 6e897e2
Show file tree
Hide file tree
Showing 5 changed files with 202 additions and 83 deletions.
Expand Up @@ -2,6 +2,7 @@

import net.aufdemrand.denizen.Denizen;
import net.aufdemrand.denizen.objects.dNPC;
import net.aufdemrand.denizen.objects.dObject;
import net.aufdemrand.denizen.objects.dPlayer;
import net.aufdemrand.denizen.scripts.ScriptBuilder;
import net.aufdemrand.denizen.scripts.ScriptEntry;
Expand All @@ -27,7 +28,7 @@ public boolean doAction(String actionName, dNPC npc, dPlayer player, AssignmentS
return doAction(actionName, npc, player, assignment, null);
}

public boolean doAction(String actionName, dNPC npc, dPlayer player, AssignmentScriptContainer assignment, Map<String, Object> context) {
public boolean doAction(String actionName, dNPC npc, dPlayer player, AssignmentScriptContainer assignment, Map<String, dObject> context) {
if (assignment == null) {
// dB.echoDebug("Tried to do 'on " + actionName + ":' but couldn't find a matching script.");
return false;
Expand All @@ -47,18 +48,19 @@ public boolean doAction(String actionName, dNPC npc, dPlayer player, AssignmentS

dB.echoDebug(DebugElement.Header, "Building action 'On " + actionName.toUpperCase() + "' for " + npc.toString());

// Add entries and context to the queue
ScriptQueue queue = InstantQueue.getQueue(null).addEntries(script);

if (context != null) {
for (Map.Entry<String, Object> entry : context.entrySet()) {
ScriptBuilder.addObjectToEntries(script, entry.getKey(), entry.getValue());
for (Map.Entry<String, dObject> entry : context.entrySet()) {
queue.addContext(entry.getKey(), entry.getValue());
}
}

ScriptQueue queue = InstantQueue.getQueue(null).addEntries(script);
// Start the queue!
queue.start();

// TODO: Read queue context to see if the event behind action should be cancelled.
// if (queue.getContext() != null
// && queue.getContext().equalsIgnoreCase("cancelled")) return true;
// TODO: Read determination to see if the event behind action should be cancelled.

return false;
}
Expand Down
Expand Up @@ -145,6 +145,12 @@ else if (arg.matchesPrefix("npc, npcid") && !if_ignore) {
scriptEntry.setNPC(npc);
}

// Save the scriptentry if needed later for fetching scriptentry context
else if (arg.matchesPrefix("save") && !if_ignore) {
dB.echoDebug("...remembering this script entry!");
scriptEntry.getResidingQueue().holdScriptEntry(arg.getValue(), scriptEntry);
}

else newArgs.add(arg.raw_value);
}

Expand Down

3 comments on commit 6e897e2

@aufdemrand
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@davidcernat Comments?

@mcmonkey4eva
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@aufdemrand you wrote <s.<id_name>.whatever> then implemented <e[entry_id].entity.blah.blah>...

@aufdemrand
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whoops. Yep, use e[entry_id].whatev for now... I'm thinking about making either a entry dObject or turning scriptentry into a dObject, then this will also allow the objectfetcher to handle it, I think.

Please sign in to comment.