fix(properties): top property slots show only their own world

The news screen's slot tooltip names the slot's own property world
whatever property is sent for it, so a property of another world was
shown under the wrong name. Each slot now only shows a property of its
own world: a location stored by the older per-slot setting is kept in
the table but not used, full auto fills each slot with its own world's
top property instead of the top four across every world, and the
dashboard no longer offers a location or candidates from other worlds.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Aaron Kimbrell
2026-09-27 18:55:56 -05:00
parent 03842d794a
commit 37459e0019
4 changed files with 39 additions and 61 deletions

View File

@@ -135,9 +135,13 @@ namespace HotPropertySlots {
return entered ? entered : any;
}
// A slot's location as stored (0: none) if it is still a property world, else the slot's own world
inline uint32_t Location(uint32_t stored, const Slot& slot, const std::vector<uint32_t>& worlds) {
return stored != 0 && std::find(worlds.begin(), worlds.end(), stored) != worlds.end() ? stored : slot.mapId;
/**
* A slot's location: always the slot's own world. The news screen's tooltip names the slot's world whatever
* property is sent for it, so a property of another world would be shown under the wrong name. A location stored
* by an older version (featured_properties.zone_id) is kept in the table but not used.
*/
inline uint32_t Location(uint32_t /*stored*/, const Slot& slot, const std::vector<uint32_t>& /*worlds*/) {
return slot.mapId;
}
constexpr int32_t PRIVACY_PUBLIC = 2; // ePropertyPrivacyOption::Public
@@ -172,14 +176,13 @@ namespace HotPropertySlots {
constexpr uint32_t CANDIDATES_PER_WORLD = NEWS_SPAWN_NAMES.size();
/**
* The worlds whose best CANDIDATES_PER_WORLD candidates Resolve needs (0: every world, for full auto). The picked
* The worlds whose best CANDIDATES_PER_WORLD candidates Resolve needs (full auto: every slot's world). The picked
* properties have to be added to the candidates as well, when they may be shown in their slot's location.
*/
inline std::vector<uint32_t> CandidateWorlds(const std::vector<Choice>& choices, bool fullAuto) {
if (fullAuto) return { 0 };
std::vector<uint32_t> worlds;
for (const auto& choice : choices) {
if (choice.mode != eMode::EMPTY && std::find(worlds.begin(), worlds.end(), choice.mapId) == worlds.end()) worlds.push_back(choice.mapId);
if ((fullAuto || choice.mode != eMode::EMPTY) && std::find(worlds.begin(), worlds.end(), choice.mapId) == worlds.end()) worlds.push_back(choice.mapId);
}
return worlds;
}
@@ -187,7 +190,8 @@ namespace HotPropertySlots {
/**
* What each slot shows (one entry per choice, in slot order), so that no property is shown twice.
* candidates: the properties that may be shown (see CandidateWorlds); a property listed twice counts once.
* Full auto ignores the choices: the slots show the candidates with the most reputation, in slot order.
* Full auto ignores the modes and picks: each slot shows its location's candidate with the most reputation, in slot
* order.
* Otherwise the picks come first, in slot order: a pick is shown when it is a candidate of the slot's location that
* an earlier slot doesn't show, else the slot falls back to AUTO. Then the AUTO slots, in slot order, each show the
* candidate of their location with the most reputation that isn't shown yet (two on one world: its #1 and #2).
@@ -210,7 +214,7 @@ namespace HotPropertySlots {
};
if (fullAuto) {
for (size_t i = 0; i < choices.size(); i++) show(i, best(std::nullopt));
for (size_t i = 0; i < choices.size(); i++) show(i, best(choices[i].mapId));
return showing;
}

View File

@@ -49,13 +49,13 @@ namespace {
return slot == slots.end() ? nullptr : &*slot;
}
// A location given by the dashboard (a property world's map id); missing: the slot's own world
// A location given by the dashboard: only the slot's own world (missing means that too), since the news screen
// names the slot's world whatever property is sent for it (HotPropertySlots::Location)
std::optional<uint32_t> ParseLocation(const nlohmann::json& value, const HotPropertySlots::Slot& slot) {
if (value.is_null()) return slot.mapId;
const auto mapId = value.is_string() ? GeneralUtils::TryParse<uint32_t>(value.get<std::string>())
: value.is_number_unsigned() ? std::optional<uint32_t>(value.get<uint32_t>()) : std::nullopt;
const auto& worlds = GetNewsWorlds().worlds;
if (!mapId || std::find(worlds.begin(), worlds.end(), *mapId) == worlds.end()) return std::nullopt;
if (mapId != slot.mapId) return std::nullopt;
return mapId;
}
@@ -207,13 +207,13 @@ void FeaturedProperties::RegisterRoutes() {
});
Route(eHTTPMethod::GET, "/api/featured_properties/:template/candidates", Perm("feature_properties"),
"Approved public properties a \"Today's Top Properties\" slot can show, most reputation first (at most 25). Query: ?location= (a property world's map id, default the slot's own), ?search= (name, description or owner)",
"Approved public properties a \"Today's Top Properties\" slot can show, most reputation first (at most 25). Only the slot's own world (the news screen names it). Query: ?search= (name, description or owner)",
[](HTTPReply& reply, const HTTPContext& context) {
const auto* slot = FindSlot(PathId<uint32_t>(context.path, 2));
if (!slot) return JsonError(reply, eHTTPStatusCode::NOT_FOUND, "No such slot");
const auto locationValue = QueryValue(context.queryString, "location");
const auto location = ParseLocation(locationValue.empty() ? nlohmann::json(nullptr) : nlohmann::json(locationValue), *slot);
if (!location) return JsonError(reply, eHTTPStatusCode::BAD_REQUEST, "location must be a property world");
if (!location) return JsonError(reply, eHTTPStatusCode::BAD_REQUEST, "A slot can only show a property of its own world (the news screen names that world)");
const auto candidates = Candidates(*location, MAX_MATCHES, QueryValue(context.queryString, "search").substr(0, MAX_SEARCH));
nlohmann::json list = nlohmann::json::array();
@@ -222,7 +222,7 @@ void FeaturedProperties::RegisterRoutes() {
});
Route(eHTTPMethod::POST, "/api/featured_properties/:template", Perm("feature_properties"),
"Choose what a \"Today's Top Properties\" slot shows. Body: {location (a property world's map id, default the slot's own), mode: auto|picked|empty, property_id (for picked: an approved public property of the location that no other slot picked)}",
"Choose what a \"Today's Top Properties\" slot shows. Body: {mode: auto|picked|empty, property_id (for picked: an approved public property of the slot's own world that no other slot picked)}",
[](HTTPReply& reply, const HTTPContext& context) {
const auto templateId = PathId<uint32_t>(context.path, 2);
if (!templateId) return JsonError(reply, eHTTPStatusCode::BAD_REQUEST, "Invalid slot");
@@ -235,7 +235,7 @@ void FeaturedProperties::RegisterRoutes() {
const auto mode = HotPropertySlots::ParseMode(body->value("mode", ""));
if (!mode) return JsonError(reply, eHTTPStatusCode::BAD_REQUEST, "mode must be auto, picked or empty");
const auto location = ParseLocation(body->contains("location") ? (*body)["location"] : nlohmann::json(nullptr), *slot);
if (!location) return JsonError(reply, eHTTPStatusCode::BAD_REQUEST, "location must be a property world");
if (!location) return JsonError(reply, eHTTPStatusCode::BAD_REQUEST, "A slot can only show a property of its own world (the news screen names that world)");
IFeaturedProperties::FeaturedSlot row;
row.templateId = slot->templateId;

View File

@@ -19,7 +19,7 @@
<div class="card-header d-flex flex-wrap justify-content-between align-items-start gap-2">
<div>
<h5 class="mb-0"><button type="button" class="btn btn-link p-0 text-body text-decoration-none fs-5 dropdown-toggle" data-bs-toggle="collapse" data-bs-target="#topPropertiesBody" aria-expanded="true" aria-controls="topPropertiesBody">Today's Top Properties</button></h5>
<details class="about-text"><summary>How the slots are picked</summary><div>The four slots of the game's news screen. Only approved public properties can be shown, and never one in two slots. <em>Full auto</em> shows the four with the most reputation across every property world; <em>Per slot</em> lets each slot show a property of any property world (its location): <em>Auto</em> the location's one with the most reputation not shown in another slot, a picked one, or nothing. Players see a change the next time they open the news screen (within 30 seconds).</div></details>
<details class="about-text"><summary>How the slots are picked</summary><div>The four slots of the game's news screen. Each slot belongs to one property world and can only show a property of that world, since the game names the slot's world whatever property is in it. Only approved public properties can be shown, and never one in two slots. <em>Full auto</em> shows each world's property with the most reputation; <em>Per slot</em> lets each slot show its world's <em>Auto</em> pick (the most reputation not shown in another slot), a picked one, or nothing. Players see a change the next time they open the news screen (within 30 seconds).</div></details>
<div class="small text-body-secondary" id="topPropertiesSetBy"></div>
</div>
<div class="btn-group btn-group-sm flex-shrink-0" role="group" aria-label="Top properties mode">
@@ -86,10 +86,6 @@ $(function () {
var modeInputs = document.querySelectorAll('input[name="topPropertiesMode"]');
var propLabel = function (p) { return (p.name || '(unnamed)') + ' by ' + (p.owner_name || '?') + ' \u2014 ' + Number(p.reputation || 0).toLocaleString() + ' rep'; };
var countLabel = function (n) { return n + ' approved public ' + (n === 1 ? 'property' : 'properties'); };
// The news screen's tooltip is the slot's own world, whatever world the property is on
var tooltipNote = function (s, location) {
return String(location) === String(s.map_id) ? '' : 'In game the slot\'s tooltip still names ' + s.zone_name + '.';
};
var renderSlots = function (state) {
var slots = state.slots || [];
var fullAuto = !!state.full_auto;
@@ -97,24 +93,15 @@ $(function () {
document.getElementById('topPropertiesSetBy').textContent = state.settings_updated_at
? 'Switched to ' + (fullAuto ? 'full auto' : 'per slot') + ' by ' + (state.settings_updated_by || '?') + ' ' + new Date(state.settings_updated_at * 1000).toLocaleString() : '';
if (!slots.length) { slotsEl.innerHTML = '<div class="col text-body-secondary">No property worlds found in the client data.</div>'; return; }
var worldOptions = function (selected) {
return (state.worlds || []).map(function (w) {
return '<option value="' + w.map_id + '"' + (String(w.map_id) === String(selected) ? ' selected' : '') + '>' + esc(w.zone_name) + '</option>';
}).join('');
};
slotsEl.innerHTML = slots.map(function (s) {
var showing = s.showing
? fmt.link('/properties/' + s.showing.id, s.showing.name || '(unnamed)') + ' <span class="text-body-secondary">by ' + esc(s.showing.owner_name) +
(String(s.showing.zone_id) !== String(s.map_id) ? ', on ' + esc(s.showing.zone_name) : '') + '</span>'
? fmt.link('/properties/' + s.showing.id, s.showing.name || '(unnamed)') + ' <span class="text-body-secondary">by ' + esc(s.showing.owner_name) + '</span>'
: '<span class="text-body-secondary">Nothing (locked slot)</span>';
var showingNote = s.showing ? tooltipNote(s, s.showing.zone_id) : '';
var warn = fullAuto ? '' : s.picked_unavailable ? '<div class="small text-warning mt-1">The picked property is no longer approved and public in ' + esc(s.location_name) + ', so the slot falls back to Auto.</div>'
var warn = fullAuto ? '' : s.picked_unavailable ? '<div class="small text-warning mt-1">The picked property isn\'t an approved public property of ' + esc(s.zone_name) + ' (any more), so the slot falls back to Auto.</div>'
: s.picked_shown_elsewhere ? '<div class="small text-warning mt-1">The picked property is already shown in an earlier slot, so this one falls back to Auto.</div>' : '';
var changed = s.updated_at ? '<div class="small text-body-secondary mt-1">Set by ' + esc(s.updated_by || '?') + ' ' + esc(new Date(s.updated_at * 1000).toLocaleString()) + '</div>' : '';
var controls = fullAuto ? '<div class="small text-body-secondary mb-2">Full auto is on: this slot\'s own settings (' + esc(s.location_name) + ', ' + esc(s.mode) + ') are kept for when you switch back to per slot.</div>' :
'<label class="form-label small mb-1">Location</label>' +
'<select class="form-select form-select-sm mb-1" data-location aria-label="Location">' + worldOptions(s.location) + '</select>' +
'<div class="small text-body-secondary mb-2"><span data-count>' + countLabel(s.candidate_total) + '</span><span class="d-block text-info" data-tooltip-note>' + esc(tooltipNote(s, s.location)) + '</span></div>' +
var controls = fullAuto ? '<div class="small text-body-secondary mb-2">Full auto is on: this slot\'s own setting (' + esc(s.mode) + ') is kept for when you switch back to per slot.</div>' :
'<div class="small text-body-secondary mb-2"><span data-count>' + countLabel(s.candidate_total) + '</span></div>' +
'<select class="form-select form-select-sm mb-2" data-mode aria-label="What the slot shows">' +
'<option value="auto"' + (s.mode === 'auto' ? ' selected' : '') + '>Auto (most reputation)</option>' +
'<option value="picked"' + (s.mode === 'picked' ? ' selected' : '') + (s.candidate_total || s.picked ? '' : ' disabled') + '>Pick a property</option>' +
@@ -124,35 +111,21 @@ $(function () {
'<button class="btn btn-sm btn-primary" data-save>Save</button>';
return '<div class="col-12 col-md-6 col-xl-3"><div class="border rounded p-3 h-100" data-slot="' + s.template_id + '">' +
'<div class="fw-semibold">' + esc(s.zone_name) + ' slot</div>' + controls +
'<div class="small mt-2">Showing: ' + showing + '</div>' +
(showingNote ? '<div class="small text-info">' + esc(showingNote) + '</div>' : '') + warn + (fullAuto ? '' : changed) +
'<div class="small mt-2">Showing: ' + showing + '</div>' + warn + (fullAuto ? '' : changed) +
'</div></div>';
}).join('');
if (fullAuto) return;
slots.forEach(function (s) {
var box = slotsEl.querySelector('[data-slot="' + s.template_id + '"]');
var select = SearchSelect(box.querySelector('[data-property]'), {
SearchSelect(box.querySelector('[data-property]'), {
value: s.picked ? s.property_id : '',
label: s.picked ? propLabel(s.picked) : '',
search: function (text) {
var location = box.querySelector('[data-location]').value;
return api.get('/api/featured_properties/' + s.template_id + '/candidates?location=' + encodeURIComponent(location) + '&search=' + encodeURIComponent(text)).then(function (d) {
return api.get('/api/featured_properties/' + s.template_id + '/candidates?search=' + encodeURIComponent(text)).then(function (d) {
return (d.properties || []).map(function (p) { return { value: p.id, label: propLabel(p) }; });
});
}
});
// Another location: the pick has to be made there, and how many there are to pick from changes
box.querySelector('[data-location]').addEventListener('change', function (e) {
var location = e.target.value;
if (location === String(s.location) && s.picked) select.set(s.property_id, propLabel(s.picked));
else select.set('', '');
box.querySelector('[data-tooltip-note]').textContent = tooltipNote(s, location);
api.get('/api/featured_properties/' + s.template_id + '/candidates?location=' + encodeURIComponent(location)).then(function (d) {
if (box.querySelector('[data-location]').value !== location) return;
box.querySelector('[data-count]').textContent = countLabel(d.total || 0);
box.querySelector('[data-mode] option[value="picked"]').disabled = !d.total;
}).catch(function () {});
});
});
};
var loadSlots = function () {
@@ -179,7 +152,7 @@ $(function () {
if (!e.target.matches('[data-save]')) return;
var box = e.target.closest('[data-slot]');
var mode = box.querySelector('[data-mode]').value;
var body = { mode: mode, location: Number(box.querySelector('[data-location]').value) };
var body = { mode: mode };
if (mode === 'picked') {
body.property_id = box.querySelector('[data-property]').dataset.value;
if (!body.property_id) { toast('Search for a property and pick one first', 'warning'); return; }

View File

@@ -90,9 +90,10 @@ TEST(HotPropertySlotsTests, PropertyWorldsAreTheEnteredTemplateMaps) {
TEST(HotPropertySlotsTests, LocationDefaultsToTheSlotsWorld) {
const auto worlds = PropertyWorlds(TEMPLATES, ENTRANCES);
const Slot blockYard{ 25166, 1150, "AGSmallProperty" };
EXPECT_EQ(Location(0, blockYard, worlds), 1150u); // rows from before locations
EXPECT_EQ(Location(1251, blockYard, worlds), 1251u); // Nimbus Isle
EXPECT_EQ(Location(58001, blockYard, worlds), 1150u); // not a property world (any more)
EXPECT_EQ(Location(0, blockYard, worlds), 1150u);
// A location stored by an older version isn't used: the news screen would name the slot's own world
EXPECT_EQ(Location(1251, blockYard, worlds), 1150u);
EXPECT_EQ(Location(58001, blockYard, worlds), 1150u);
}
namespace {
@@ -151,17 +152,17 @@ TEST(HotPropertySlotsTests, APickOfAnotherWorld) {
EXPECT_EQ(Shown(Resolve(choices, false, CANDIDATES)), (Ids{ 202, 201, std::nullopt, 301 }));
}
TEST(HotPropertySlotsTests, FullAutoShowsTheTopFourAcrossEveryWorld) {
// The choices don't matter
const std::vector<Choice> choices{ { eMode::EMPTY, 1150 }, { eMode::PICKED, 1150, 103 }, { eMode::AUTO, 1350 }, { eMode::AUTO, 1450 } };
TEST(HotPropertySlotsTests, FullAutoShowsEachSlotsWorldsBest) {
// The modes and picks don't matter; each slot still shows only its own world
const std::vector<Choice> choices{ { eMode::EMPTY, 1150 }, { eMode::PICKED, 1150, 103 }, { eMode::AUTO, 1350 }, { eMode::AUTO, 1151 } };
const auto showing = Resolve(choices, true, CANDIDATES);
EXPECT_EQ(Shown(showing), (Ids{ 201, 301, 101, 102 }));
EXPECT_EQ(Shown(showing), (Ids{ 101, 102, std::nullopt, 201 }));
for (const auto& slot : showing) EXPECT_FALSE(slot.pickFellBack);
}
TEST(HotPropertySlotsTests, FullAutoWithFewerPropertiesThanSlots) {
const std::vector<Choice> choices(4);
EXPECT_EQ(Shown(Resolve(choices, true, { { 202, 1151, 50 }, { 301, 1250, 700 } })), (Ids{ 301, 202, std::nullopt, std::nullopt }));
const std::vector<Choice> choices{ { eMode::AUTO, 1150 }, { eMode::AUTO, 1151 }, { eMode::AUTO, 1250 }, { eMode::AUTO, 1350 } };
EXPECT_EQ(Shown(Resolve(choices, true, { { 202, 1151, 50 }, { 301, 1250, 700 } })), (Ids{ std::nullopt, 202, 301, std::nullopt }));
EXPECT_EQ(Shown(Resolve(choices, true, {})), (Ids(4, std::nullopt)));
}
@@ -176,5 +177,5 @@ TEST(HotPropertySlotsTests, ACandidateListedTwiceCountsOnce) {
TEST(HotPropertySlotsTests, CandidateWorlds) {
const std::vector<Choice> choices{ { eMode::AUTO, 1150 }, { eMode::PICKED, 1151, 202 }, { eMode::EMPTY, 1350 }, { eMode::AUTO, 1150 } };
EXPECT_EQ(CandidateWorlds(choices, false), (std::vector<uint32_t>{ 1150, 1151 }));
EXPECT_EQ(CandidateWorlds(choices, true), (std::vector<uint32_t>{ 0 }));
EXPECT_EQ(CandidateWorlds(choices, true), (std::vector<uint32_t>{ 1150, 1151, 1350 }));
}