XFE Git
XFE Studio Git
Git 首页 全局搜索
XFE 主站 文档 NuGet

SpaceNinjaServer

A simple server for a small space ninja game

公开
关注 0 Fork 1 Star 0
返回提交历史

XFEstudio/SpaceNinjaServer

chore: improve changeDojoRoot (#1522)

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. Co-authored-by: Sainan <63328889+Sainan@users.noreply.github.com> Co-committed-by: Sainan <63328889+Sainan@users.noreply.github.com>

feb1dd47
Sainan <63328889+Sainan@users.noreply.github.com>
提交于

代码差异

5 个文件 +12 -12
Modified src/controllers/api/changeDojoRootController.ts +8 -12
@@ -15,6 +15,12 @@ export const changeDojoRootController: RequestHandler = async (req, res) => {
15 15 return;
16 16 }
17 17
18 // 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]}}"}
19 if (req.body) {
20 logger.debug(`data provided to ${req.path}: ${String(req.body)}`);
21 throw new Error("dojo reparent operation should not need deco repositioning"); // because we always provide SortId
22 }
23
18 24 const idToNode: Record<string, INode> = {};
19 25 guild.DojoComponents.forEach(x => {
20 26 idToNode[x._id.toString()] = {
@@ -43,23 +49,13 @@ export const changeDojoRootController: RequestHandler = async (req, res) => {
43 49 newRoot.component.pp = undefined;
44 50 newRoot.parent = undefined;
45 51
46 // Don't even ask me why this is needed because I don't know either
52 // Set/update SortId in top-to-bottom order
47 53 const stack: INode[] = [newRoot];
48 let i = 0;
49 const idMap: Record<string, Types.ObjectId> = {};
50 54 while (stack.length != 0) {
51 55 const top = stack.shift()!;
52 idMap[top.component._id.toString()] = new Types.ObjectId(
53 (++i).toString(16).padStart(8, "0") + top.component._id.toString().substr(8)
54 );
56 top.component.SortId = new Types.ObjectId();
55 57 top.children.forEach(x => stack.push(x));
56 58 }
57 guild.DojoComponents.forEach(x => {
58 x._id = idMap[x._id.toString()];
59 if (x.pi) {
60 x.pi = idMap[x.pi.toString()];
61 }
62 });
63 59
64 60 logger.debug("New tree:\n" + treeToString(newRoot));
65 61
Modified src/models/guildModel.ts +1 -0
@@ -43,6 +43,7 @@ const dojoLeaderboardEntrySchema = new Schema<IDojoLeaderboardEntry>(
43 43 );
44 44
45 45 const dojoComponentSchema = new Schema<IDojoComponentDatabase>({
46 SortId: Schema.Types.ObjectId,
46 47 pf: { type: String, required: true },
47 48 ppf: String,
48 49 pi: Schema.Types.ObjectId,
Modified src/routes/api.ts +1 -0
@@ -145,6 +145,7 @@ const apiRouter = express.Router();
145 145 apiRouter.get("/abandonLibraryDailyTask.php", abandonLibraryDailyTaskController);
146 146 apiRouter.get("/abortDojoComponentDestruction.php", abortDojoComponentDestructionController);
147 147 apiRouter.get("/cancelGuildAdvertisement.php", cancelGuildAdvertisementController);
148 apiRouter.get("/changeDojoRoot.php", changeDojoRootController);
148 149 apiRouter.get("/changeGuildRank.php", changeGuildRankController);
149 150 apiRouter.get("/checkDailyMissionBonus.php", checkDailyMissionBonusController);
150 151 apiRouter.get("/claimLibraryDailyTaskReward.php", claimLibraryDailyTaskRewardController);
Modified src/services/guildService.ts +1 -0
@@ -147,6 +147,7 @@ export const getDojoClient = async (
147 147 if (!componentId || dojoComponent._id.equals(componentId)) {
148 148 const clientComponent: IDojoComponentClient = {
149 149 id: toOid(dojoComponent._id),
150 SortId: toOid(dojoComponent.SortId ?? dojoComponent._id), // always providing a SortId so decos don't need repositioning to reparent
150 151 pf: dojoComponent.pf,
151 152 ppf: dojoComponent.ppf,
152 153 Name: dojoComponent.Name,
Modified src/types/guildTypes.ts +1 -0
@@ -190,6 +190,7 @@ export interface IDojoComponentDatabase
190 190 "id" | "SortId" | "pi" | "CompletionTime" | "DestructionTime" | "Decos" | "PaintBot"
191 191 > {
192 192 _id: Types.ObjectId;
193 SortId?: Types.ObjectId;
193 194 pi?: Types.ObjectId;
194 195 CompletionTime?: Date;
195 196 CompletionLogPending?: boolean;