Minor Bug: Town Inventory No Longer Combines Deployed/Undeployed on Multiplayer Branch

ui
a24r841

#1

From my digging around, this seems related to the changes to entity uris’, since they’re now attached with a #number. Here’s a screenshot where I have 16 total fenses, 2 deployed, and 14 in stockpile.


This also brings up a question about the exact changes that were made to entities now in multiplayer, is there somewhere that documents these changes yet?

#2

Those were never combined… or were they? :thinking:


#3

In my case, bigger problem is some kind of ghost item duplication occurring when deploying item.


#4

I believe so too. They were never combined. :thinking:

Is this the bug with items that disappear? Or for plants? There’s an issue that in some cases the same plant can appear both deployed and undeployed in the town inventory. :confused:


#5

and we call it: schrodingers shrubbery!


#6

The only reason I say they aren’t combined is because in the code it would appear they intended for these to be combined:

            self._playerInventoryTrace = new StonehearthDataTrace(response.tracker, itemTraces)
           .progress(function(response) {
              var inventoryItems = {}
              var total_num_items = 0;
              // merge iconic and root entities
              radiant.each(response.tracking_data, function(uri, uri_entry) {
                 radiant.each(uri_entry.item_qualities, function (item_quality_key, item) {
                    var rootUri = uri;
                    var key = rootUri + App.constants.item_quality.KEY_SEPARATOR + item_quality_key;
                    var isIconic = false;
                    if (uri_entry.canonical_uri && uri_entry.canonical_uri.__self != uri_entry.uri.__self) {
                       isIconic = true;
                    }
                    if (!inventoryItems[key]) {
                       inventoryItems[key] = radiant.shallow_copy(uri_entry);
                       inventoryItems[key].count = item.count;
                    } else {
                       inventoryItems[key].count = inventoryItems[key].count + item.count;
                    }
                    inventoryItems[key].item_quality = item_quality_key;
                    if (isIconic) {
                       var numUndeployed = item.count;
                       // Add an additional tip to the item for the number of undeployed items in the world.
                       inventoryItems[key].additionalTip = i18n.t('stonehearth:ui.game.entities.tooltip_num_undeployed', { num_undeployed: numUndeployed });
                    }
                    total_num_items += item.count;
                 });
              });

              self._inventoryPalette.stonehearthItemPalette('updateItems', inventoryItems);

              self.set('inventory_item_count', total_num_items);
           });

Plus, there’s something weird going on since it claims theres 16 undeployed when there are 14 undeployd and 2 deployed.


#7

I think the “merge iconic and root entities” might not be what you think it is (but I could be wrong) :thinking:
This code seems to count (“merge”) the number of iconics (undeployed) and the number of roots (deployed) separately, so that there’s only 1 icon in the UI for each form, with the final count (and not one icon per each individual item).

So if you inspect the UI, one icon corresponds to the iconic uri (a path) and the other one to the root uri (an alias). And the “undeployed” message is only added/updated in the tooltip for the iconics.

Perhaps they were merged at some point in the past, but I’ve checked as far as A19 and they always appear separatedly in the UI :confused:

This might have 2 possible causes:

  1. Tooltips are not updated in real time. If you close and reopen the inventory UI, the count should update.
  2. If it wasn’t the above, save and load that savefile. Open the console and execute “dump_inaccessible_items”, and check if 2 items were dumped near the banner.

If it’s none of these 2, then it might be a bug. :disappointed_relieved:


#8

Is the inventory not supposed to combine ll the undeployed and deployed items of the same quality into one entry?

Can you try this code in town.js? This seems to output the behavior I expected:

