Skip to content

Commit

Permalink
ClaimRoomProcessのdelegate処理を追加
Browse files Browse the repository at this point in the history
  • Loading branch information
mitsuyoshi-yamazaki committed Aug 20, 2024
1 parent 08fd9fe commit 6e2e185
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 3 deletions.
35 changes: 34 additions & 1 deletion src/os_v5/processes/application/event_driven_test_process.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export type EventDrivenTestProcessId = ProcessId<Dependency, string, Api, EventD

export class EventDrivenTestProcess extends ApplicationProcess<Dependency, string, Api, EventDrivenTestProcessState, EventDrivenTestProcess> {
public readonly applicationName = "EventDrivenTest"
public readonly version = new SemanticVersion(1, 0, 1)
public readonly version = new SemanticVersion(1, 0, 2)

public readonly dependencies: ProcessDependencies = {
processes: [
Expand Down Expand Up @@ -175,10 +175,38 @@ export class EventDrivenTestProcess extends ApplicationProcess<Dependency, strin
)
},

// ---- ClaimRoomProcess ---- //
claimRoomDidFinishClaiming: (process: ClaimRoomProcess): void => {
SystemCalls.logger.log(this, `claimRoomDidFinishClaiming: ${ConsoleUtility.roomLink(process.roomName)}`)

this.childProcessState = {
case: "finished",
t: Game.time,
}
},

claimRoomDidFailClaiming: (process: ClaimRoomProcess, problem: ClaimRoomProblem): void => {
const problemDescription = ((): string => {
switch (problem.case) {
case "claim_failed":
return `[claim_failed] ${problem.reason}`
case "controller_unreachable":
return "[controller_unreachable]"
case "creep_attacked":
return "[creep_attacked]"
case "room_unreachable":
return `[room_unreachable] ${ConsoleUtility.roomLink(problem.blockingRoomName)}`
case "unknown":
return `[unknown] ${problem.reason}`
}
})()
SystemCalls.logger.log(this, `claimRoomDidFailClaiming: ${ConsoleUtility.roomLink(process.roomName)}, ${problemDescription}`)

this.childProcessState = {
case: "failed",
reason: `${ConsoleUtility.roomLink(process.roomName)}: ${problemDescription}`,
t: Game.time,
}
},
}
}
Expand Down Expand Up @@ -218,6 +246,8 @@ export class EventDrivenTestProcess extends ApplicationProcess<Dependency, strin
}
})

SystemCalls.logger.log(this, `Launched ${process}`)

return {
case: "running",
p: process.processId as AnyProcessId,
Expand All @@ -231,6 +261,8 @@ export class EventDrivenTestProcess extends ApplicationProcess<Dependency, strin
}
})()

SystemCalls.logger.log(this, `Launch ${processType} failed: ${error}`)

return {
case: "failed",
reason: `Launching ${processType} failed with: ${error}`,
Expand Down Expand Up @@ -261,6 +293,7 @@ export class EventDrivenTestProcess extends ApplicationProcess<Dependency, strin
})()

const descriptions: string[] = [
"- " + ConsoleUtility.colored(`${this.version}`, "white"),
`- ${ConsoleUtility.colored(this.identifier, "white")}`,
`- Child process state: ${stateDescription}`,
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ export class ClaimRoomProcess extends Process<Dependency, RoomName, void, ClaimR
case ERR_NO_PATH:
return {
case: "room_unreachable",
blockingRoom: creep.room.name,
blockingRoomName: creep.room.name,
}

case ERR_NOT_OWNER:
Expand Down
2 changes: 1 addition & 1 deletion src/os_v5/processes/economy/claim_room/delegate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export type ClaimRoomProblemControllerUnreachable = {
}
export type ClaimRoomProblemRoomUnreachable = {
readonly case: "room_unreachable"
readonly blockingRoom: RoomName
readonly blockingRoomName: RoomName
}
export type ClaimRoomProblemUnknown = {
readonly case: "unknown"
Expand Down

0 comments on commit 6e2e185

Please sign in to comment.