mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-07-23 23:04:05 +02:00
change logic for determining if current avatar is bookmarked & move to model
This commit is contained in:
parent
512e72d6d1
commit
47ffcf8c42
2 changed files with 79 additions and 40 deletions
|
@ -107,51 +107,19 @@ Rectangle {
|
||||||
} else if(message.method === getAvatarsMethod) {
|
} else if(message.method === getAvatarsMethod) {
|
||||||
var getAvatarsReply = message.reply;
|
var getAvatarsReply = message.reply;
|
||||||
allAvatars.populate(getAvatarsReply.bookmarks);
|
allAvatars.populate(getAvatarsReply.bookmarks);
|
||||||
|
setCurrentAvatar(getAvatarsReply.currentAvatar);
|
||||||
|
|
||||||
var currentAvatar = getAvatarsReply.currentAvatar;
|
|
||||||
console.debug('currentAvatar: ', JSON.stringify(currentAvatar, null, '\t'));
|
console.debug('currentAvatar: ', JSON.stringify(currentAvatar, null, '\t'));
|
||||||
var selectedAvatarIndex = -1;
|
var bookmarkAvatarIndex = allAvatars.findAvatarIndexByValue(currentAvatar);
|
||||||
|
|
||||||
// 2DO: find better way of determining selected avatar in bookmarks
|
if(bookmarkAvatarIndex === -1) {
|
||||||
console.debug('allAvatars.count: ', allAvatars.count);
|
console.debug('bookmarkAvatarIndex = -1, avatar is not favorite')
|
||||||
for(var i = 0; i < allAvatars.count; ++i) {
|
|
||||||
var thesame = true;
|
|
||||||
for(var prop in currentAvatar) {
|
|
||||||
// console.debug('prop', prop);
|
|
||||||
|
|
||||||
var v1 = currentAvatar[prop];
|
|
||||||
var v2 = allAvatars.get(i).entry[prop];
|
|
||||||
console.debug('v1', v1, 'v2', v2);
|
|
||||||
|
|
||||||
var s1 = JSON.stringify(v1);
|
|
||||||
var s2 = JSON.stringify(v2);
|
|
||||||
|
|
||||||
// console.debug('comparing\n', s1, 'to\n', s2, '...');
|
|
||||||
if(s1 !== s2) {
|
|
||||||
if(!(Array.isArray(v1) && v1.length === 0 && v2 === undefined)) {
|
|
||||||
thesame = false;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// console.debug('values seems to be the same...');
|
|
||||||
}
|
|
||||||
if(thesame) {
|
|
||||||
selectedAvatarIndex = i;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
console.debug('selectedAvatarIndex = -1, avatar is not favorite')
|
|
||||||
|
|
||||||
setCurrentAvatar(currentAvatar);
|
|
||||||
|
|
||||||
if(selectedAvatarIndex === -1) {
|
|
||||||
selectedAvatar = root.currentAvatar;
|
selectedAvatar = root.currentAvatar;
|
||||||
view.setPage(0);
|
view.setPage(0);
|
||||||
|
|
||||||
console.debug('selectedAvatar = ', JSON.stringify(selectedAvatar, null, '\t'))
|
console.debug('selectedAvatar = ', JSON.stringify(selectedAvatar, null, '\t'))
|
||||||
} else {
|
} else {
|
||||||
view.selectAvatar(allAvatars.get(selectedAvatarIndex));
|
view.selectAvatar(allAvatars.get(bookmarkAvatarIndex));
|
||||||
}
|
}
|
||||||
} else if(message.method === 'selectAvatarEntity') {
|
} else if(message.method === 'selectAvatarEntity') {
|
||||||
adjustWearables.selectWearableByID(message.entityID);
|
adjustWearables.selectWearableByID(message.entityID);
|
||||||
|
@ -537,7 +505,7 @@ Rectangle {
|
||||||
id: view
|
id: view
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
interactive: false;
|
interactive: false;
|
||||||
currentIndex: (selectedAvatarId !== '' && !pageOfAvatars.isUpdating) ? pageOfAvatars.findAvatar(selectedAvatarId) : -1
|
currentIndex: (selectedAvatarId !== '' && !pageOfAvatars.isUpdating) ? pageOfAvatars.findAvatarIndex(selectedAvatarId) : -1
|
||||||
|
|
||||||
property int horizontalSpacing: 18
|
property int horizontalSpacing: 18
|
||||||
property int verticalSpacing: 44
|
property int verticalSpacing: 44
|
||||||
|
@ -840,10 +808,9 @@ Rectangle {
|
||||||
gotoAvatarAppPanel.visible = false;
|
gotoAvatarAppPanel.visible = false;
|
||||||
|
|
||||||
var i = allAvatars.count + 1;
|
var i = allAvatars.count + 1;
|
||||||
var url = allAvatars.urls[i++ % allAvatars.urls.length]
|
|
||||||
|
|
||||||
var avatar = {
|
var avatar = {
|
||||||
'url': Qt.resolvedUrl(url),
|
'url': '',
|
||||||
'name': 'Lexi' + (++newAvatarIndex),
|
'name': 'Lexi' + (++newAvatarIndex),
|
||||||
'wearables': []
|
'wearables': []
|
||||||
};
|
};
|
||||||
|
|
|
@ -32,6 +32,78 @@ ListModel {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function arraysAreEqual(a1, a2, comparer) {
|
||||||
|
if(Array.isArray(a1) && Array.isArray(a2)) {
|
||||||
|
if(a1.length !== a2.length) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
for(var i = 0; i < a1.length; ++i) {
|
||||||
|
if(!comparer(a1[i], a2[i])) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if(Array.isArray(a1)) {
|
||||||
|
return a1.length === 0;
|
||||||
|
} else if(Array.isArray(a2)) {
|
||||||
|
return a2.length === 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
function compareArrays(a1, a2, props) {
|
||||||
|
for(var prop in props) {
|
||||||
|
if(JSON.stringify(a1[prop]) !== JSON.stringify(a2[prop])) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
function compareWearables(w1, w2) {
|
||||||
|
return compareArrays(w1, w2, ['modelUrl', 'parentJointIndex', 'marketplaceID', 'itemName', 'script', 'rotation'])
|
||||||
|
}
|
||||||
|
|
||||||
|
function compareAttachments(a1, a2) {
|
||||||
|
return compareAttachments(a1, a2, ['position', 'orientation', 'parentJointIndex', 'modelurl'])
|
||||||
|
}
|
||||||
|
|
||||||
|
function findAvatarIndexByValue(avatar) {
|
||||||
|
|
||||||
|
var index = -1;
|
||||||
|
var avatarObject = avatar.entry;
|
||||||
|
|
||||||
|
// 2DO: find better way of determining selected avatar in bookmarks
|
||||||
|
console.debug('allAvatars.count: ', allAvatars.count);
|
||||||
|
for(var i = 0; i < allAvatars.count; ++i) {
|
||||||
|
var thesame = true;
|
||||||
|
var bookmarkedAvatarObject = allAvatars.get(i).entry;
|
||||||
|
|
||||||
|
if(bookmarkedAvatarObject.avatarUrl !== avatarObject.avatarUrl)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if(bookmarkedAvatarObject.avatarScale !== avatarObject.avatarScale)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if(!arraysAreEqual(bookmarkedAvatarObject.attachments, avatarObject.attachments, compareAttachments)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!arraysAreEqual(bookmarkedAvatarObject.avatarEntities, avatarObject.avatarEntities, compareWearables)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(thesame) {
|
||||||
|
index = i;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return index;
|
||||||
|
}
|
||||||
|
|
||||||
function findAvatarIndex(avatarName) {
|
function findAvatarIndex(avatarName) {
|
||||||
for(var i = 0; i < count; ++i) {
|
for(var i = 0; i < count; ++i) {
|
||||||
if(get(i).name === avatarName) {
|
if(get(i).name === avatarName) {
|
||||||
|
|
Loading…
Reference in a new issue