self._playerInventoryTrace = new StonehearthDataTrace(response.tracker, itemTraces)
        .progress(function(response) {
           var inventoryItems = {}
           var total_num_items = 0;
              // merge iconic and root entities
              radiant.each(response.tracking_data, function(uri, uri_entry) {
                 radiant.each(uri_entry.item_qualities, function (item_quality_key, item) {
                    var rootUri = uri;

                    if (uri_entry.canonical_uri) {
                       rootUri = uri_entry.canonical_uri;
                    }
                    var key = rootUri + App.constants.item_quality.KEY_SEPARATOR + item_quality_key;
                    var isIconic = false;
                    if (uri_entry.canonical_uri && uri_entry.canonical_uri.__self != uri_entry.uri.__self) {
                       isIconic = true;
                    }
                    if (!inventoryItems[key]) {
                       inventoryItems[key] = radiant.shallow_copy(uri_entry);
                       inventoryItems[key].count = item.count;
                    } else {
                       inventoryItems[key].count = inventoryItems[key].count + item.count;
                    }
                    inventoryItems[key].item_quality = item_quality_key;
                    if (isIconic) {
                       var numUndeployed = item.count;
                       // Add an additional tip to the item for the number of undeployed items in the world.
                       inventoryItems[key].additionalTip = i18n.t('stonehearth:ui.game.entities.tooltip_num_undeployed', { num_undeployed: numUndeployed });
                    }
                    total_num_items += item.count;
                 });
              });

              self._inventoryPalette.stonehearthItemPalette('updateItems', inventoryItems);

              self.set('inventory_item_count', total_num_items);
           });

Sorry for all this, I’m just confused and there’s definitely something not going right here if it thinks theres 16 undeployed when there are really 14


#9

Did you try any of the suggestions I made at the end of my post?


#10

Yes, the reloading does fix the tooltip, but the entries are still separated:
beds

In this case I have 48 regular comfy beds and two are deployed. I’m still thinking the town inventory panel should be showing one entry for all these beds…


#11

It would be logical for them to be combined. Like this, it says you have 46 beds and hovering over the picture tells you that 46 out of these 46 beds are undeployed. Then you have two more beds that have no specific state written in the tooltip. Or it would even make more sense if there was a symbol in the corner of the thumbnail or if the undeployed beds were discolored or something.


#12
var rootUri = uri;
if (uri_entry.canonical_uri) { 
    rootUri = uri_entry.canonical_uri; 
}

That would indeed merge the entries, and I’m not sure why they’re not doing it given the “undeployed” tooltip. It seems like two different people were working on the code (or one person at two different times) with different ideas about how fully the items should be merged. And it’s not like clicking on the items in that view gives you any sort of interactive capability with that item (in which case there would be a reason to keep them separate).


#13

If it’s less confusing for you that way, I’ll make a ticket for it.
You can indeed see how many undeployed items you have by opening the placement menu directly, in the inventory UI you can’t really tell at first glance unless they had different icons. :confused:

I think the initial code was simply to clear iconics and root entities and show the count of each, since both exist at the same time for the same item in the inventory, but you can only see one of them (see the list of all entities in the object browser). The same root will always have assigned the same iconic, unlike ghosts, that are created / destroyed every time.


#14

Ahh, I see. I have anoter question (sorry to bother):
is there a way to convert or figure out what the root uri should be (the one with “#number;json” at the end)? Does this number denote your player_id?

So say I have “/stonehearth/entities/furniture/comfy_bed/comfy_bed_iconic.json” but I need “”/stonehearth/entities/furniture/comfy_bed/comfy_bed_iconic&#46json;"


#15

Wait a second… that looks like an ascii caracter code… is that not supposed to be there, is that the bug?


#16

I’m pretty sure that’s just to get around Javascript not wanting object properties that have a period in them. The uri variable in that code is the property of the container object that indexes the item, but the item itself also has a uri property and that contains the actual uri with the period in it.


#17

oh. well. About my duplication of ghost item problem

As Relyss said, this problem mostly happen when moving plant or seeding plant.

But not just plants definitely. I frequently noticed storage box or furniture duplicate in my town inventory.

As far as I observed, when items are in worker’s inventory or hand this problem happen.

especially when i deployed multiple time at once.