Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Smartshop poi display #71

Open
thomasrudin opened this issue Dec 6, 2019 · 2 comments
Open

Smartshop poi display #71

thomasrudin opened this issue Dec 6, 2019 · 2 comments
Labels
bug Something isn't working

Comments

@thomasrudin
Copy link
Contributor

thomasrudin commented Dec 6, 2019

Position marker for smartshop does not make sense currently:
The 4 markers overlap and 3 of them are not visible.

Possible solutions

  • Compact all the info into one marker
  • Scatter marker positions
@S-S-X
Copy link

S-S-X commented Jul 1, 2020

Maybe issue is here:

for i := 1; i <= 4; i++ {
payInvName := "pay" + strconv.Itoa(i)
giveInvName := "give" + strconv.Itoa(i)
pay := invMap[payInvName]
give := invMap[giveInvName]
if len(pay.Items) == 0 || len(give.Items) == 0 {
continue
}
o := mapobjectdb.NewMapObject(block.Pos, x, y, z, "shop")
o.Attributes["type"] = "smartshop"
o.Attributes["owner"] = md["owner"]
in_item := pay.Items[0].Name
in_count := math.Max(1, float64(pay.Items[0].Count))
out_item := give.Items[0].Name
out_count := math.Max(1, float64(give.Items[0].Count))
stock := 0
if isCreative {
stock = 999
} else {
for _, item := range mainInv.Items {
if item.Name == out_item {
stock += item.Count
}
}
}
//multiples of out_count
stock_factor := math.Floor(float64(stock) / float64(out_count))
o.Attributes["in_item"] = in_item
o.Attributes["in_count"] = strconv.Itoa(int(in_count))
o.Attributes["out_item"] = out_item
o.Attributes["out_count"] = strconv.Itoa(int(out_count))
o.Attributes["stock"] = strconv.Itoa(int(stock_factor))
list = append(list, o)
}

it creates 4 POI objects in loop while it should probably just collect data and create one POI after loop.

edit. Now reading description again I think this was already known but here's my opinion: Just concat everything into single POI and then if needed update UI elements so that all info can be displayed nicely.

@BuckarooBanzay
Copy link
Member

BuckarooBanzay commented Jul 2, 2020

Just fyi (or for me in the future when i find some time and motivation for this 😄)

Here is the drawing logic on the frontend for the POI's:

getMapObjects({
pos1: { x:x1, y:y1, z:z1 },
pos2: { x:x2, y:y2, z:z2 },
type: this.type
})
.then(function(objects){
//TODO: remove non-existing markers
objects.forEach(function(obj){
var hash = self.hashPos(obj.x, obj.y, obj.z);
var marker = self.currentObjects[hash];
var popup, icon;
if (marker) {
//marker exists
icon = self.getIcon(obj);
if (!icon) {
//icon does not wanna be displayed anymore
marker.remove();
return;
}
//set popup, if changed
popup = self.createPopup(obj);
if (popup)
marker.setPopupContent(popup);
//redraw icon, if changed
marker.setIcon(icon);
} else {
//marker does not exist
icon = self.getIcon(obj);
if (!icon) {
//icon does not want to be displayed
return;
}
marker = L.marker([obj.z, obj.x], {icon: icon});
popup = self.createPopup(obj);
if (popup)
marker.bindPopup(popup);
marker.addTo(self);
self.currentObjects[hash] = marker;
}
});
});

Obviously not intended for overlapping markers on the same position 😋

This triggers the createPopup() functions on the subclasses:

createPopup: function(obj){
return "<h4>" + obj.attributes.type + "</h4><hr>" +
"<b>Owner: </b> " + obj.attributes.owner + "<br>" +
"<b>Input: </b> " + obj.attributes.in_count + " x " + obj.attributes.in_item + "<br>" +
"<b>Output: </b> " + obj.attributes.out_count + " x " + obj.attributes.out_item + "<br>" +
"<b>Stock: </b> " + obj.attributes.stock + "<br>";
}

@Omikhleia

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants