Skip to content

Commit

Permalink
fix: Fix game crash if no arcadian headgear is selected
Browse files Browse the repository at this point in the history
  • Loading branch information
johnedvard committed Aug 28, 2022
1 parent f2306f5 commit bb6319d
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
5 changes: 2 additions & 3 deletions src/Player.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export class Player {
sprite = { render: () => {}, x: 0, y: 0 }; // draw sprite on pointmass position
headSprite = { render: () => {}, x: 0, y: 0 }; // From Arcadian API
hasWon = false;
headImg = { width: 0, height: 0 };
headImg = getSelectedArcadian().img || { width: 0, height: 0 };
headOffset = { x: 10, y: 38 };
isLeft = false;
isRopeCut = false;
Expand All @@ -27,7 +27,6 @@ export class Player {
const startY = levelData.p.y;
this.createRope({ startX, startY, ropeLength });
this.createSprite();
this.headImg = getSelectedArcadian().img;
this.createHeadSprite(this.headImg);
this.playerControls = new PlayerControls(this);
this.listenForGameEvents();
Expand Down Expand Up @@ -63,7 +62,7 @@ export class Player {
};
}
createHeadSprite(img) {
if (!img) return;
if (!img.width || img.height) return;
const scale = this.scale / 2;
let scaleX = scale;
if (this.isLeft) scaleX = scaleX * -1;
Expand Down
6 changes: 3 additions & 3 deletions src/arcadianApi.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@ export async function queryArcadian(id) {
});
}

export const fetchArcadianHeads = (startId = 0) => {
export const fetchArcadianHeads = () => {
return new Promise((resolve) => {
const promises = [];
for (let i = startId; i < 100; i = i + 5) {
if (i === 0) continue;
for (let i = 1; i < 46; i++) {
if (i === 2 || i === 13) continue;
const promise = queryArcadian(i);
promises.push(promise);
}
Expand Down

0 comments on commit bb6319d

Please sign in to comment.