chore: improve changeDojoRoot
All checks were successful
Build / build (18) (push) Successful in 52s
Build / build (20) (push) Successful in 1m20s
Build / build (18) (pull_request) Successful in 48s
Build / build (22) (push) Successful in 1m22s
Build / build (20) (pull_request) Successful in 1m21s
Build / build (22) (pull_request) Successful in 42s
All checks were successful
Build / build (18) (push) Successful in 52s
Build / build (20) (push) Successful in 1m20s
Build / build (18) (pull_request) Successful in 48s
Build / build (22) (push) Successful in 1m22s
Build / build (20) (pull_request) Successful in 1m21s
Build / build (22) (pull_request) Successful in 42s
Using SortId instead of actually changing the component ids. What's strange is that providing/omitting SortId does seem to make a difference in regards to deco positioning, which is presumably what the POST body would be for. I've opted to simply always provide the SortId in hopes that this avoids the need for repositioning entirely.
This commit is contained in:
parent
5cd18db7a7
commit
41623807e1
@ -15,6 +15,11 @@ 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.warn(`ignoring changeDojoRoot body, decos may end up beyond room bounds: ${String(req.body)}`);
|
||||
}
|
||||
|
||||
const idToNode: Record<string, INode> = {};
|
||||
guild.DojoComponents.forEach(x => {
|
||||
idToNode[x._id.toString()] = {
|
||||
@ -43,23 +48,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<string, Types.ObjectId> = {};
|
||||
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));
|
||||
|
||||
|
@ -43,6 +43,7 @@ const dojoLeaderboardEntrySchema = new Schema<IDojoLeaderboardEntry>(
|
||||
);
|
||||
|
||||
const dojoComponentSchema = new Schema<IDojoComponentDatabase>({
|
||||
SortId: Schema.Types.ObjectId,
|
||||
pf: { type: String, required: true },
|
||||
ppf: String,
|
||||
pi: Schema.Types.ObjectId,
|
||||
|
@ -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);
|
||||
|
@ -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.SortId : dojoComponent._id), // always providing a SortId so decos don't need repositioning to reparent
|
||||
pf: dojoComponent.pf,
|
||||
ppf: dojoComponent.ppf,
|
||||
Name: dojoComponent.Name,
|
||||
|
@ -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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user