Fix item updates in various scenarious

This commit is contained in:
Carl Philipp Klemm 2026-04-01 14:49:30 +02:00
parent 34769049f9
commit 9648c7c040
3 changed files with 22 additions and 12 deletions

View file

@ -161,26 +161,34 @@ Item& Item::operator=(const ItemData& other)
void Item::requestUpdate(ItemUpdateRequest update) void Item::requestUpdate(ItemUpdateRequest update)
{ {
if(!hasChanged(update.payload)) assert(update.type != ITEM_UPDATE_INVALID);
if(update.type != ITEM_UPDATE_LOADED && value_ == update.payload.getValue())
return; return;
if(update.type == ITEM_UPDATE_ACTOR && override_) if(update.type == ITEM_UPDATE_ACTOR && override_)
return; return;
if(update.type != ITEM_UPDATE_LOADED qDebug()<<"Item Update Request for"<<getName()<<" type "<<update.type<<" value "<<update.payload.getValue();
&& (programMode == PROGRAM_MODE_PRIMARY || programMode == PROGRAM_MODE_HEADLESS_PRIMARY))
if(update.type != ITEM_UPDATE_LOADED &&
update.type != ITEM_UPDATE_BACKEND &&
(programMode == PROGRAM_MODE_PRIMARY || programMode == PROGRAM_MODE_HEADLESS_PRIMARY))
enactValue(update.payload.getValue()); enactValue(update.payload.getValue());
*this = update.payload; if(update.type != ITEM_UPDATE_LOADED)
update.payload = *this;
if(update.type == ITEM_UPDATE_LOADED)
{ {
value_ = update.payload.getValue();
}
else
{
name_ = update.payload.getName();
//itemId_ = update.payload.id();
hidden_ = update.payload.isHidden();
actors_.clear(); actors_.clear();
for(std::shared_ptr<Actor>& actor : update.newActors) for(std::shared_ptr<Actor>& actor : update.newActors)
addActor(actor); addActor(actor);
} }
update.payload = *this;
updated(update); updated(update);
} }
@ -286,6 +294,7 @@ ItemUpdateRequest Item::createValueUpdateRequest(uint8_t value,
bool withActors) bool withActors)
{ {
ItemUpdateRequest update; ItemUpdateRequest update;
update.type = type;
update.payload = *this; update.payload = *this;
update.payload.setValueData(value); update.payload.setValueData(value);
if(withActors) if(withActors)

View file

@ -19,7 +19,8 @@ typedef enum {
ITEM_UPDATE_ACTOR, ITEM_UPDATE_ACTOR,
ITEM_UPDATE_REMOTE, ITEM_UPDATE_REMOTE,
ITEM_UPDATE_LOADED, ITEM_UPDATE_LOADED,
ITEM_UPDATE_BACKEND ITEM_UPDATE_BACKEND,
ITEM_UPDATE_INVALID
} item_update_type_t; } item_update_type_t;
class ItemData class ItemData
@ -67,7 +68,7 @@ public:
struct ItemUpdateRequest struct ItemUpdateRequest
{ {
item_update_type_t type; item_update_type_t type = ITEM_UPDATE_INVALID;
ItemData payload; ItemData payload;
std::vector<std::shared_ptr<Actor> > newActors; std::vector<std::shared_ptr<Actor> > newActors;
}; };

View file

@ -29,6 +29,7 @@ void ItemStore::addItem(const std::shared_ptr<Item>& item, item_update_type_t up
ItemUpdateRequest request = item->createValueUpdateRequest(item->getValue(), ItemUpdateRequest request = item->createValueUpdateRequest(item->getValue(),
updateType, updateType,
updateType == ITEM_UPDATE_LOADED); updateType == ITEM_UPDATE_LOADED);
request.newActors = item->getActors();
updateItem(request); updateItem(request);
} }
} }
@ -56,6 +57,7 @@ void ItemStore::removeItem(const ItemData& item)
void ItemStore::replaceItems(const std::vector<std::shared_ptr<Item>>& items) void ItemStore::replaceItems(const std::vector<std::shared_ptr<Item>>& items)
{ {
qDebug()<<__func__;
addItems(items, ITEM_UPDATE_LOADED); addItems(items, ITEM_UPDATE_LOADED);
std::vector<ItemData> deletedItems; std::vector<ItemData> deletedItems;
for(std::shared_ptr<Item> item : items_) for(std::shared_ptr<Item> item : items_)
@ -86,7 +88,6 @@ void ItemStore::updateItem(const ItemUpdateRequest& update)
if(items_[i]->operator==(update.payload)) if(items_[i]->operator==(update.payload))
{ {
items_[i]->requestUpdate(update); items_[i]->requestUpdate(update);
qDebug() << "Item" << items_[i]->getName() << "updated";
itemUpdated(update); itemUpdated(update);
} }
} }
@ -106,7 +107,6 @@ void ItemStore::store(QJsonObject& json)
void ItemStore::itemUpdateSlot(ItemUpdateRequest update) void ItemStore::itemUpdateSlot(ItemUpdateRequest update)
{ {
qDebug() << "Item" << update.payload.getName() << "updated from update slot";
itemUpdated(update); itemUpdated(update);
} }