diff --git a/src/controllers/api/changeDojoRootController.ts b/src/controllers/api/changeDojoRootController.ts index e28b92d9..1c7cb792 100644 --- a/src/controllers/api/changeDojoRootController.ts +++ b/src/controllers/api/changeDojoRootController.ts @@ -15,6 +15,12 @@ export const changeDojoRootController: RequestHandler = async (req, res) => { return; } + // Example POST body: {"pivot":[0, 0, -64],"components":"{\"670429301ca0a63848ccc467\":{\"R\":[0,0,0],\"P\":[0,3,32]},\"6704254a1ca0a63848ccb33c\":{\"R\":[0,0,0],\"P\":[0,9.25,-32]},\"670429461ca0a63848ccc731\":{\"R\":[-90,0,0],\"P\":[-47.999992370605,3,16]}}"} + if (req.body) { + logger.debug(`data provided to ${req.path}: ${String(req.body)}`); + throw new Error("dojo reparent operation should not need deco repositioning"); // because we always provide SortId + } + const idToNode: Record = {}; guild.DojoComponents.forEach(x => { idToNode[x._id.toString()] = { @@ -43,23 +49,13 @@ export const changeDojoRootController: RequestHandler = async (req, res) => { newRoot.component.pp = undefined; newRoot.parent = undefined; - // Don't even ask me why this is needed because I don't know either + // Set/update SortId in top-to-bottom order const stack: INode[] = [newRoot]; - let i = 0; - const idMap: Record = {}; while (stack.length != 0) { const top = stack.shift()!; - idMap[top.component._id.toString()] = new Types.ObjectId( - (++i).toString(16).padStart(8, "0") + top.component._id.toString().substr(8) - ); + top.component.SortId = new Types.ObjectId(); top.children.forEach(x => stack.push(x)); } - guild.DojoComponents.forEach(x => { - x._id = idMap[x._id.toString()]; - if (x.pi) { - x.pi = idMap[x.pi.toString()]; - } - }); logger.debug("New tree:\n" + treeToString(newRoot)); diff --git a/src/models/guildModel.ts b/src/models/guildModel.ts index 2d757039..7cd28c6c 100644 --- a/src/models/guildModel.ts +++ b/src/models/guildModel.ts @@ -43,6 +43,7 @@ const dojoLeaderboardEntrySchema = new Schema( ); const dojoComponentSchema = new Schema({ + SortId: Schema.Types.ObjectId, pf: { type: String, required: true }, ppf: String, pi: Schema.Types.ObjectId, diff --git a/src/routes/api.ts b/src/routes/api.ts index d8be0cb3..7dfd562f 100644 --- a/src/routes/api.ts +++ b/src/routes/api.ts @@ -145,6 +145,7 @@ const apiRouter = express.Router(); apiRouter.get("/abandonLibraryDailyTask.php", abandonLibraryDailyTaskController); apiRouter.get("/abortDojoComponentDestruction.php", abortDojoComponentDestructionController); apiRouter.get("/cancelGuildAdvertisement.php", cancelGuildAdvertisementController); +apiRouter.get("/changeDojoRoot.php", changeDojoRootController); apiRouter.get("/changeGuildRank.php", changeGuildRankController); apiRouter.get("/checkDailyMissionBonus.php", checkDailyMissionBonusController); apiRouter.get("/claimLibraryDailyTaskReward.php", claimLibraryDailyTaskRewardController); diff --git a/src/services/guildService.ts b/src/services/guildService.ts index f8e33a5e..3dbddc02 100644 --- a/src/services/guildService.ts +++ b/src/services/guildService.ts @@ -147,6 +147,7 @@ export const getDojoClient = async ( if (!componentId || dojoComponent._id.equals(componentId)) { const clientComponent: IDojoComponentClient = { id: toOid(dojoComponent._id), + SortId: toOid(dojoComponent.SortId ?? dojoComponent._id), // always providing a SortId so decos don't need repositioning to reparent pf: dojoComponent.pf, ppf: dojoComponent.ppf, Name: dojoComponent.Name, diff --git a/src/types/guildTypes.ts b/src/types/guildTypes.ts index 2502b57e..518e6bcf 100644 --- a/src/types/guildTypes.ts +++ b/src/types/guildTypes.ts @@ -190,6 +190,7 @@ export interface IDojoComponentDatabase "id" | "SortId" | "pi" | "CompletionTime" | "DestructionTime" | "Decos" | "PaintBot" > { _id: Types.ObjectId; + SortId?: Types.ObjectId; pi?: Types.ObjectId; CompletionTime?: Date; CompletionLogPending?: boolean;