edit-poi.ts 1.0 KB

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