feat(editor): add --remove-quest-objective for symmetric CRUD

Symmetric counterpart to --add-quest-objective. Quest design is
iterative — when an objective gets reworked or trimmed, you need
to remove the wrong one without nuking the entire quest.

  wowee_editor --remove-quest-objective <zoneDir> <questIdx> <objIdx>

Both indices are 0-based and reported by --info-quests / --list-quests.
Range-checks both: questIdx against quest count, objIdx against the
selected quest's objective count. Each errors with a precise out-of-
range message.

Verified: scaffolded zone, added quest with 3 objectives (kill /
collect / talk), removed objective at index 1 (the collect),
--info-quests confirms '1 kill, 0 collect, 1 talk' afterward.
Bad quest and bad objective indices both rejected with exit 1.

Quest-authoring CLI is now fully symmetric:
  --add-quest                   --remove-quest
  --add-quest-objective         --remove-quest-objective
  --add-quest-reward-item       (additive only — items are dedup'd)
  --set-quest-reward            (idempotent field-level update)
This commit is contained in:
Kelsi 2026-05-06 12:35:10 -07:00
parent 9c46d3aeeb
commit 1328998ec5

View file

@ -419,6 +419,8 @@ static void printUsage(const char* argv0) {
std::printf(" Append one quest to <zoneDir>/quests.json and exit\n");
std::printf(" --add-quest-objective <zoneDir> <questIdx> <kill|collect|talk|explore|escort|use> <targetName> [count]\n");
std::printf(" Append one objective to a quest by index\n");
std::printf(" --remove-quest-objective <zoneDir> <questIdx> <objIdx>\n");
std::printf(" Remove the objective at given 0-based index from a quest\n");
std::printf(" --add-quest-reward-item <zoneDir> <questIdx> <itemPath> [more...]\n");
std::printf(" Append item reward(s) to a quest's reward.itemRewards list\n");
std::printf(" --set-quest-reward <zoneDir> <questIdx> [--xp N] [--gold N] [--silver N] [--copper N]\n");
@ -527,6 +529,7 @@ int main(int argc, char* argv[]) {
"--scaffold-zone", "--add-tile",
"--add-creature", "--add-object", "--add-quest",
"--add-quest-objective", "--add-quest-reward-item", "--set-quest-reward",
"--remove-quest-objective",
"--remove-creature", "--remove-object", "--remove-quest",
"--copy-zone", "--rename-zone",
"--build-woc", "--regen-collision", "--fix-zone",
@ -576,6 +579,11 @@ int main(int argc, char* argv[]) {
"--add-quest-objective requires <zoneDir> <questIdx> <type> <targetName>\n");
return 1;
}
if (std::strcmp(argv[i], "--remove-quest-objective") == 0 && i + 3 >= argc) {
std::fprintf(stderr,
"--remove-quest-objective requires <zoneDir> <questIdx> <objIdx>\n");
return 1;
}
if (std::strcmp(argv[i], "--add-quest-reward-item") == 0 && i + 3 >= argc) {
std::fprintf(stderr,
"--add-quest-reward-item requires <zoneDir> <questIdx> <itemPath>\n");
@ -3261,6 +3269,57 @@ int main(int argc, char* argv[]) {
obj.description.c_str(), idx, q->title.c_str(),
q->objectives.size());
return 0;
} else if (std::strcmp(argv[i], "--remove-quest-objective") == 0 && i + 3 < argc) {
// Symmetric counterpart to --add-quest-objective. Removes the
// objective at <objIdx> within quest <questIdx>. Pair with
// --info-quests / --list-quests to find the right indices.
std::string zoneDir = argv[++i];
std::string qIdxStr = argv[++i];
std::string oIdxStr = argv[++i];
std::string path = zoneDir + "/quests.json";
if (!std::filesystem::exists(path)) {
std::fprintf(stderr, "remove-quest-objective: %s not found\n", path.c_str());
return 1;
}
int qIdx, oIdx;
try {
qIdx = std::stoi(qIdxStr);
oIdx = std::stoi(oIdxStr);
} catch (...) {
std::fprintf(stderr, "remove-quest-objective: bad index\n");
return 1;
}
wowee::editor::QuestEditor qe;
if (!qe.loadFromFile(path)) {
std::fprintf(stderr, "remove-quest-objective: failed to load %s\n",
path.c_str());
return 1;
}
if (qIdx < 0 || qIdx >= static_cast<int>(qe.questCount())) {
std::fprintf(stderr,
"remove-quest-objective: questIdx %d out of range [0, %zu)\n",
qIdx, qe.questCount());
return 1;
}
wowee::editor::Quest* q = qe.getQuest(qIdx);
if (!q) return 1;
if (oIdx < 0 || oIdx >= static_cast<int>(q->objectives.size())) {
std::fprintf(stderr,
"remove-quest-objective: objIdx %d out of range [0, %zu)\n",
oIdx, q->objectives.size());
return 1;
}
std::string removedDesc = q->objectives[oIdx].description;
q->objectives.erase(q->objectives.begin() + oIdx);
if (!qe.saveToFile(path)) {
std::fprintf(stderr, "remove-quest-objective: failed to write %s\n",
path.c_str());
return 1;
}
std::printf("Removed objective '%s' (was index %d) from quest %d ('%s'), now %zu remaining\n",
removedDesc.c_str(), oIdx, qIdx, q->title.c_str(),
q->objectives.size());
return 0;
} else if (std::strcmp(argv[i], "--add-quest-reward-item") == 0 && i + 3 < argc) {
// Append one or more item rewards to a quest. Multiple paths
// can be passed in a single invocation: