#
vincentlu
2025-05-13 ebd2f4397a92c6a5096de1b86d59154363344720
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
import * as PIXI from 'pixi.js';
import { DEVICE_TYPE, POINT_ROUTE_DIRECTION } from "./constants";
 
export default class PointRoute extends PIXI.Graphics {
 
    startSprite;
    endSprite;
 
    direction;
 
    type;
    no;
 
    constructor(direction) {
        super();
        this.direction = direction ? direction : POINT_ROUTE_DIRECTION.OUT_OF_ORDER;
        // this.data = {
        //     type: DEVICE_TYPE.ROUTE
        // };
        this.type = DEVICE_TYPE.ROUTE;
    }
 
    style() {
        const scale = 1;
        this.clear();
        this.lineStyle(1.5, 0x2d3436);
        this.moveTo(this.startSprite.x * scale, this.startSprite.y * scale);
        this.lineTo(this.endSprite.x * scale, this.endSprite.y * scale);
    }
 
    setPoint(startSprite, endSprite) {
        this.startSprite = startSprite;
        this.endSprite = endSprite;
        // this.data.no = this.startSprite?.data?.no + "-" + this.endSprite?.data?.no;
        this.no = this.startSprite?.data?.no + "-" + this.endSprite?.data?.no;
    }
 
    update(dragSprite) {
        const scale = 1;
        this.clear();
        this.lineStyle(1.5, 0x2d3436);
        if (dragSprite === this.startSprite) {
            this.moveTo(dragSprite.position.x * scale, dragSprite.position.y * scale);
        } else {
            this.moveTo(this.startSprite.position.x * scale, this.startSprite.position.y * scale);
        }
        if (dragSprite === this.endSprite) {
            this.lineTo(dragSprite.position.x * scale, dragSprite.position.y * scale);
        } else {
            this.lineTo(this.endSprite.position.x * scale, this.endSprite.position.y * scale);
        }
    }
 
    about(sprite) {
        return sprite === this.startSprite || sprite === this.endSprite;
    }
 
    has(startSprite, endSprite) {
        let res = false;
        switch (this.direction) {
            case POINT_ROUTE_DIRECTION.OUT_OF_ORDER:
                if (startSprite === this.startSprite) {
                    if (endSprite === this.endSprite) {
                        res = true;
                    }
                }
                if (startSprite === this.endSprite) {
                    if (endSprite === this.startSprite) {
                        res = true;
                    }
                }
                break
            case POINT_ROUTE_DIRECTION.ORDER:
                if (startSprite === this.startSprite) {
                    if (endSprite === this.endSprite) {
                        res = true;
                    }
                }
                break
            case POINT_ROUTE_DIRECTION.REVERSE_ORDER:
                if (startSprite === this.endSprite) {
                    if (endSprite === this.startSprite) {
                        res = true;
                    }
                }
                break
            default:
                break
        }
        return res;
    }
 
}