|
1 |
| - |
2 | 1 | // output image class: one image to one layer
|
3 | 2 | // * path:
|
4 | 3 | // * image layer
|
5 | 4 | // * viewer()
|
6 | 5 | // * select()
|
7 | 6 | // * isLayerValid()
|
8 | 7 | // * init image class: has three layers
|
9 |
| -// * path : |
| 8 | +// * path : |
10 | 9 | // * init image group layer
|
11 | 10 | // * init image layer
|
12 |
| -// * background layer |
| 11 | +// * background layer |
13 | 12 | // * isLayerValid()
|
14 |
| -// * mask class: |
| 13 | +// * mask class: |
15 | 14 | // * path
|
16 | 15 | // * mask group
|
17 | 16 | // * white mask
|
|
22 | 21 |
|
23 | 22 | const psapi = require('./psapi')
|
24 | 23 |
|
25 |
| -class ViewerImage{ |
26 |
| - constructor(){ |
| 24 | +class ViewerImage { |
| 25 | + constructor () {} |
| 26 | + visible (visibleOn) {} |
| 27 | + select () {} |
| 28 | + isLayerValid () {} |
| 29 | + isSameLayer (layer_id) {} |
| 30 | +} |
27 | 31 |
|
| 32 | +class OutputImage extends ViewerImage { |
| 33 | + constructor (layer, path) { |
| 34 | + super() |
| 35 | + this.layer = layer |
| 36 | + this.path = path |
| 37 | + } |
| 38 | + visible (visibleOn) { |
| 39 | + super.visible(visibleOn) |
| 40 | + if (this.isLayerValid()) { |
| 41 | + this.layer.visible = visibleOn |
28 | 42 | }
|
29 |
| - visible(visibleOn) |
30 |
| - { |
31 |
| - |
32 |
| - } |
33 |
| - select() { |
34 |
| - |
35 |
| - } |
36 |
| - isLayerValid(){ |
37 |
| - |
| 43 | + } |
| 44 | + select () { |
| 45 | + super.select() |
| 46 | + if (this.isLayerValid()) { |
| 47 | + psapi.selectLayers([this.layer]) |
| 48 | + // console.log(`${this.layer.id} got selected`); |
38 | 49 | }
|
39 |
| - isSameLayer(layer_id){ |
40 |
| - |
| 50 | + } |
| 51 | + isLayerValid () { |
| 52 | + super.isLayerValid() |
| 53 | + //check if layer is defined or not |
| 54 | + //true if the layer is defined |
| 55 | + //false otherwise |
| 56 | + let isValid = false |
| 57 | + if (typeof this.layer !== 'undefined') { |
| 58 | + isValid = true |
41 | 59 | }
|
| 60 | + return isValid |
| 61 | + } |
| 62 | + isSameLayer (layer_id) { |
| 63 | + super.isSameLayer(layer_id) |
| 64 | + const is_same = this.layer.id == layer_id |
| 65 | + return is_same |
| 66 | + } |
42 | 67 | }
|
43 | 68 |
|
44 |
| -class OutputImage extends ViewerImage { |
45 |
| - constructor(layer, path) { |
46 |
| - super() |
47 |
| - this.layer = layer |
48 |
| - this.path = path; |
49 |
| - |
50 |
| - |
| 69 | +class InitImage extends ViewerImage { |
| 70 | + constructor (init_group, init_snapshot, solid_layer, path) { |
| 71 | + super() |
| 72 | + this.init_group = init_group |
| 73 | + this.init_snapshot = init_snapshot |
| 74 | + this.solid_layer = solid_layer |
51 | 75 |
|
52 |
| - } |
53 |
| - visible(visibleOn) |
54 |
| - { |
| 76 | + this.path = path |
| 77 | + } |
| 78 | + visible (visibleOn) { |
55 | 79 | super.visible(visibleOn)
|
56 |
| - if(this.isLayerValid()){ |
57 |
| - this.layer.visible = visibleOn |
| 80 | + // const isValid = this.isLayerValid() |
| 81 | + let visibleValues = [] |
| 82 | + if (visibleOn) { |
| 83 | + visibleValues = [true, true, true] |
| 84 | + } else { |
| 85 | + visibleValues = [false, false, false] |
58 | 86 | }
|
| 87 | + |
| 88 | + if (this.isLayerValid(this.init_group)) { |
| 89 | + this.init_group.visible = visibleValues[0] |
| 90 | + } |
| 91 | + if (this.isLayerValid(this.init_snapshot)) { |
| 92 | + this.init_snapshot.visible = visibleValues[1] |
59 | 93 | }
|
60 |
| - select() { |
61 |
| - super.select() |
62 |
| - if(this.isLayerValid()){ |
63 |
| - psapi.selectLayers([this.layer]) |
64 |
| - // console.log(`${this.layer.id} got selected`); |
65 |
| - } |
| 94 | + if (this.isLayerValid(this.solid_layer)) { |
| 95 | + this.solid_layer.visible = visibleValues[2] |
66 | 96 | }
|
67 |
| - isLayerValid(){ |
68 |
| - super.isLayerValid() |
69 |
| - //check if layer is defined or not |
70 |
| - //true if the layer is defined |
71 |
| - //false otherwise |
72 |
| - let isValid = false |
73 |
| - if (typeof this.layer !== "undefined") |
74 |
| - { |
75 |
| - isValid = true |
76 |
| - } |
77 |
| - return isValid |
| 97 | + } |
| 98 | + |
| 99 | + select () { |
| 100 | + super.select() |
| 101 | + |
| 102 | + const selectLayers = [] |
| 103 | + if (this.isLayerValid(this.init_group)) { |
| 104 | + |
| 105 | + selectLayers.push(this.init_group) |
| 106 | + } |
| 107 | + // if (this.isLayerValid(this.init_snapshot)) { |
| 108 | + |
| 109 | + // selectLayers.push(this.init_snapshot) |
| 110 | + // } |
| 111 | + // if (this.isLayerValid(this.solid_layer)) { |
| 112 | + // selectLayers.push(this.solid_layer) |
| 113 | + // } |
| 114 | + |
| 115 | + psapi.selectLayers(selectLayers) |
| 116 | + // console.log(`${this.layer.id} got selected`); |
| 117 | + } |
| 118 | + |
| 119 | + isLayerValid (layer) { |
| 120 | + super.isLayerValid() |
| 121 | + //check if layer is defined or not |
| 122 | + //true if the layer is defined |
| 123 | + //false otherwise |
| 124 | + // let isValid = [false,false,false] |
| 125 | + let isValid = false |
| 126 | + if (typeof layer !== 'undefined') { |
| 127 | + isValid = true |
78 | 128 | }
|
79 |
| - isSameLayer(layer_id){ |
80 |
| - super.isSameLayer(layer_id) |
81 |
| - const is_same = this.layer.id == layer_id |
82 |
| - return is_same |
| 129 | + |
| 130 | + return isValid |
| 131 | + } |
| 132 | + isSameLayer (layer_id) { |
| 133 | + super.isSameLayer(layer_id) |
| 134 | + let is_same = false |
| 135 | + if(this.isLayerValid(this.init_group)){ |
| 136 | + is_same = this.init_group.id == layer_id |
| 137 | + |
83 | 138 | }
|
| 139 | + return is_same |
84 | 140 | }
|
| 141 | +} |
| 142 | + |
| 143 | +class InitMaskImage extends ViewerImage { |
| 144 | + constructor (mask_group, white_mark, solid_black, path) { |
| 145 | + super() |
| 146 | + this.mask_group = mask_group |
| 147 | + this.white_mark = white_mark |
| 148 | + this.solid_black = solid_black |
85 | 149 |
|
86 |
| - class InitImage extends OutputImage { |
87 |
| - constructor(name) { |
88 |
| - super(name); // call the super class constructor and pass in the name parameter |
| 150 | + this.path = path |
89 | 151 | }
|
| 152 | + visible (visibleOn) { |
| 153 | + super.visible(visibleOn) |
| 154 | + // const isValid = this.isLayerValid() |
| 155 | + let visibleValues = [] |
| 156 | + if (visibleOn) { |
| 157 | + visibleValues = [true, true, true] |
| 158 | + } else { |
| 159 | + visibleValues = [false, false, false] |
| 160 | + } |
90 | 161 |
|
91 |
| - // speak() { |
92 |
| - // console.log(`${this.name} barks.`); |
93 |
| - // } |
94 |
| - } |
| 162 | + if (this.isLayerValid(this.mask_group)) { |
| 163 | + this.mask_group.visible = visibleValues[0] |
| 164 | + } |
| 165 | + if (this.isLayerValid(this.white_mark)) { |
| 166 | + this.white_mark.visible = visibleValues[1] |
| 167 | + } |
| 168 | + if (this.isLayerValid(this.solid_black)) { |
| 169 | + this.solid_black.visible = visibleValues[2] |
| 170 | + } |
| 171 | + } |
95 | 172 |
|
96 |
| - |
97 |
| - module.exports = { |
98 |
| - OutputImage, |
99 |
| - InitImage |
| 173 | + select () { |
| 174 | + super.select() |
| 175 | + |
| 176 | + const selectLayers = [] |
| 177 | + if (this.isLayerValid(this.mask_group)) { |
| 178 | + |
| 179 | + selectLayers.push(this.mask_group) |
| 180 | + } |
| 181 | + // if (this.isLayerValid(this.init_snapshot)) { |
| 182 | + |
| 183 | + // selectLayers.push(this.init_snapshot) |
| 184 | + // } |
| 185 | + // if (this.isLayerValid(this.solid_layer)) { |
| 186 | + // selectLayers.push(this.solid_layer) |
| 187 | + // } |
| 188 | + |
| 189 | + psapi.selectLayers(selectLayers) |
| 190 | + // console.log(`${this.layer.id} got selected`); |
| 191 | + } |
| 192 | + |
| 193 | + isLayerValid (layer) { |
| 194 | + super.isLayerValid() |
| 195 | + //check if layer is defined or not |
| 196 | + //true if the layer is defined |
| 197 | + //false otherwise |
| 198 | + // let isValid = [false,false,false] |
| 199 | + let isValid = false |
| 200 | + if (typeof layer !== 'undefined') { |
| 201 | + isValid = true |
| 202 | + } |
| 203 | + |
| 204 | + return isValid |
| 205 | + } |
| 206 | + isSameLayer (layer_id) { |
| 207 | + super.isSameLayer(layer_id) |
| 208 | + let is_same = false |
| 209 | + if(this.isLayerValid(this.mask_group)){ |
| 210 | + is_same = this.mask_group.id == layer_id |
| 211 | + |
| 212 | + } |
| 213 | + return is_same |
| 214 | + } |
100 | 215 | }
|
101 | 216 |
|
| 217 | + |
| 218 | +module.exports = { |
| 219 | + OutputImage, |
| 220 | + InitImage, |
| 221 | + InitMaskImage, |
| 222 | +} |
0 commit comments