Skip to content
Open
Show file tree
Hide file tree
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
42 changes: 22 additions & 20 deletions client/ayon_harmony/js/loaders/TemplateLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ TemplateLoader.prototype.loadContainer = function(args) {
var templatePath = args[0];
var overrideName = args[1] || "";
var parentBackdropName = args[2] || null;
var existingNames = args[3] || [];

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This is strange, existing names better be collected on the JS side. Or the whole function should be refactored in order to deal with correct name on the python side and passed as overrideName.
@kalisp do you have a preference?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think we were adding numeric suffixes in JS, weren't we? So probably JS to match.


// Copy from template file
MessageLog.trace("loadContainer:: ");
Expand All @@ -51,7 +52,7 @@ TemplateLoader.prototype.loadContainer = function(args) {
function parseBackdropName(name) {
var lastIndex = name.lastIndexOf('_');
if (lastIndex === -1) {
return { baseName: name, count: 1 };
return { baseName: name, count: 0 };
}
var base = name.substring(0, lastIndex);
var suffix = name.substring(lastIndex + 1);
Expand All @@ -60,7 +61,7 @@ TemplateLoader.prototype.loadContainer = function(args) {
if (isNumericSuffix) {
return { baseName: base, count: increment };
}
return { baseName: name, count: 1 };
return { baseName: name, count: 0 };
}

var _copyOptions = copyPaste.getCurrentCreateOptions();
Expand Down Expand Up @@ -134,27 +135,28 @@ TemplateLoader.prototype.loadContainer = function(args) {
mainBackdrop.title.text = overrideName;
}

// Count existing backdrops by base name
var backdropCounts = {};
for (var i = 0; i < allBackdrops.length; i++) {
var parsed = parseBackdropName(allBackdrops[i].title.text);
var baseName = parsed.baseName;
var count = parsed.count;

if (backdropCounts[baseName]) {
backdropCounts[baseName]++;
} else {
backdropCounts[baseName] = count;
var mainBackdropBaseName = parseBackdropName(mainBackdrop.title.text).baseName;

// Collect used suffix slots for this baseName, based on the
// Python-provided list of already-registered container names
var usedNumbers = [];
for (var n = 0; n < existingNames.length; n++) {
var parsed = parseBackdropName(existingNames[n]);
if (parsed.baseName !== mainBackdropBaseName) {
continue;
}
usedNumbers.push(parsed.count);
}

// Increment count of backdrop with the same base name
var mainBackdropName = mainBackdrop.title.text;
var mainBackdropParsed = parseBackdropName(mainBackdropName);
var count = backdropCounts[mainBackdropParsed.baseName] !== undefined ? backdropCounts[mainBackdropParsed.baseName] : 1;
if (count > 1){
// count -1 to match imported nodes which start from _1
mainBackdropName = mainBackdropName + "_" + (count - 1);
var mainBackdropName;
if (usedNumbers.indexOf(0) === -1) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think this would be faster, 0 will either be at index 0:

Suggested change
if (usedNumbers.indexOf(0) === -1) {
if (usedNumbers[0] === 0) {

mainBackdropName = mainBackdropBaseName;
} else {
var nextSuffix = 1;
while (usedNumbers.indexOf(nextSuffix) !== -1) {
nextSuffix++;
}
mainBackdropName = mainBackdropBaseName + "_" + nextSuffix;
}

// Set name of main backdrop (always at index 0)
Expand Down
10 changes: 9 additions & 1 deletion client/ayon_harmony/plugins/load/load_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,13 @@ def load(self, context, name=None, namespace=None, data=None):
if self.parent_backdrop_matching:
parent_backdrop_name = self._resolve_parent_backdrop_name(context)

scene_data = harmony.get_scene_data() or {}
existing_names = [
entity_name
for entity_name, entity_data in scene_data.items()
if isinstance(entity_data, dict) and entity_data.get("loader")
]

with zipfile.ZipFile(zip_file, "r") as zip_ref:
zip_ref.extractall(temp_dir)

Expand All @@ -53,7 +60,8 @@ def load(self, context, name=None, namespace=None, data=None):
"args": [
next(Path(temp_dir).glob("*.tpl")).as_posix(),
override_name,
parent_backdrop_name
parent_backdrop_name,
existing_names,
],
}
)["result"]
Expand Down
1 change: 0 additions & 1 deletion client/ayon_harmony/vendor/OpenHarmony
Submodule OpenHarmony deleted from 763169