@ohmygame/level-editor 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.ohmygame-plugin/plugin.json +42 -0
- package/LICENSE +201 -0
- package/README.md +43 -2
- package/assets/icon.svg +1 -0
- package/locales/en.json +9 -0
- package/locales/zh-CN.json +9 -0
- package/package.json +27 -4
- package/panel/dom.js +79 -0
- package/panel/i18n.js +225 -0
- package/panel/index.html +15 -0
- package/panel/inspector.js +156 -0
- package/panel/main.js +1697 -0
- package/panel/new-map.js +112 -0
- package/panel/palette.js +196 -0
- package/panel/render.js +321 -0
- package/panel/style.css +137 -0
- package/panel/tmj.js +901 -0
- package/skills/level-maps/SKILL.md +28 -0
package/panel/index.html
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="utf-8" />
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
6
|
+
<title>Levels</title>
|
|
7
|
+
<link rel="stylesheet" href="/_ohmygame/plugin-ui.css" />
|
|
8
|
+
<link rel="stylesheet" href="./style.css" />
|
|
9
|
+
<script type="module" src="/_ohmygame/ui/1/index.js"></script>
|
|
10
|
+
<script type="module" src="./main.js"></script>
|
|
11
|
+
</head>
|
|
12
|
+
<body>
|
|
13
|
+
<div id="app"></div>
|
|
14
|
+
</body>
|
|
15
|
+
</html>
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
// The inspector for the selected object: name, class, position, size and
|
|
2
|
+
// custom properties. Each change is one step in the panel's history.
|
|
3
|
+
import * as tmj from "./tmj.js";
|
|
4
|
+
import { h, icon, iconButton } from "./dom.js";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Makes the inspector in `element`; call the function it returns to draw it
|
|
8
|
+
* again after a change. Fields keep what is being typed in them.
|
|
9
|
+
*/
|
|
10
|
+
export function createInspector({ element, t, selection: currentSelection, doc: currentDoc, editable, editFields, deleteSelection }) {
|
|
11
|
+
function renderInspector() {
|
|
12
|
+
const box = element;
|
|
13
|
+
const selection = currentSelection();
|
|
14
|
+
if (!selection) {
|
|
15
|
+
if (box.dataset.object !== "") {
|
|
16
|
+
box.dataset.object = "";
|
|
17
|
+
box.object = undefined;
|
|
18
|
+
box.fields = [];
|
|
19
|
+
box.replaceChildren(h("p", { class: "note" }, t.noSelection));
|
|
20
|
+
}
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
const { object } = selection;
|
|
24
|
+
const readOnly = !editable(selection);
|
|
25
|
+
const signature = JSON.stringify([object.id, readOnly, Boolean(object.point), (object.properties ?? []).map((property) => [property.name, property.type])]);
|
|
26
|
+
if (box.object === object && box.signature === signature) {
|
|
27
|
+
// Same object and fields: refresh the values, except in the field being typed in.
|
|
28
|
+
for (const field of box.fields) {
|
|
29
|
+
if (field.element === document.activeElement || field.element.matches(":focus-within")) continue;
|
|
30
|
+
const value = field.value();
|
|
31
|
+
if (field.kind === "checkbox") field.element.checked = Boolean(value);
|
|
32
|
+
else if (field.element.value !== String(value ?? "")) field.element.value = String(value ?? "");
|
|
33
|
+
}
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
box.object = object;
|
|
37
|
+
box.signature = signature;
|
|
38
|
+
box.dataset.object = String(object.id);
|
|
39
|
+
box.fields = [];
|
|
40
|
+
const doc = currentDoc();
|
|
41
|
+
const edit = (change) => editFields(object, change);
|
|
42
|
+
const input = (label, value, commit, attributes = {}) => {
|
|
43
|
+
const element = h("omg-input", {
|
|
44
|
+
label,
|
|
45
|
+
value: String(value() ?? ""),
|
|
46
|
+
readonly: readOnly,
|
|
47
|
+
...attributes,
|
|
48
|
+
on: { change: (event) => commit(event.currentTarget.value) },
|
|
49
|
+
});
|
|
50
|
+
box.fields.push({ element, value });
|
|
51
|
+
return element;
|
|
52
|
+
};
|
|
53
|
+
const number = (key) =>
|
|
54
|
+
input(t[key], () => object[key] ?? 0, (text) => {
|
|
55
|
+
const value = Number.parseFloat(text);
|
|
56
|
+
if (Number.isFinite(value)) edit((target) => tmj.setKey(target, key, value));
|
|
57
|
+
else renderInspector();
|
|
58
|
+
}, { type: "number", step: "any", disabled: (key === "width" || key === "height") && object.point ? true : undefined });
|
|
59
|
+
const classKey = tmj.classKey(doc, object);
|
|
60
|
+
const properties = (object.properties ?? []).map((property) => propertyRow(object, property.name, readOnly));
|
|
61
|
+
box.replaceChildren(
|
|
62
|
+
h("div", { class: "object-id" }, h("span", { class: "note" }, `#${object.id ?? "?"}`)),
|
|
63
|
+
input(t.name, () => object.name ?? "", (value) => edit((target) => tmj.setKey(target, "name", value))),
|
|
64
|
+
input(t.className, () => object[classKey] ?? "", (value) => edit((target) => tmj.setKey(target, classKey, value))),
|
|
65
|
+
h("div", { class: "field-grid" }, number("x"), number("y"), number("width"), number("height")),
|
|
66
|
+
h("div", { class: "subhead" }, t.properties),
|
|
67
|
+
h("div", { class: "property-list" }, properties),
|
|
68
|
+
readOnly
|
|
69
|
+
? undefined
|
|
70
|
+
: h(
|
|
71
|
+
"div",
|
|
72
|
+
{ class: "inspector-actions" },
|
|
73
|
+
h("omg-button", { variant: "ghost", on: { click: () => addProperty(object) } }, icon("plus"), t.addProperty),
|
|
74
|
+
h("omg-button", { variant: "danger", on: { click: () => deleteSelection() } }, icon("trash"), t.deleteObject),
|
|
75
|
+
),
|
|
76
|
+
);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// Each read goes through `current()`: undo and redo put back copies of the
|
|
80
|
+
// properties, so a property object held from when the row was drawn may be stale.
|
|
81
|
+
function propertyRow(object, propertyName, readOnly) {
|
|
82
|
+
const box = element;
|
|
83
|
+
const edit = (change) => editFields(object, change);
|
|
84
|
+
const current = () => tmj.propertyNamed(object, propertyName);
|
|
85
|
+
const property = current();
|
|
86
|
+
const simple = tmj.PROPERTY_TYPES.includes(property.type ?? "string");
|
|
87
|
+
const type = property.type ?? "string";
|
|
88
|
+
const name = h("omg-input", {
|
|
89
|
+
"aria-label": t.propertyName,
|
|
90
|
+
value: property.name,
|
|
91
|
+
readonly: readOnly,
|
|
92
|
+
on: {
|
|
93
|
+
change: (event) => {
|
|
94
|
+
const next = event.currentTarget.value.trim();
|
|
95
|
+
if (next && next !== propertyName) edit((target) => tmj.renameProperty(target, propertyName, next));
|
|
96
|
+
else event.currentTarget.value = propertyName;
|
|
97
|
+
renderInspector();
|
|
98
|
+
},
|
|
99
|
+
},
|
|
100
|
+
});
|
|
101
|
+
const typeSelect = simple
|
|
102
|
+
? h(
|
|
103
|
+
"omg-select",
|
|
104
|
+
{
|
|
105
|
+
"aria-label": t.propertyType,
|
|
106
|
+
value: type,
|
|
107
|
+
disabled: readOnly,
|
|
108
|
+
on: {
|
|
109
|
+
change: (event) => {
|
|
110
|
+
const next = event.currentTarget.value;
|
|
111
|
+
edit((target) => tmj.setProperty(target, propertyName, next, tmj.propertyValue(next, current()?.value)));
|
|
112
|
+
},
|
|
113
|
+
},
|
|
114
|
+
},
|
|
115
|
+
tmj.PROPERTY_TYPES.map((option) => h("option", { value: option }, option)),
|
|
116
|
+
)
|
|
117
|
+
: h("span", { class: "property-type" }, type);
|
|
118
|
+
let value;
|
|
119
|
+
if (type === "bool") {
|
|
120
|
+
value = h("omg-checkbox", {
|
|
121
|
+
"aria-label": t.propertyValue,
|
|
122
|
+
checked: Boolean(property.value),
|
|
123
|
+
disabled: readOnly,
|
|
124
|
+
on: { change: (event) => edit((target) => tmj.setProperty(target, propertyName, "bool", event.currentTarget.checked)) },
|
|
125
|
+
});
|
|
126
|
+
box.fields.push({ element: value, kind: "checkbox", value: () => current()?.value });
|
|
127
|
+
} else {
|
|
128
|
+
value = h("omg-input", {
|
|
129
|
+
"aria-label": t.propertyValue,
|
|
130
|
+
value: simple ? String(property.value ?? "") : JSON.stringify(property.value),
|
|
131
|
+
readonly: readOnly || !simple,
|
|
132
|
+
type: type === "int" || type === "float" ? "number" : undefined,
|
|
133
|
+
step: type === "float" ? "any" : undefined,
|
|
134
|
+
on: { change: (event) => edit((target) => tmj.setProperty(target, propertyName, type, tmj.propertyValue(type, event.currentTarget.value))) },
|
|
135
|
+
});
|
|
136
|
+
if (simple) box.fields.push({ element: value, value: () => current()?.value });
|
|
137
|
+
}
|
|
138
|
+
return h(
|
|
139
|
+
"div",
|
|
140
|
+
{ class: "property-row" },
|
|
141
|
+
name,
|
|
142
|
+
typeSelect,
|
|
143
|
+
value,
|
|
144
|
+
readOnly ? undefined : iconButton("close", t.removeProperty, () => edit((target) => tmj.setProperty(target, propertyName, type, undefined))),
|
|
145
|
+
);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
function addProperty(object) {
|
|
149
|
+
const names = new Set((object.properties ?? []).map((property) => property.name));
|
|
150
|
+
let name = t.newProperty;
|
|
151
|
+
for (let n = 2; names.has(name); n++) name = `${t.newProperty} ${n}`;
|
|
152
|
+
editFields(object, (target) => tmj.setProperty(target, name, "string", ""));
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
return renderInspector;
|
|
156
|
+
}
|