Skip to content

Commit c10ae04

Browse files
committed
Starting layer editing.
1 parent c1dc0cd commit c10ae04

File tree

4 files changed

+52
-4
lines changed

4 files changed

+52
-4
lines changed

src/pg/inputPixelEditor/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,14 @@ See usage for each method below.
4040
| `hasUndo()` | - | Has undo |
4141
| `hasRedo()` | - | Has redo |
4242
| `redo()` | - | Redo. |
43-
| `selectLayer()` | - | Select layer. |
43+
| `selectLayer(index)` | - | Select layer. |
4444
| `getLayers()` | - | Get layer array. |
4545
| `addLayer(option)` | - | Add layer. |
4646
| `removeLayer(index)` | - | Remove layer. |
4747
| `flattenLayers(layerIndexes)` | - | Flatten layers. |
4848
| `moveLayer(startIndex, endIndex)` | - | Move layer. |
4949
| `getColors()` | - | Get colors. |
50+
| `setColor(index, r, g, b, a)` | - | Set Color. |
5051
| `addColor(r, g, b, a)` | - | Add color. |
5152
| `removeColor(index)` | - | Remove color. |
5253
| `moveColor(startIndex, endIndex)` | - | Move index. |

src/pg/inputPixelEditor/__examples__/basic/basic.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -161,9 +161,14 @@ export default class XPgInputPixelEditorBasic extends HTMLElement {
161161
hideLabel: true,
162162
}];
163163
this.$addLayer.addEventListener('click', () => {
164-
// number[][][]
165-
// this.$input.addLayer();
166-
164+
this.$layers.data.push(
165+
createTableItem({
166+
name: 'Layer 1',
167+
type: 'pixel',
168+
selected: true,
169+
})
170+
);
171+
this.$input.addLayer();
167172
});
168173
// Colors
169174
this.$colors.columns = [{

src/pg/inputPixelEditor/inputPixelEditor.ts

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -995,4 +995,43 @@ export default class PgInputPixelEditor extends HTMLElement {
995995
this.#init();
996996
}
997997

998+
addColor(r, g, b, a) {
999+
this.#colors.push([r, g, b, a]);
1000+
}
1001+
1002+
removeColor(index) {
1003+
this.#colors.splice(index, 1);
1004+
}
1005+
1006+
setColor(index, r, g, b, a) {
1007+
this.#colors[index] = [r, g, b, a];
1008+
}
1009+
1010+
moveColor(startIndex, endIndex) {
1011+
1012+
}
1013+
1014+
getLayers() {
1015+
return this.#data.map((data, index) => index);
1016+
}
1017+
1018+
selectLayer(index) {
1019+
this.#layer = index;
1020+
}
1021+
1022+
addLayer() {
1023+
this.#data.push(fillGrid(this.width, this.height));
1024+
}
1025+
1026+
removeLayer(index) {
1027+
this.#data.splice(index, 1);
1028+
}
1029+
1030+
/**
1031+
* Flatten layers, first index determines the color
1032+
*/
1033+
flattenLayers(layerIndexes: number[]) {
1034+
1035+
}
1036+
9981037
}

src/pg/json/json.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,9 @@ export default class PgJson extends HTMLElement {
8383

8484
render(changes) {
8585
if (changes.value && this.value !== null) {
86+
if (this.$container.children.length === 1) {
87+
this.$container.children[0].remove();
88+
}
8689
if (typeof this.value === 'object') {
8790
const $object = document.createElement('pg-json-object') as PgJsonObject;
8891
$object.value = unwrapObject(this.value);

0 commit comments

Comments
 (0)