FloorView.js 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. import { SGraphView } from "@saga-web/graph/lib";
  2. import { SMouseButton, SMouseEvent, SNetUtil } from "@saga-web/base/lib";
  3. import { SPoint } from "@saga-web/draw/lib";
  4. export class FloorView extends SGraphView {
  5. constructor() {
  6. super(...arguments);
  7. this._leftKeyPos = new SPoint();
  8. this.spaceKey = false;
  9. }
  10. saveFloorJson(name) {
  11. if (!this.scene || !this.scene.json)
  12. return;
  13. let url = URL.createObjectURL(new Blob([this.scene.json]));
  14. SNetUtil.downLoad(name, url);
  15. }
  16. onKeyDown(event) {
  17. let keyCode = event.keyCode;
  18. this.spaceKey = false;
  19. switch (keyCode) {
  20. case 32:
  21. this.spaceKey = true;
  22. break;
  23. case 87:
  24. this.origin.y -= 10;
  25. break;
  26. case 83:
  27. this.origin.y += 10;
  28. break;
  29. case 68:
  30. this.origin.x += 10;
  31. break;
  32. case 65:
  33. this.origin.x -= 10;
  34. break;
  35. default:
  36. super.onKeyDown(event);
  37. break;
  38. }
  39. }
  40. onKeyUp(event) {
  41. this.spaceKey = false;
  42. super.onKeyUp(event);
  43. }
  44. onMouseDown(event) {
  45. let se = new SMouseEvent(event);
  46. if (se.buttons & SMouseButton.LeftButton) {
  47. this._leftKeyPos.x = se.x;
  48. this._leftKeyPos.y = se.y;
  49. }
  50. super.onMouseDown(event);
  51. }
  52. onMouseMove(event) {
  53. let se = new SMouseEvent(event);
  54. if (se.buttons & SMouseButton.LeftButton) {
  55. this.origin.x += se.x - this._leftKeyPos.x;
  56. this.origin.y += se.y - this._leftKeyPos.y;
  57. this._leftKeyPos.x = se.x;
  58. this._leftKeyPos.y = se.y;
  59. this.update();
  60. }
  61. super.onMouseMove(event);
  62. }
  63. }