Showing the changes to interface/src/scripting/SelectionScriptingInterface.cpp (1 of 3 files). Show all
Unified · Split
| @@ -46,6 +46,7 @@ bool GameplayObjects::removeFromGameplayObjects(const OverlayID& overlayID) { · 45 unmodified lines | |||
| 46 | return true; | 46 | return true; |
| 47 | } | 47 | } |
| 48 | 48 | ||
| 49 | |||
| 49 | SelectionScriptingInterface::SelectionScriptingInterface() { | 50 | SelectionScriptingInterface::SelectionScriptingInterface() { |
| 50 | } | 51 | } |
| 51 | 52 | ||
| @@ -71,8 +72,9 @@ bool SelectionScriptingInterface::removeFromSelectedItemsList(const QString& lis · 19 unmodified lines | |||
| 71 | } | 72 | } |
| 72 | 73 | ||
| 73 | template <class T> bool SelectionScriptingInterface::addToGameplayObjects(const QString& listName, T idToAdd) { | 74 | template <class T> bool SelectionScriptingInterface::addToGameplayObjects(const QString& listName, T idToAdd) { |
| 74 | if (_selectedItemsListMap.contains(listName)) { | 75 | QWriteLocker writeLock(&_mapLock); |
| 75 | auto currentList = _selectedItemsListMap.take(listName); | 76 | auto currentList = _selectedItemsListMap.value(listName); |
| 77 | if (currentList.getContainsData()) { | ||
| 76 | currentList.addToGameplayObjects(idToAdd); | 78 | currentList.addToGameplayObjects(idToAdd); |
| 77 | _selectedItemsListMap.insert(listName, currentList); | 79 | _selectedItemsListMap.insert(listName, currentList); |
| 78 | 80 | ||
| @@ -84,8 +86,9 @@ template <class T> bool SelectionScriptingInterface::addToGameplayObjects(const · 5 unmodified lines | |||
| 84 | } | 86 | } |
| 85 | } | 87 | } |
| 86 | template <class T> bool SelectionScriptingInterface::removeFromGameplayObjects(const QString& listName, T idToRemove) { | 88 | template <class T> bool SelectionScriptingInterface::removeFromGameplayObjects(const QString& listName, T idToRemove) { |
| 87 | if (_selectedItemsListMap.contains(listName)) { | 89 | QWriteLocker writeLock(&_mapLock); |
| 88 | auto currentList = _selectedItemsListMap.take(listName); | 90 | auto currentList = _selectedItemsListMap.value(listName); |
| 91 | if (currentList.getContainsData()) { | ||
| 89 | currentList.removeFromGameplayObjects(idToRemove); | 92 | currentList.removeFromGameplayObjects(idToRemove); |
| 90 | _selectedItemsListMap.insert(listName, currentList); | 93 | _selectedItemsListMap.insert(listName, currentList); |
| 91 | 94 | ||
| @@ -100,12 +103,14 @@ template <class T> bool SelectionScriptingInterface::removeFromGameplayObjects(c · 8 unmodified lines | |||
| 100 | // | 103 | // |
| 101 | 104 | ||
| 102 | GameplayObjects SelectionScriptingInterface::getList(const QString& listName) { | 105 | GameplayObjects SelectionScriptingInterface::getList(const QString& listName) { |
| 106 | QReadLocker readLock(&_mapLock); | ||
| 103 | return _selectedItemsListMap.value(listName); | 107 | return _selectedItemsListMap.value(listName); |
| 104 | } | 108 | } |
| 105 | 109 | ||
| 106 | void SelectionScriptingInterface::printList(const QString& listName) { | 110 | void SelectionScriptingInterface::printList(const QString& listName) { |
| 107 | if (_selectedItemsListMap.contains(listName)) { | 111 | QReadLocker readLock(&_mapLock); |
| 108 | auto currentList = _selectedItemsListMap.value(listName); | 112 | auto currentList = _selectedItemsListMap.value(listName); |
| 113 | if (currentList.getContainsData()) { | ||
| 109 | 114 | ||
| 110 | qDebug() << "Avatar IDs:"; | 115 | qDebug() << "Avatar IDs:"; |
| 111 | for (auto i : currentList.getAvatarIDs()) { | 116 | for (auto i : currentList.getAvatarIDs()) { |
| @@ -130,6 +135,7 @@ void SelectionScriptingInterface::printList(const QString& listName) { · 18 unmodified lines | |||
| 130 | } | 135 | } |
| 131 | 136 | ||
| 132 | bool SelectionScriptingInterface::removeListFromMap(const QString& listName) { | 137 | bool SelectionScriptingInterface::removeListFromMap(const QString& listName) { |
| 138 | QWriteLocker writeLock(&_mapLock); | ||
| 133 | if (_selectedItemsListMap.remove(listName)) { | 139 | if (_selectedItemsListMap.remove(listName)) { |
| 134 | emit selectedItemsListChanged(listName); | 140 | emit selectedItemsListChanged(listName); |
| 135 | return true; | 141 | return true; |
| @@ -142,8 +148,7 @@ bool SelectionScriptingInterface::removeListFromMap(const QString& listName) { · 6 unmodified lines | |||
| 142 | SelectionToSceneHandler::SelectionToSceneHandler() { | 148 | SelectionToSceneHandler::SelectionToSceneHandler() { |
| 143 | } | 149 | } |
| 144 | 150 | ||
| 145 | void SelectionToSceneHandler::initialize(render::ScenePointer mainScene, const QString& listName) { | 151 | void SelectionToSceneHandler::initialize(const QString& listName) { |
| 146 | _mainScene = mainScene; | ||
| 147 | _listName = listName; | 152 | _listName = listName; |
| 148 | } | 153 | } |
| 149 | 154 | ||
| @@ -154,11 +159,12 @@ void SelectionToSceneHandler::selectedItemsListChanged(const QString& listName) · 4 unmodified lines | |||
| 154 | } | 159 | } |
| 155 | 160 | ||
| 156 | void SelectionToSceneHandler::updateSceneFromSelectedList() { | 161 | void SelectionToSceneHandler::updateSceneFromSelectedList() { |
| 157 | if (_mainScene) { | 162 | auto mainScene = qApp->getMain3DScene(); |
| 163 | if (mainScene) { | ||
| 158 | GameplayObjects thisList = DependencyManager::get<SelectionScriptingInterface>()->getList(_listName); | 164 | GameplayObjects thisList = DependencyManager::get<SelectionScriptingInterface>()->getList(_listName); |
| 159 | render::Transaction transaction; | ||
| 160 | 165 | ||
| 161 | if (thisList.getContainsData()) { | 166 | if (thisList.getContainsData()) { |
| 167 | render::Transaction transaction; | ||
| 162 | render::ItemIDs finalList; | 168 | render::ItemIDs finalList; |
| 163 | render::ItemID currentID; | 169 | render::ItemID currentID; |
| 164 | auto entityTree = qApp->getEntities()->getTree(); | 170 | auto entityTree = qApp->getEntities()->getTree(); |
| @@ -202,7 +208,7 @@ void SelectionToSceneHandler::updateSceneFromSelectedList() { · 37 unmodified lines | |||
| 202 | render::Selection selection(_listName.toStdString(), finalList); | 208 | render::Selection selection(_listName.toStdString(), finalList); |
| 203 | transaction.resetSelection(selection); | 209 | transaction.resetSelection(selection); |
| 204 | 210 | ||
| 205 | _mainScene->enqueueTransaction(transaction); | 211 | mainScene->enqueueTransaction(transaction); |
| 206 | } else { | 212 | } else { |
| 207 | qWarning() << "List of GameplayObjects doesn't exist in thisList"; | 213 | qWarning() << "List of GameplayObjects doesn't exist in thisList"; |
| 208 | } | 214 | } |