edit-poi.ts 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  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. console.log("??");
  7. super.enableDrag({
  8. readyHandler: () => {
  9. this.container.bus.emit("dataChangeBefore");
  10. },
  11. moveHandler: (move) => {
  12. this.attrib.x = move[0];
  13. this.attrib.y = move[1];
  14. },
  15. endHandler: () => {
  16. this.container.bus.emit("dataChangeAfter");
  17. },
  18. });
  19. }
  20. del() {
  21. const pois = this.container.getSameLevelData(this);
  22. if (pois) {
  23. pois.splice(pois.indexOf(this.attrib), 1);
  24. }
  25. this.container.bus.emit("dataChange");
  26. }
  27. copy(props: Pick<CopyProps, "count" | "dire"> = {}) {
  28. copyEntityAttrib({
  29. ...props,
  30. entity: this,
  31. size: this.actShape.getSize(),
  32. factoryAttrib: (pos) => ({
  33. x: pos[0],
  34. y: pos[1],
  35. type: this.attrib.type,
  36. }),
  37. });
  38. this.container.bus.emit("dataChange");
  39. }
  40. }