Skip to content
Snippets Groups Projects
Commit a97aba04 authored by Paolo Brasolin's avatar Paolo Brasolin
Browse files

refactor: #fe shift all backend usage to FightScene

parent 4ed8ea39
No related branches found
No related tags found
No related merge requests found
Pipeline #24556 failed
...@@ -260,7 +260,24 @@ export default class FightScene extends MainScene { ...@@ -260,7 +260,24 @@ export default class FightScene extends MainScene {
} }
async spawnFoe(length: number, timeout: number) { async spawnFoe(length: number, timeout: number) {
// TODO: this is a terrible pattern const beWord = (
await new Foe(this, timeout).initialize(length); await backend.createWordChoice({
ocr_transcript_length_min: length,
ocr_transcript_length_max: length,
})
).data;
const beClue = (
await backend.createClue(this.beGame.id, {
word_id: beWord.id,
began_at: new Date().toISOString(),
began_at_gmtm: this.getGameTime(),
})
).data;
if (!this.scene.isActive()) return;
const foe = new Foe(this, timeout);
foe.initialize(length, beWord, beClue);
} }
} }
...@@ -3,7 +3,6 @@ import Clue from "./clue"; ...@@ -3,7 +3,6 @@ import Clue from "./clue";
import Critter from "./critter"; import Critter from "./critter";
import FightScene from "./fight_scene"; import FightScene from "./fight_scene";
import backend from "./backend";
import * as Types from "../../../backend/src/types"; import * as Types from "../../../backend/src/types";
class Foe { class Foe {
...@@ -23,21 +22,9 @@ class Foe { ...@@ -23,21 +22,9 @@ class Foe {
this.duration = duration; this.duration = duration;
} }
async initialize(length: number) { initialize(length: number, beWord: Types.Word, beClue: Types.Clue) {
this.beWord = ( this.beWord = beWord;
await backend.createWordChoice({ this.beClue = beClue;
ocr_transcript_length_min: length,
ocr_transcript_length_max: length,
})
).data;
if (!this.scene.scene.isActive()) return;
this.beClue = (
await backend.createClue(this.scene.beGame.id, {
word_id: this.beWord.id,
began_at: new Date().toISOString(),
began_at_gmtm: this.scene.getGameTime(),
})
).data;
this.clue = new Clue(this.scene, this.beWord, this.duration); this.clue = new Clue(this.scene, this.beWord, this.duration);
// TODO: this is the time to reach a collision w/player, but maybe we should just use the transversal of the full screen. // TODO: this is the time to reach a collision w/player, but maybe we should just use the transversal of the full screen.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment