Skip to content

Update markerTagToScene for new Javascript runtime #311

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 26, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 9 additions & 18 deletions plugins/markerTagToScene/markerTagToScene.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ function ok() {

function main() {
var hookContext = input.Args.hookContext;
var opInput = hookContext.input;
var primaryTagID = opInput.primary_tag_id;
var sceneID = opInput.scene_id;
var opInput = hookContext.Input;
var primaryTagID = opInput.PrimaryTagID;
var sceneID = opInput.SceneID;

// we can't currently find scene markers. If it's not in the input
// then just return
Expand All @@ -19,22 +19,13 @@ function main() {

// get the existing scene tags
var sceneTags = getSceneTags(sceneID);
var tagIDs = [];
for (var i = 0; i < sceneTags.length; ++i) {
var tagID = sceneTags[i].id;
if (tagID == primaryTagID) {
log.Debug("primary tag already exists on scene");
return;
}

tagIDs.push(tagID);
}

// set the tag on the scene if not present
tagIDs.push(primaryTagID);
// Combine all tags from scene and the new marker
var allTags = [...new Set([...sceneTags, primaryTagID, ...opInput.TagIds])];
var newTags = allTags.filter((t) => sceneTags.includes(t));

setSceneTags(sceneID, tagIDs);
log.Info("added primary tag " + primaryTagID + " to scene " + sceneID);
setSceneTags(sceneID, allTags);
log.Debug("added new tags " + newTags.join(", ") + " to scene " + sceneID);
}

function getSceneTags(sceneID) {
Expand All @@ -55,7 +46,7 @@ query findScene($id: ID) {\
var result = gql.Do(query, variables);
var findScene = result.findScene;
if (findScene) {
return findScene.tags;
return findScene.tags.map((t) => t.id);
}

return [];
Expand Down