Skip to content

Commit 52bf659

Browse files
committed
Better Naming
1 parent da113f9 commit 52bf659

File tree

2 files changed

+57
-30
lines changed

2 files changed

+57
-30
lines changed

fission/src/mirabuf/ProtectedZoneSceneObject.ts

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,10 @@ import MatchMode, { MatchModeType } from "@/systems/MatchMode"
2020

2121
export enum ContactType {
2222
ROBOT_ENTERS = "Robot Enters",
23+
ANY_ROBOT_INSIDE = "Collision with Any Robot Inside",
2324
BOTH_ROBOTS_INSIDE = "Collision with Both Robots Inside",
24-
OPPONENT_ROBOT_INSIDE = "Collision with Opponent Robot Inside",
25-
ALLY_ROBOT_INSIDE = "Collision with Ally Robot Inside",
25+
RED_ROBOT_INSIDE = "Collision with Red Robot Inside",
26+
BLUE_ROBOT_INSIDE = "Collision with Blue Robot Inside",
2627
}
2728

2829
class ProtectedZoneSceneObject extends SceneObject {
@@ -259,7 +260,6 @@ class ProtectedZoneSceneObject extends SceneObject {
259260
if (Date.now() - this._lastRobotCollisionTime < 500) return
260261

261262
let shouldPenalize = false
262-
let robotToPenalize: MirabufSceneObject | undefined
263263

264264
// Find the robot that has the opposite alliance from the zone
265265
const opposingRobot = [collisionObjectBody1, collisionObjectBody2].find(
@@ -271,35 +271,42 @@ class ProtectedZoneSceneObject extends SceneObject {
271271
// Penalize opposing robot if both robots are inside the zone and colliding
272272
if (this.isRobotInside(collisionObjectBody1) && this.isRobotInside(collisionObjectBody2)) {
273273
shouldPenalize = true
274-
robotToPenalize = opposingRobot
275274
}
276275
break
277276

278-
case ContactType.OPPONENT_ROBOT_INSIDE:
279-
// Penalize if the opposing robot is inside when collision occurs
280-
if (this.isRobotInside(opposingRobot)) {
277+
case ContactType.ANY_ROBOT_INSIDE:
278+
// Penalize if any robot is inside the zone when collision occurs
279+
if (this.isRobotInside(collisionObjectBody1) || this.isRobotInside(collisionObjectBody2)) {
281280
shouldPenalize = true
282-
robotToPenalize = opposingRobot
283281
}
284282
break
285283

286-
case ContactType.ALLY_ROBOT_INSIDE: {
287-
// Penalize opposing robot if an ally robot is inside when collision occurs
288-
const allyRobot = [collisionObjectBody1, collisionObjectBody2].find(
289-
robot => robot.alliance === this._prefs?.alliance
284+
case ContactType.RED_ROBOT_INSIDE:
285+
// Penalize if the red robot is inside the zone when collision occurs
286+
const redRobot = [collisionObjectBody1, collisionObjectBody2].find(
287+
robot => robot.alliance === "red"
290288
)
291-
if (allyRobot && this.isRobotInside(allyRobot)) {
289+
if (redRobot && this.isRobotInside(redRobot)) {
290+
shouldPenalize = true
291+
}
292+
break
293+
294+
case ContactType.BLUE_ROBOT_INSIDE: {
295+
// Penalize if the blue robot is inside the zone when collision occurs
296+
const blueRobot = [collisionObjectBody1, collisionObjectBody2].find(
297+
robot => robot.alliance === "blue"
298+
)
299+
if (blueRobot && this.isRobotInside(blueRobot)) {
292300
shouldPenalize = true
293-
robotToPenalize = opposingRobot
294301
}
295302
break
296303
}
297304
}
298305

299-
if (shouldPenalize && robotToPenalize) {
306+
if (shouldPenalize) {
300307
this._lastRobotCollisionTime = Date.now()
301308
SimulationSystem.robotPenalty(
302-
robotToPenalize,
309+
opposingRobot,
303310
this._prefs?.penaltyPoints ?? 0,
304311
`Contact penalty in protected zone`
305312
)

fission/src/test/mirabuf/ProtectedZoneSceneObject.test.ts

Lines changed: 34 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -187,34 +187,43 @@ describe("ProtectedZoneSceneObject", () => {
187187

188188
instance["handleContactPenalty"](redRobotBodyId, blueRobotBodyId)
189189

190-
expect(vi.mocked(SimulationSystem.robotPenalty)).toHaveBeenCalledTimes(1)
191-
expect(vi.mocked(SimulationSystem.robotPenalty)).toHaveBeenCalledWith(blueRobot, 5, expect.any(String))
190+
expect(vi.mocked(SimulationSystem.robotPenalty)).toHaveBeenCalledExactlyOnceWith(blueRobot, 5, expect.any(String))
192191
})
193192

194-
test("HandleContactPenalty opponent robot inside", () => {
193+
test("HandleContactPenalty any robot inside", () => {
195194
const instance = createProtectedZoneInstance({
196-
contactType: ContactType.OPPONENT_ROBOT_INSIDE,
195+
contactType: ContactType.ANY_ROBOT_INSIDE,
197196
})
198197

199198
instance["zoneCollision"](blueRobotBodyId)
200199

201200
instance["handleContactPenalty"](redRobotBodyId, blueRobotBodyId)
202201

203-
expect(vi.mocked(SimulationSystem.robotPenalty)).toHaveBeenCalledTimes(1)
204-
expect(vi.mocked(SimulationSystem.robotPenalty)).toHaveBeenCalledWith(blueRobot, 5, expect.any(String))
202+
expect(vi.mocked(SimulationSystem.robotPenalty)).toHaveBeenCalledExactlyOnceWith(blueRobot, 5, expect.any(String))
205203
})
206204

207-
test("HandleContactPenalty ally robot inside", () => {
205+
test("HandleContactPenalty blue robot inside", () => {
208206
const instance = createProtectedZoneInstance({
209-
contactType: ContactType.ALLY_ROBOT_INSIDE,
207+
contactType: ContactType.BLUE_ROBOT_INSIDE,
208+
})
209+
210+
instance["zoneCollision"](blueRobotBodyId)
211+
212+
instance["handleContactPenalty"](redRobotBodyId, blueRobotBodyId)
213+
214+
expect(vi.mocked(SimulationSystem.robotPenalty)).toHaveBeenCalledExactlyOnceWith(blueRobot, 5, expect.any(String))
215+
})
216+
217+
test("HandleContactPenalty red robot inside", () => {
218+
const instance = createProtectedZoneInstance({
219+
contactType: ContactType.RED_ROBOT_INSIDE,
210220
})
211221

212222
instance["zoneCollision"](redRobotBodyId)
213223

214224
instance["handleContactPenalty"](redRobotBodyId, blueRobotBodyId)
215225

216-
expect(vi.mocked(SimulationSystem.robotPenalty)).toHaveBeenCalledTimes(1)
217-
expect(vi.mocked(SimulationSystem.robotPenalty)).toHaveBeenCalledWith(blueRobot, 5, expect.any(String))
226+
expect(vi.mocked(SimulationSystem.robotPenalty)).toHaveBeenCalledExactlyOnceWith(blueRobot, 5, expect.any(String))
218227
})
219228

220229
test("HandleContactPenalty doesn't penalize if not all robots are inside", () => {
@@ -229,9 +238,20 @@ describe("ProtectedZoneSceneObject", () => {
229238
expect(vi.mocked(SimulationSystem.robotPenalty)).not.toHaveBeenCalled()
230239
})
231240

232-
test("HandleContactPenalty doesn't penalize if contact type is ally and ally is not inside", () => {
241+
test("HandleContactPenalty doesn't penalize if contact type is any and no robots are inside", () => {
242+
const instance = createProtectedZoneInstance({
243+
contactType: ContactType.ANY_ROBOT_INSIDE,
244+
})
245+
246+
247+
instance["handleContactPenalty"](redRobotBodyId, blueRobotBodyId)
248+
249+
expect(vi.mocked(SimulationSystem.robotPenalty)).not.toHaveBeenCalled()
250+
})
251+
252+
test("HandleContactPenalty doesn't penalize if contact type is red and red is not inside", () => {
233253
const instance = createProtectedZoneInstance({
234-
contactType: ContactType.ALLY_ROBOT_INSIDE,
254+
contactType: ContactType.RED_ROBOT_INSIDE,
235255
})
236256

237257
instance["zoneCollision"](blueRobotBodyId)
@@ -241,9 +261,9 @@ describe("ProtectedZoneSceneObject", () => {
241261
expect(vi.mocked(SimulationSystem.robotPenalty)).not.toHaveBeenCalled()
242262
})
243263

244-
test("HandleContactPenalty doesn't penalize if contact type is opponent and opponent is not inside", () => {
264+
test("HandleContactPenalty doesn't penalize if contact type is blue and blue is not inside", () => {
245265
const instance = createProtectedZoneInstance({
246-
contactType: ContactType.OPPONENT_ROBOT_INSIDE,
266+
contactType: ContactType.BLUE_ROBOT_INSIDE,
247267
})
248268

249269
instance["zoneCollision"](redRobotBodyId)

0 commit comments

Comments
 (0)