Skip to content

Commit

Permalink
Start work on parsing the RelaxNG schema to drive the editor
Browse files Browse the repository at this point in the history
  • Loading branch information
dmchurch committed Feb 29, 2024
1 parent 8b416f7 commit 05bfe71
Show file tree
Hide file tree
Showing 7 changed files with 511 additions and 11 deletions.
17 changes: 9 additions & 8 deletions data/schema/actionList.rng
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
<grammar xmlns="http://relaxng.org/ns/structure/1.0"
xmlns:a="http://relaxng.org/ns/compatibility/annotations/1.0"
xmlns:il="http://dmchurch.github.io/omsi-loops/schema/1.0"
datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes">
<start>
<element name="actions">
<interleave>
<optional>
<element name="defs">
<a:documentation>Definitions</a:documentation>
<zeroOrMore>
<ref name="anyDef"></ref>
</zeroOrMore>
Expand Down Expand Up @@ -54,14 +57,12 @@
</element>
</define>
<define name="anyDef" combine="choice">
<choice>
<element name="defineAdjustment">
<attribute name="name" />
<zeroOrMore>
<ref name="numericAdjustment"></ref>
</zeroOrMore>
</element>
</choice>
<element name="defineAdjustment">
<attribute name="name" />
<zeroOrMore>
<ref name="numericAdjustment"></ref>
</zeroOrMore>
</element>
</define>
<define name="numericEvaluation">
<choice>
Expand Down
1 change: 1 addition & 0 deletions editor.html
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ <h2>Actions</h2>
<script src="data.js"></script>
<script src="localization.js"></script>
<script src="helpers.js"></script>
<script src="schema.js"></script>
<script src="uicomponents.js"></script>
<script src="actionList.js"></script>
<script src="actionLog.js"></script>
Expand Down
1 change: 0 additions & 1 deletion editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -768,7 +768,6 @@ class ActionListEditor {

if (!this.windowBound) {
this.windowBound = true;
addEventListener("input", setValueAttribute, {capture: true, passive: true});

this.bindDataList("skills", skills, s => s.label);
this.bindDataList("buffs", buffs, b => !(b.name in prestigeBases) && b.label);
Expand Down
53 changes: 52 additions & 1 deletion helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -731,4 +731,55 @@ function defineLazyGetter(object, name, getter) {
const typedKeys = /** @type {<K extends string|number|symbol>(object: Partial<Record<K, any>>) => K[]} */(Object.keys);

/** Strongly-typed version of Object.keys */
const typedEntries = /** @type {<K extends string|number|symbol, V>(object: Partial<Record<K, V>>) => [K, V][]} */(Object.entries);
const typedEntries = /** @type {<K extends string|number|symbol, V>(object: Partial<Record<K, V>>) => [K, V][]} */(Object.entries);

const devtoolsHeader = Symbol.for("devtoolsHeader");
const devtoolsHasBody = Symbol.for("devtoolsHasBody");
const devtoolsBody = Symbol.for("devtoolsBody");

/**
* Convenience class for defining devtools formatting
* @template {*} DTConfig
*/
class DevtoolsFormattable {
/** @param {DTConfig} config @returns {DTJHTML<this, DTConfig> | null} */
dtHeader(config) { return null; }
/** @param {DTConfig} config */
dtHasBody(config) { return false; }
/** @param {DTConfig} config @returns {DTJHTML<this, DTConfig> | null} */
dtBody(config) { return null; }

[devtoolsHeader](config) {
return this.dtHeader(config);
}
[devtoolsHasBody](config) {
return this.dtHasBody(config);
}
[devtoolsBody](config) {
return this.dtBody(config);
}

constructor() {
new.target.addFormatter();
}

/** @type {DTFormatter} */
static formatter = {
header(object, config) {
return object?.[devtoolsHeader]?.(config) ?? null;
},
hasBody(object, config) {
return object?.[devtoolsHasBody]?.(config) ?? false;
},
body(object, config) {
return object?.[devtoolsBody]?.(config) ?? null;
}
}

static addFormatter() {
self.devtoolsFormatters ??= [];
if (!self.devtoolsFormatters.includes(this.formatter)) {
self.devtoolsFormatters.push(this.formatter);
}
}
}
Loading

0 comments on commit 05bfe71

Please sign in to comment.