Skip to content

Commit 464f4d5

Browse files
committed
some bug fixes
1 parent 538a7e7 commit 464f4d5

File tree

5 files changed

+17
-14
lines changed

5 files changed

+17
-14
lines changed

client/src/components/game/game-renderer.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ const ZoomableGameRenderer: React.FC<{
193193
// Adjust hovered tile if hovering over a body
194194
const hoveredBody = hoveredTile ? round?.bodies.getBodyAtLocation(hoveredTile.x, hoveredTile.y) : undefined
195195

196-
if (hoveredBody && hoveredTile){
196+
if (hoveredBody && hoveredBody.pos && hoveredTile){
197197
hoveredTile = hoveredBody.pos
198198
if (hoveredBody.robotType == schema.RobotType.RAT_KING){
199199
hoveredTile = vectorAdd(hoveredTile, {x: -1, y: -1} )

client/src/components/sidebar/map-editor/MapGenerator.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,13 +149,13 @@ function verifyMap(map: CurrentMap, bodies: Bodies): string {
149149
// Check distance from cat to other cats and cheese mines
150150
let body_type = undefined
151151
switch (body.robotType) {
152-
case RobotType.CAT:
152+
case schema.RobotType.CAT:
153153
body_type = 'Cat'
154154
break
155-
case RobotType.RAT:
155+
case schema.RobotType.RAT:
156156
body_type = 'Rat'
157157
break
158-
case RobotType.RAT_KING:
158+
case schema.RobotType.RAT_KING:
159159
body_type = 'Rat King'
160160
break
161161
default:

client/src/components/sidebar/map-editor/map-editor.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,8 +188,10 @@ export const MapEditorPage: React.FC<Props> = (props) => {
188188

189189
useEffect(() => {
190190
if (canvasMouseDown && hoveredTile) applyBrush(hoveredTile)
191-
if (canvasMouseDown && hoveredTile) {
191+
// added defensive checks just in case stuff is null for some reason
192+
if (canvasMouseDown && hoveredTile && typeof hoveredTile.x === 'number' && typeof hoveredTile.y === 'number') {
192193
// override the GameRenderer's canvas click
194+
if (!canvasMouseDown || !hoveredTile) return;
193195
const newSelectedBody = GameRunner.match?.currentRound.bodies.getBodyAtLocation(
194196
hoveredTile.x,
195197
hoveredTile.y

client/src/playback/Actions.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -104,10 +104,10 @@ export const ACTION_DEFINITIONS: Record<schema.Action, typeof Action<ActionUnion
104104
// chomping animation
105105
const src = match.currentRound.bodies.getById(this.robotId) // cat
106106
// const target = match.currentRound.bodies.getById(this.actionData.id()) // rat being eaten
107-
const coords = renderUtils.getRenderCoords(src.pos.x, src.pos.y, match.map.dimension, true)
108-
const random1 = ((src.pos.x * 491 + src.pos.y * 603 + match.currentRound.roundNumber * 343) / 100) % 1 // https://xkcd.com/221/
109-
const random2 = ((src.pos.x * 259 + src.pos.y * 429 + match.currentRound.roundNumber * 224) / 100) % 1
110-
const interpolationFactor = match.getInterpolationFactor()
107+
// const coords = renderUtils.getRenderCoords(src.pos.x, src.pos.y, match.map.dimension, true)
108+
// const random1 = ((src.pos.x * 491 + src.pos.y * 603 + match.currentRound.roundNumber * 343) / 100) % 1 // https://xkcd.com/221/
109+
// const random2 = ((src.pos.x * 259 + src.pos.y * 429 + match.currentRound.roundNumber * 224) / 100) % 1
110+
// const interpolationFactor = match.getInterpolationFactor()
111111

112112
// ctx.save()
113113
// ctx.globalAlpha = 0.5 - 0.5 * interpolationFactor * interpolationFactor
@@ -194,8 +194,11 @@ export const ACTION_DEFINITIONS: Record<schema.Action, typeof Action<ActionUnion
194194

195195
if (target.beingCarried) {
196196
// drop the target
197-
const carrier = round.bodies.getById(target.carrierRobot!)
198-
carrier.carriedRobot = undefined
197+
// const carrier = round.bodies.getById(target.carrierRobot!)
198+
if(target.carrierRobot !== undefined) {
199+
const carrier = round.bodies.getById(target.carrierRobot)
200+
carrier.carriedRobot = undefined
201+
}
199202
target.size = 1
200203
target.beingCarried = false
201204
target.carrierRobot = undefined

client/src/playback/Bodies.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -435,10 +435,8 @@ export class Body {
435435
const OFFSET = { x: .35, y: 0 } // to center the rat on the tile
436436
const ratnapped = this.robotType === schema.RobotType.RAT && this.beingCarried
437437

438-
if(ratnapped) this.pos.x += OFFSET.x
439438
const pos = this.getInterpolatedCoords(match)
440-
if(ratnapped) this.pos.x -= OFFSET.x
441-
439+
442440
const renderCoords = renderUtils.getRenderCoords(pos.x, pos.y, match.currentRound.map.staticMap.dimension)
443441

444442
if (this.robotType == schema.RobotType.CAT) {

0 commit comments

Comments
 (0)