edit-poi.ts 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. import { CopyProps, copyEntityAttrib } from "../../shared";
  2. import { Poi, PoiAttrib } from "./poi";
  3. export class EditPoi<T extends PoiAttrib = PoiAttrib> extends Poi<T> {
  4. mounted(): void {
  5. super.enableMouseAct(this.actShape);
  6. this.bus.on("shapeStatusChange", (data) => {
  7. if (data.type === "click") {
  8. if (data.current === "active") {
  9. this.container.bus.emit("active", { active: true, entity: this });
  10. } else {
  11. this.container.bus.emit("active", { active: false, entity: this });
  12. }
  13. }
  14. });
  15. super.enableDrag({
  16. readyHandler: () => {
  17. this.container.bus.emit("dataChangeBefore");
  18. },
  19. moveHandler: (move) => {
  20. this.attrib.x = move[0];
  21. this.attrib.y = move[1];
  22. },
  23. endHandler: () => {
  24. this.container.bus.emit("dataChangeAfter");
  25. },
  26. });
  27. super.mounted();
  28. }
  29. del() {
  30. const pois = this.container.getSameLevelData(this);
  31. if (pois) {
  32. pois.splice(pois.indexOf(this.attrib), 1);
  33. }
  34. this.container.bus.emit("dataChange");
  35. }
  36. copy(props: Pick<CopyProps, "count" | "dire"> = {}) {
  37. copyEntityAttrib({
  38. ...props,
  39. entity: this,
  40. size: this.actShape.getSize(),
  41. factoryAttrib: (pos) => ({
  42. x: pos[0],
  43. y: pos[1],
  44. type: this.attrib.type,
  45. }),
  46. });
  47. this.container.bus.emit("dataChange");
  48. }
  49. }