SheetView.js 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. import { FiniteStateMachine } from "../libraries/FiniteStateMachine.js";
  2. import { SpritesheetAtlas } from "../libraries/SpritesheetAtlas.js";
  3. import { SheetTileSelectorState } from "./states/SheetTileSelectorState.js";
  4. export class SheetView {
  5. constructor() {
  6. this.stateMachine = new FiniteStateMachine();
  7. this.characterAtlas = new SpritesheetAtlas()
  8. this.worldAtlas = new SpritesheetAtlas()
  9. this.indoorAtlas = new SpritesheetAtlas()
  10. this.cityAtlas = new SpritesheetAtlas()
  11. this.dungeonAtlas = new SpritesheetAtlas()
  12. this.stateMachine.registerState("sheet", new SheetTileSelectorState(this))
  13. }
  14. async init() {
  15. let assetLoading = []
  16. assetLoading.push(this.characterAtlas.load("./assets/roguelikeChar_transparent.png", {width: 16, height: 16, margin: 1}))
  17. assetLoading.push(this.worldAtlas.load("./assets/roguelikeSheet_transparent.png", {width: 16, height: 16, margin: 1}))
  18. assetLoading.push(this.indoorAtlas.load("./assets/roguelikeIndoor_transparent.png", {width: 16, height: 16, margin: 1}))
  19. assetLoading.push(this.cityAtlas.load("./assets/roguelikeCity_transparent.png", {width: 16, height: 16, margin: 1}))
  20. assetLoading.push(this.dungeonAtlas.load("./assets/roguelikeDungeon_transparent.png", {width: 16, height: 16, margin: 1}))
  21. await Promise.all(assetLoading)
  22. this.stateMachine.setCurrentState("sheet");
  23. this.stateMachine.getCurrentState().enter();
  24. }
  25. draw(ctx, scaledCanvas) {
  26. this.stateMachine.getCurrentState().draw(ctx, scaledCanvas);
  27. }
  28. update(delta) {
  29. this.stateMachine.getCurrentState().update(delta);
  30. }
  31. }