Skip to content

Commit

Permalink
Merge pull request #1462 from matkoniecz/zoomer
Browse files Browse the repository at this point in the history
reduce chance that quest marker disappears as user zooms in [not ready for review]
  • Loading branch information
westnordost committed Jul 6, 2019
2 parents 95bba58 + 3e4035b commit f103eca
Showing 1 changed file with 21 additions and 4 deletions.
Expand Up @@ -385,6 +385,26 @@ public void addQuest(Quest quest, QuestGroup group)
}
*/

private int getQuestPriority(Quest quest){
// priority is decided by
// - primarily by quest type to allow quest prioritization
// - for quests of the same type - influenced by quest id,
// this is done to reduce chance that as user zoom in a quest disappears,
// especially in case where disappearing quest is one that user selected to solve

// main priority part - values fit into Integer, but with as large steps as possible
Integer order = questTypeOrder.get(quest.getType());
if(order == null) order = 0;
int freeValuesForEachQuest = Integer.MAX_VALUE / questTypeOrder.size();
order *= freeValuesForEachQuest;

// quest ID is used to add values unique to each quest to make ordering consistent
// freeValuesForEachQuest is an int, so % freeValuesForEachQuest will fit into int
int hopefullyUniqueValueForQuest = (int) (quest.getId() % freeValuesForEachQuest);

return order + hopefullyUniqueValueForQuest;
}

@UiThread
public void addQuests(Iterable quests, QuestGroup group)
{
Expand All @@ -406,9 +426,6 @@ public void addQuests(Iterable quests, QuestGroup group)

String questIconName = getActivity().getResources().getResourceEntryName(quest.getType().getIcon());

Integer order = questTypeOrder.get(quest.getType());
if(order == null) order = 0;

LatLon[] positions = quest.getMarkerLocations();

for (LatLon pos : positions)
Expand All @@ -434,7 +451,7 @@ public void addQuests(Iterable quests, QuestGroup group)
geoJson.append("\",\"");
geoJson.append("order");
geoJson.append("\":\"");
geoJson.append(order);
geoJson.append(getQuestPriority(quest));
geoJson.append("\"}}");
}
}
Expand Down

0 comments on commit f103eca

Please sign in to comment.