Skip to content

Commit 38bf6c1

Browse files
Merge branch '6310-sdk-negative-integers-in-settint-and-other-colour-setters-causes-a-crash' into 'master'
fix(sdk): invalid negative values for colours no longer crash the game See merge request codingame/game-engine!211
2 parents 453d2ff + 7e55058 commit 38bf6c1

File tree

3 files changed

+26
-1
lines changed

3 files changed

+26
-1
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
export class InvalidPlayerColorToken extends Error {
2+
constructor (playerIdx, cause) {
3+
super(`Invalid color token: there is no player at index ${playerIdx}. Make sure to use getColorToken() if you want the color of a specific player.`)
4+
this.playerIdx = playerIdx
5+
this.cause = cause
6+
this.name = 'InvalidPlayerColorTokenError'
7+
}
8+
}

engine/modules/entities/src/main/resources/view/entity-module/properties.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,24 @@
11
import { lerp, lerpColor, lerpAngle } from '../core/utils.js'
2+
import {ErrorLog} from '../core/ErrorLog.js'
3+
import {InvalidPlayerColorToken} from './errors/InvalidPlayerColorToken.js'
4+
25

36
const noLerp = (a, b, u) => u < 1 ? a : b
47
const timeLerp = (a, b, u) => b < a ? b : lerp(a, b, u)
58

9+
610
const colorOpts = {
711
type: Number,
812
lerpMethod: lerpColor,
913
convert (value, globalData) {
10-
return value < 0 ? (globalData.players[-(value + 1)].color) : value
14+
const playerIdx = -(value + 1)
15+
16+
try {
17+
return value < 0 ? (globalData.players[playerIdx].color) : value
18+
} catch (error) {
19+
ErrorLog.push(new InvalidPlayerColorToken(playerIdx))
20+
return 0xffffff
21+
}
1122
}
1223
}
1324

playground/misc/misc-3-release-notes.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22

33
The CodinGame SDK is regularly updated and improved. This document lets you know what changed in the latest releases.
44

5+
## Next release
6+
7+
### 🐞 Bug fix
8+
9+
- `Invalid negative values for colours no longer crash the game`
10+
511
## 3.4.8
612

713
### 🐞 Bug fix

0 commit comments

Comments
 (0)