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)
{
if(!hasChanged(update.payload))
assert(update.type != ITEM_UPDATE_INVALID);
if(update.type != ITEM_UPDATE_LOADED && value_ == update.payload.getValue())
return;
if(update.type == ITEM_UPDATE_ACTOR && override_)
return;
if(update.type != ITEM_UPDATE_LOADED
&& (programMode == PROGRAM_MODE_PRIMARY || programMode == PROGRAM_MODE_HEADLESS_PRIMARY))
qDebug()<<"Item Update Request for"<<getName()<<" type "<<update.type<<" value "<<update.payload.getValue();
if(update.type != ITEM_UPDATE_LOADED &&
update.type != ITEM_UPDATE_BACKEND &&
(programMode == PROGRAM_MODE_PRIMARY || programMode == PROGRAM_MODE_HEADLESS_PRIMARY))
enactValue(update.payload.getValue());
*this = update.payload;
update.payload = *this;
if(update.type == ITEM_UPDATE_LOADED)
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();
for(std::shared_ptr<Actor>& actor : update.newActors)
addActor(actor);
}
update.payload = *this;
updated(update);
}
@ -286,6 +294,7 @@ ItemUpdateRequest Item::createValueUpdateRequest(uint8_t value,
bool withActors)
{
ItemUpdateRequest update;
update.type = type;
update.payload = *this;
update.payload.setValueData(value);
if(withActors)

View file

@ -19,7 +19,8 @@ typedef enum {
ITEM_UPDATE_ACTOR,
ITEM_UPDATE_REMOTE,
ITEM_UPDATE_LOADED,
ITEM_UPDATE_BACKEND
ITEM_UPDATE_BACKEND,
ITEM_UPDATE_INVALID
} item_update_type_t;
class ItemData
@ -67,7 +68,7 @@ public:
struct ItemUpdateRequest
{
item_update_type_t type;
item_update_type_t type = ITEM_UPDATE_INVALID;
ItemData payload;
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(),
updateType,
updateType == ITEM_UPDATE_LOADED);
request.newActors = item->getActors();
updateItem(request);
}
}
@ -56,6 +57,7 @@ void ItemStore::removeItem(const ItemData& item)
void ItemStore::replaceItems(const std::vector<std::shared_ptr<Item>>& items)
{
qDebug()<<__func__;
addItems(items, ITEM_UPDATE_LOADED);
std::vector<ItemData> deletedItems;
for(std::shared_ptr<Item> item : items_)
@ -86,7 +88,6 @@ void ItemStore::updateItem(const ItemUpdateRequest& update)
if(items_[i]->operator==(update.payload))
{
items_[i]->requestUpdate(update);
qDebug() << "Item" << items_[i]->getName() << "updated";
itemUpdated(update);
}
}
@ -106,7 +107,6 @@ void ItemStore::store(QJsonObject& json)
void ItemStore::itemUpdateSlot(ItemUpdateRequest update)
{
qDebug() << "Item" << update.payload.getName() << "updated from update slot";
itemUpdated(update);
}