@adeficior/data-modifier-tags 2.0.0-rc.20260814115618
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/dist/emitter/index.d.ts +32 -0
- package/dist/emitter/index.js +64 -0
- package/dist/emitter/index.js.map +1 -0
- package/dist/emitter/options.d.ts +3 -0
- package/dist/emitter/options.js +1 -0
- package/dist/emitter/options.js.map +1 -0
- package/dist/emitter/scoped.d.ts +25 -0
- package/dist/emitter/scoped.js +74 -0
- package/dist/emitter/scoped.js.map +1 -0
- package/dist/helper.d.ts +5 -0
- package/dist/helper.js +17 -0
- package/dist/helper.js.map +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -0
- package/dist/loader.d.ts +12 -0
- package/dist/loader.js +122 -0
- package/dist/loader.js.map +1 -0
- package/dist/module.d.ts +11 -0
- package/dist/module.js +22 -0
- package/dist/module.js.map +1 -0
- package/dist/options.d.ts +2 -0
- package/dist/options.js +2 -0
- package/dist/options.js.map +1 -0
- package/dist/schema.d.ts +20 -0
- package/dist/schema.js +3 -0
- package/dist/schema.js.map +1 -0
- package/dist/testing/index.d.ts +1 -0
- package/dist/testing/index.js +2 -0
- package/dist/testing/index.js.map +1 -0
- package/dist/testing/setup.d.ts +2 -0
- package/dist/testing/setup.js +16 -0
- package/dist/testing/setup.js.map +1 -0
- package/package.json +42 -0
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { type ClearableEmitter, type LoaderContext, type NormalizedId, type TagInput } from "@adeficior/data-modifier-core";
|
|
2
|
+
import { type CommonFilter } from "@adeficior/data-modifier-core/serializer";
|
|
3
|
+
import { type InferIds, type RegistryId } from "@adeficior/data-modifier/generated";
|
|
4
|
+
import { type TagEntry, type TagRegistryHolder } from "../schema";
|
|
5
|
+
import { type TagEmitterOptions } from "./options";
|
|
6
|
+
import { type ScopedTagRules } from "./scoped";
|
|
7
|
+
export interface TagRules {
|
|
8
|
+
add<T extends RegistryId>(registry: T, id: TagInput, value: TagEntry<InferIds<T>>): void;
|
|
9
|
+
remove<T extends RegistryId>(registry: T, id: TagInput, test: CommonFilter<NormalizedId<InferIds<T>>>): void;
|
|
10
|
+
scoped<T extends RegistryId>(key: T, folder?: string): ScopedTagRules<T>;
|
|
11
|
+
empty<T extends RegistryId>(registry: T, id: TagInput): void;
|
|
12
|
+
replace<T extends RegistryId>(registry: T, id: TagInput, values: TagEntry<InferIds<T>>[]): void;
|
|
13
|
+
blocks: ScopedTagRules<"minecraft:block">;
|
|
14
|
+
items: ScopedTagRules<"minecraft:item">;
|
|
15
|
+
fluids: ScopedTagRules<"minecraft:fluid">;
|
|
16
|
+
}
|
|
17
|
+
export declare class TagEmitter implements TagRules, ClearableEmitter {
|
|
18
|
+
private readonly registry;
|
|
19
|
+
private readonly options;
|
|
20
|
+
private readonly emitters;
|
|
21
|
+
readonly blocks: ScopedTagRules<"minecraft:block">;
|
|
22
|
+
readonly items: ScopedTagRules<"minecraft:item">;
|
|
23
|
+
readonly fluids: ScopedTagRules<"minecraft:fluid">;
|
|
24
|
+
constructor(registry: TagRegistryHolder, options: TagEmitterOptions);
|
|
25
|
+
clear(): void;
|
|
26
|
+
resolver(context: LoaderContext): import("@adeficior/pack-resolver").Resolver<import("@adeficior/pack-resolver").Acceptable, import("@adeficior/pack-resolver").BaseContext>;
|
|
27
|
+
add<T extends RegistryId>(registry: T, id: TagInput, value: TagEntry<InferIds<T>>): void;
|
|
28
|
+
remove<T extends RegistryId>(registry: T, id: TagInput, test: CommonFilter<NormalizedId<InferIds<T>>>): void;
|
|
29
|
+
replace<T extends RegistryId>(registry: T, id: TagInput, values: TagEntry<InferIds<T>>[]): void;
|
|
30
|
+
empty<T extends RegistryId>(registry: T, id: TagInput): void;
|
|
31
|
+
scoped<T extends RegistryId>(registry: T, folder?: string): ScopedTagRules<T>;
|
|
32
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { toJson, } from "@adeficior/data-modifier-core";
|
|
2
|
+
import {} from "@adeficior/data-modifier-core/serializer";
|
|
3
|
+
import {} from "@adeficior/data-modifier/generated";
|
|
4
|
+
import { simpleResolver } from "@adeficior/pack-resolver";
|
|
5
|
+
import { orderTagEntries, tagFolderOf } from "../helper";
|
|
6
|
+
import {} from "../schema";
|
|
7
|
+
import {} from "./options";
|
|
8
|
+
import { ScopedEmitter } from "./scoped";
|
|
9
|
+
export class TagEmitter {
|
|
10
|
+
registry;
|
|
11
|
+
options;
|
|
12
|
+
emitters = new Map();
|
|
13
|
+
blocks;
|
|
14
|
+
items;
|
|
15
|
+
fluids;
|
|
16
|
+
constructor(
|
|
17
|
+
// TODO use container or inject?
|
|
18
|
+
registry, options) {
|
|
19
|
+
this.registry = registry;
|
|
20
|
+
this.options = options;
|
|
21
|
+
this.blocks = this.scoped("minecraft:block", "blocks");
|
|
22
|
+
this.items = this.scoped("minecraft:item", "items");
|
|
23
|
+
this.fluids = this.scoped("minecraft:fluid", "fluids");
|
|
24
|
+
}
|
|
25
|
+
clear() {
|
|
26
|
+
this.emitters.forEach((it) => it.clear());
|
|
27
|
+
}
|
|
28
|
+
resolver(context) {
|
|
29
|
+
return simpleResolver(async (acceptor) => {
|
|
30
|
+
const emitters = Array.from(this.emitters.values());
|
|
31
|
+
await Promise.all(emitters.flatMap((scoped) => scoped.getModified(async (id, definition) => {
|
|
32
|
+
const path = `data/${id.namespace}/tags/${scoped.folder}/${id.path}.json`;
|
|
33
|
+
await acceptor(path, toJson({
|
|
34
|
+
...definition,
|
|
35
|
+
values: definition.values && orderTagEntries(definition.values),
|
|
36
|
+
remove: definition.remove && orderTagEntries(definition.remove),
|
|
37
|
+
}));
|
|
38
|
+
})));
|
|
39
|
+
}, context);
|
|
40
|
+
}
|
|
41
|
+
add(registry, id, value) {
|
|
42
|
+
this.scoped(registry).add(id, value);
|
|
43
|
+
}
|
|
44
|
+
remove(registry, id, test) {
|
|
45
|
+
this.scoped(registry).remove(id, test);
|
|
46
|
+
}
|
|
47
|
+
replace(registry, id, values) {
|
|
48
|
+
this.scoped(registry).replace(id, values);
|
|
49
|
+
}
|
|
50
|
+
empty(registry, id) {
|
|
51
|
+
this.scoped(registry).empty(id);
|
|
52
|
+
}
|
|
53
|
+
scoped(registry, folder = tagFolderOf(registry)) {
|
|
54
|
+
const existing = this.emitters.get(registry);
|
|
55
|
+
if (existing)
|
|
56
|
+
return existing;
|
|
57
|
+
else {
|
|
58
|
+
const emitter = new ScopedEmitter(this.registry.registry(registry), folder, this.options);
|
|
59
|
+
this.emitters.set(registry, emitter);
|
|
60
|
+
return emitter;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/emitter/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,MAAM,GAKP,MAAM,+BAA+B,CAAC;AACvC,OAAO,EAAqB,MAAM,0CAA0C,CAAC;AAC7E,OAAO,EAGN,MAAM,oCAAoC,CAAC;AAC5C,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAC1D,OAAO,EAAE,eAAe,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AACzD,OAAO,EAAyC,MAAM,WAAW,CAAC;AAClE,OAAO,EAA0B,MAAM,WAAW,CAAC;AACnD,OAAO,EAAE,aAAa,EAAuB,MAAM,UAAU,CAAC;AA8B9D,MAAM,OAAO,UAAU;IASF;IACA;IATF,QAAQ,GAAG,IAAI,GAAG,EAAqC,CAAC;IAEhE,MAAM,CAAoC;IAC1C,KAAK,CAAmC;IACxC,MAAM,CAAoC;IAEnD;IACE,gCAAgC;IACf,QAA2B,EAC3B,OAA0B;QAD1B,aAAQ,GAAR,QAAQ,CAAmB;QAC3B,YAAO,GAAP,OAAO,CAAmB;QAE3C,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC,iBAAiB,E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C,EAAE,EAAE,KAAK,CAAC,CAAC;IACvC,CAAC;IAED,MAAM,CACJ,QAAW,EACX,EAAY,EACZ,IAA6C;QAE7C,IAAI,CAAC,MAAM,CAAI,QAAQ,CAAC,CAAC,MAAM,CAAC,EAAE,EAAE,IAAI,CAAC,CAAC;IAC5C,CAAC;IAED,OAAO,CACL,QAAW,EACX,EAAY,EACZ,MAA+B;QAE/B,IAAI,CAAC,MAAM,CAAI,QAAQ,CAAC,CAAC,OAAO,CAAC,EAAE,EAAE,MAAM,CAAC,CAAC;IAC/C,CAAC;IAED,KAAK,CAAuB,QAAW,EAAE,EAAY;QACnD,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;IAClC,CAAC;IAED,MAAM,CACJ,QAAW,EACX,SAAiB,WAAW,CAAC,QAAQ,CAAC;QAEtC,MAAM,QAAQ,GAAG,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;QAC7C,IAAI,QAAQ;YAAE,OAAO,QAA6B,CAAC;aAC9C,CAAC;YACJ,MAAM,OAAO,GAAG,IAAI,aAAa,CAC/B,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,QAAQ,CAAC,EAChC,MAAM,EACN,IAAI,CAAC,OAAO,CACb,CAAC;YACF,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;YACrC,OAAO,OAA4B,CAAC;QACtC,CAAC;IACH,CAAC;CACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
//# sourceMappingURL=options.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"options.js","sourceRoot":"","sources":["../../src/emitter/options.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { type Id, type NormalizedId, type TagInput } from "@adeficior/data-modifier-core";
|
|
2
|
+
import { type CommonFilter } from "@adeficior/data-modifier-core/serializer";
|
|
3
|
+
import { type InferIds, type RegistryId } from "@adeficior/data-modifier/generated";
|
|
4
|
+
import { type TagDefinition, type TagEntry, type TagRegistry } from "../schema";
|
|
5
|
+
import { type TagEmitterOptions } from "./options";
|
|
6
|
+
export interface ScopedTagRules<T extends RegistryId> {
|
|
7
|
+
add(id: TagInput, value: TagEntry<InferIds<T>>): void;
|
|
8
|
+
remove(id: TagInput, test: CommonFilter<NormalizedId<InferIds<T>>>): void;
|
|
9
|
+
empty(id: TagInput): void;
|
|
10
|
+
replace(id: TagInput, values: TagEntry<InferIds<T>>[]): void;
|
|
11
|
+
}
|
|
12
|
+
export declare class ScopedEmitter<T extends RegistryId> implements ScopedTagRules<T> {
|
|
13
|
+
private readonly registry;
|
|
14
|
+
readonly folder: string;
|
|
15
|
+
private readonly options;
|
|
16
|
+
constructor(registry: TagRegistry<RegistryId>, folder: string, options: TagEmitterOptions);
|
|
17
|
+
private readonly modifiers;
|
|
18
|
+
getModified<R>(consumer: (id: Id, definition: TagDefinition) => R): R[];
|
|
19
|
+
private modify;
|
|
20
|
+
add(id: TagInput, value: TagEntry): void;
|
|
21
|
+
remove(id: TagInput, test: CommonFilter<NormalizedId<InferIds<T>>>): void;
|
|
22
|
+
empty(id: TagInput): void;
|
|
23
|
+
replace(id: TagInput, values: TagEntry<InferIds<T>>[]): void;
|
|
24
|
+
clear(): void;
|
|
25
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { createId, Registry, } from "@adeficior/data-modifier-core";
|
|
2
|
+
import { resolveIdTest, } from "@adeficior/data-modifier-core/serializer";
|
|
3
|
+
import {} from "@adeficior/data-modifier/generated";
|
|
4
|
+
import { entryId } from "../helper";
|
|
5
|
+
import {} from "../schema";
|
|
6
|
+
import {} from "./options";
|
|
7
|
+
export class ScopedEmitter {
|
|
8
|
+
registry;
|
|
9
|
+
folder;
|
|
10
|
+
options;
|
|
11
|
+
constructor(registry, folder, options) {
|
|
12
|
+
this.registry = registry;
|
|
13
|
+
this.folder = folder;
|
|
14
|
+
this.options = options;
|
|
15
|
+
}
|
|
16
|
+
modifiers = new Registry();
|
|
17
|
+
getModified(consumer) {
|
|
18
|
+
const results = [];
|
|
19
|
+
this.modifiers.forEach((modifiers, id) => {
|
|
20
|
+
const modified = modifiers.reduce((previous, modifier) => modifier(previous), {
|
|
21
|
+
values: [],
|
|
22
|
+
replace: false,
|
|
23
|
+
});
|
|
24
|
+
results.push(consumer(createId(id), modified));
|
|
25
|
+
});
|
|
26
|
+
return results;
|
|
27
|
+
}
|
|
28
|
+
modify(id, modifier) {
|
|
29
|
+
this.modifiers.getOrPut(id, () => []).push(modifier);
|
|
30
|
+
}
|
|
31
|
+
add(id, value) {
|
|
32
|
+
this.modify(id, (previous) => {
|
|
33
|
+
return {
|
|
34
|
+
...previous,
|
|
35
|
+
values: [...(previous.values ?? []), value],
|
|
36
|
+
};
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
remove(id, test) {
|
|
40
|
+
if (this.options.advancedTags) {
|
|
41
|
+
if (test instanceof RegExp || typeof test === "function") {
|
|
42
|
+
throw new Error("advanced tag loader only accepts tag entries in removal");
|
|
43
|
+
}
|
|
44
|
+
this.modify(id, (previous) => {
|
|
45
|
+
return {
|
|
46
|
+
...previous,
|
|
47
|
+
remove: [...(previous.remove ?? []), test],
|
|
48
|
+
};
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
const predicate = resolveIdTest(test, this.registry);
|
|
53
|
+
this.modify(id, (previous) => {
|
|
54
|
+
const defaultValues = (previous.replace ? undefined : this.registry.resolve(id)) ?? [];
|
|
55
|
+
return {
|
|
56
|
+
replace: true,
|
|
57
|
+
values: [...defaultValues, ...(previous.values ?? [])].filter((it) => {
|
|
58
|
+
return !predicate(entryId(it));
|
|
59
|
+
}),
|
|
60
|
+
};
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
empty(id) {
|
|
65
|
+
this.replace(id, []);
|
|
66
|
+
}
|
|
67
|
+
replace(id, values) {
|
|
68
|
+
this.modify(id, () => ({ replace: true, values }));
|
|
69
|
+
}
|
|
70
|
+
clear() {
|
|
71
|
+
this.modifiers.clear();
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
//# sourceMappingURL=scoped.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scoped.js","sourceRoot":"","sources":["../../src/emitter/scoped.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EACR,QAAQ,GAIT,MAAM,+BAA+B,CAAC;AACvC,OAAO,EACL,aAAa,GAGd,MAAM,0CAA0C,CAAC;AAClD,OAAO,EAGN,MAAM,oCAAoC,CAAC;AAC5C,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAuD,MAAM,WAAW,CAAC;AAChF,OAAO,EAA0B,MAAM,WAAW,CAAC;AAcnD,MAAM,OAAO,aAAa;IAEL;IACD;IACC;IAHnB,YACmB,QAAiC,EAClC,MAAc,EACb,OAA0B;QAF1B,aAAQ,GAAR,QAAQ,CAAyB;QAClC,WAAM,GAAN,MAAM,CAAQ;QACb,YAAO,GAAP,OAAO,CAAmB;IAC1C,CAAC;IAEa,SAAS,GAAG,IAAI,QAAQ,EAAiB,CAAC;IAE3D,WAAW,CAAI,QAAkD;QAC/D,MAAM,OAAO,GAAQ,EAAE,CAAC;QAExB,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC,SAAS,EAAE,EAAE,EAAE,EAAE;YACvC,MAAM,QAAQ,GAAG,SAAS,CAAC,MAAM,CAC/B,CAAC,QAAuB,EAAE,QAAQ,EAAE,EAAE,CAAC,QAAQ,CAAC,QAAQ,CAAC,EACzD;gBACE,MAAM,EAAE,EAAE;gBACV,OAAO,EAAE,KAAK;aACf,CACF,CAAC;YAEF,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,EAAE,CAAC,EAAE,QAAQ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C,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC;gBACnE,OAAO;oBACL,OAAO,EAAE,IAAI;oBACb,MAAM,EAAE,CAAC,GAAG,aAAa,EAAE,GAAG,CAAC,QAAQ,CAAC,MAAM,IAAI,EAAE,CAAC,CAAC,CAAC,MAAM,CAC3D,CAAC,EAAE,EAAE,EAAE;wBACL,OAAO,CAAC,SAAS,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC,CAAC;oBACjC,CAAC,CACF;iBACF,CAAC;YACJ,CAAC,CAAC,CAAC;QACL,CAAC;IACH,CAAC;IAED,KAAK,CAAC,EAAY;QAChB,IAAI,CAAC,OAAO,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC;IACvB,CAAC;IAED,OAAO,CAAC,EAAY,EAAE,MAA+B;QACnD,IAAI,CAAC,MAAM,CAAC,EAAE,EAAE,GAAG,EAAE,CAAC,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC;IACrD,CAAC;IAED,KAAK;QACH,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,CAAC;IACzB,CAAC;CACF"}
|
package/dist/helper.d.ts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { type IdInput, type NormalizedId } from "@adeficior/data-modifier-core";
|
|
2
|
+
import { type TagEntry } from "./schema";
|
|
3
|
+
export declare function entryId(entry: TagEntry): NormalizedId;
|
|
4
|
+
export declare function orderTagEntries<T extends string>(entries: TagEntry<T>[]): TagEntry<T>[];
|
|
5
|
+
export declare function tagFolderOf(registry: IdInput): string;
|
package/dist/helper.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { createId, encodeId, } from "@adeficior/data-modifier-core";
|
|
2
|
+
import { orderBy, uniqBy } from "lodash-es";
|
|
3
|
+
import {} from "./schema";
|
|
4
|
+
export function entryId(entry) {
|
|
5
|
+
if (typeof entry === "string")
|
|
6
|
+
return encodeId(entry);
|
|
7
|
+
else
|
|
8
|
+
return encodeId(entry.id);
|
|
9
|
+
}
|
|
10
|
+
export function orderTagEntries(entries) {
|
|
11
|
+
return orderBy(uniqBy(entries, (it) => entryId(it)), (it) => entryId(it));
|
|
12
|
+
}
|
|
13
|
+
export function tagFolderOf(registry) {
|
|
14
|
+
const { path } = createId(registry);
|
|
15
|
+
return path;
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=helper.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"helper.js","sourceRoot":"","sources":["../src/helper.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EACR,QAAQ,GAGT,MAAM,+BAA+B,CAAC;AACvC,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AAC5C,OAAO,EAAiB,MAAM,UAAU,CAAC;AAEzC,MAAM,UAAU,OAAO,CAAC,KAAe;IACrC,IAAI,OAAO,KAAK,KAAK,QAAQ;QAAE,OAAO,QAAQ,CAAC,KAAK,CAAC,CAAC;;QACjD,OAAO,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;AACjC,CAAC;AAED,MAAM,UAAU,eAAe,CAC7B,OAAsB;IAEtB,OAAO,OAAO,CACZ,MAAM,CAAC,OAAO,EAAE,CAAC,EAAE,EAAE,EAAE,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC,EACpC,CAAC,EAAE,EAAE,EAAE,CAAC,OAAO,CAAC,EAAE,CAAC,CACpB,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,WAAW,CAAC,QAAiB;IAC3C,MAAM,EAAE,IAAI,EAAE,GAAG,QAAQ,CAAC,QAAQ,CAAC,CAAC;IACpC,OAAO,IAAI,CAAC;AACd,CAAC"}
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC"}
|
package/dist/loader.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { type IdInput, type SemVerInput } from "@adeficior/data-modifier-core";
|
|
2
|
+
import { type RegistryId } from "@adeficior/data-modifier/generated";
|
|
3
|
+
import { type Acceptable, type Acceptor } from "@adeficior/pack-resolver";
|
|
4
|
+
import { type TagRegistry, type TagRegistryHolder } from "./schema";
|
|
5
|
+
export declare class TagsLoader implements TagRegistryHolder, Acceptor {
|
|
6
|
+
private registries;
|
|
7
|
+
constructor(packFormat: SemVerInput);
|
|
8
|
+
registerRegistry(key: IdInput, folder?: string): void;
|
|
9
|
+
registry<T extends RegistryId>(key: IdInput<T>): TagRegistry<T>;
|
|
10
|
+
private parsePath;
|
|
11
|
+
accept(path: string, content: PromiseLike<Acceptable>): Promise<false | undefined>;
|
|
12
|
+
}
|
package/dist/loader.js
ADDED
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import { encodeId, fromJson, isAtLeastVersion, Registry, } from "@adeficior/data-modifier-core";
|
|
2
|
+
import {} from "@adeficior/data-modifier-core/serializer";
|
|
3
|
+
import {} from "@adeficior/data-modifier/generated";
|
|
4
|
+
import {} from "@adeficior/pack-resolver";
|
|
5
|
+
import { entryId, orderTagEntries, tagFolderOf } from "./helper";
|
|
6
|
+
import {} from "./schema";
|
|
7
|
+
class WriteableTagRegistry {
|
|
8
|
+
folder;
|
|
9
|
+
entries = new Registry();
|
|
10
|
+
constructor(folder) {
|
|
11
|
+
this.folder = folder;
|
|
12
|
+
}
|
|
13
|
+
validateId(input) {
|
|
14
|
+
const id = encodeId(input);
|
|
15
|
+
if (!id.startsWith("#"))
|
|
16
|
+
throw new Error("tag id's must start with a '#'");
|
|
17
|
+
}
|
|
18
|
+
load(id, definition) {
|
|
19
|
+
this.validateId(id);
|
|
20
|
+
const existingEntries = this.entries.get(id) ?? [];
|
|
21
|
+
const unique = orderTagEntries([
|
|
22
|
+
...existingEntries,
|
|
23
|
+
...(definition.values ?? []),
|
|
24
|
+
]);
|
|
25
|
+
// TODO support for advanced-tag-loader packs?
|
|
26
|
+
this.entries.set(id, unique);
|
|
27
|
+
}
|
|
28
|
+
list() {
|
|
29
|
+
return this.entries.keys();
|
|
30
|
+
}
|
|
31
|
+
get(id) {
|
|
32
|
+
this.validateId(id);
|
|
33
|
+
return this.entries.get(id);
|
|
34
|
+
}
|
|
35
|
+
resolve(input, level = 0) {
|
|
36
|
+
const id = encodeId(input);
|
|
37
|
+
if (level >= 100)
|
|
38
|
+
throw new Error(`Circular TagDefinition: ${id}`);
|
|
39
|
+
const entries = this.get(input) ?? [];
|
|
40
|
+
return entries.flatMap((it) => {
|
|
41
|
+
const entry = entryId(it);
|
|
42
|
+
const required = typeof it === "string" ? true : it.required !== false;
|
|
43
|
+
if (entry.startsWith("#")) {
|
|
44
|
+
if (entry === id)
|
|
45
|
+
throw new Error(`Circular TagDefinition: ${entry} -> ${id}`);
|
|
46
|
+
const step = this.resolve(entry);
|
|
47
|
+
if (required)
|
|
48
|
+
return step;
|
|
49
|
+
return step.map((it) => {
|
|
50
|
+
if (typeof it === "string")
|
|
51
|
+
return { required: false, id: it };
|
|
52
|
+
return { ...it, required: false };
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
return [it];
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
contains(id, entry) {
|
|
59
|
+
const entryId = encodeId(entry);
|
|
60
|
+
return (this.get(id)?.some((it) => {
|
|
61
|
+
const value = encodeId(typeof it === "string" ? it : it.id);
|
|
62
|
+
if (value === entryId)
|
|
63
|
+
return true;
|
|
64
|
+
if (value.startsWith("#"))
|
|
65
|
+
return this.contains(value, entryId);
|
|
66
|
+
return false;
|
|
67
|
+
}) ?? false);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
export class TagsLoader {
|
|
71
|
+
registries = {};
|
|
72
|
+
constructor(packFormat) {
|
|
73
|
+
const withSuffix = (it) => {
|
|
74
|
+
if (isAtLeastVersion(packFormat, "44"))
|
|
75
|
+
return it;
|
|
76
|
+
return it + "s";
|
|
77
|
+
};
|
|
78
|
+
this.registerRegistry("minecraft:banner_pattern");
|
|
79
|
+
this.registerRegistry("minecraft:block", withSuffix("block"));
|
|
80
|
+
this.registerRegistry("minecraft:cat_variant");
|
|
81
|
+
this.registerRegistry("minecraft:damage_type");
|
|
82
|
+
this.registerRegistry("minecraft:entity_type", withSuffix("entity_type"));
|
|
83
|
+
this.registerRegistry("minecraft:fluid", withSuffix("fluid"));
|
|
84
|
+
this.registerRegistry("minecraft:game_event", withSuffix("game_event"));
|
|
85
|
+
this.registerRegistry("minecraft:instrument");
|
|
86
|
+
this.registerRegistry("minecraft:item", withSuffix("item"));
|
|
87
|
+
this.registerRegistry("minecraft:painting_variant");
|
|
88
|
+
this.registerRegistry("minecraft:worldgen/biome");
|
|
89
|
+
this.registerRegistry("minecraft:worldgen/structure");
|
|
90
|
+
this.registerRegistry("minecraft:worldgen/flat_level_generator_preset");
|
|
91
|
+
this.registerRegistry("minecraft:worldgen/world_preset");
|
|
92
|
+
}
|
|
93
|
+
registerRegistry(key, folder = tagFolderOf(key)) {
|
|
94
|
+
this.registries[encodeId(key)] = new WriteableTagRegistry(folder);
|
|
95
|
+
}
|
|
96
|
+
registry(key) {
|
|
97
|
+
const id = encodeId(key);
|
|
98
|
+
if (!(id in this.registries))
|
|
99
|
+
throw new Error(`unknown registry tags '${id}'. Register them using \`registerRegistry\``);
|
|
100
|
+
return this.registries[id];
|
|
101
|
+
}
|
|
102
|
+
parsePath(input) {
|
|
103
|
+
const match = /data\/(?<namespace>[\w-]+)\/tags\/(?<rest>[\w-/]+).json/.exec(input);
|
|
104
|
+
if (!match?.groups)
|
|
105
|
+
return null;
|
|
106
|
+
const { namespace, rest } = match.groups;
|
|
107
|
+
const registry = Object.values(this.registries).find((it) => rest.startsWith(`${it.folder}/`));
|
|
108
|
+
if (!registry)
|
|
109
|
+
return null;
|
|
110
|
+
const path = rest.substring(registry.folder.length + 1);
|
|
111
|
+
return { namespace, registry, path, isTag: true };
|
|
112
|
+
}
|
|
113
|
+
async accept(path, content) {
|
|
114
|
+
const info = this.parsePath(path);
|
|
115
|
+
if (!info)
|
|
116
|
+
return false;
|
|
117
|
+
const parsed = fromJson(await content);
|
|
118
|
+
const id = encodeId(info);
|
|
119
|
+
info.registry.load(id, parsed);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
//# sourceMappingURL=loader.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"loader.js","sourceRoot":"","sources":["../src/loader.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EACR,QAAQ,EACR,gBAAgB,EAChB,QAAQ,GAKT,MAAM,+BAA+B,CAAC;AACvC,OAAO,EAAmB,MAAM,0CAA0C,CAAC;AAC3E,OAAO,EAGN,MAAM,oCAAoC,CAAC;AAC5C,OAAO,EAAkC,MAAM,0BAA0B,CAAC;AAC1E,OAAO,EAAE,OAAO,EAAE,eAAe,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AACjE,OAAO,EAKN,MAAM,UAAU,CAAC;AAElB,MAAM,oBAAoB;IAKI;IAFX,OAAO,GAAG,IAAI,QAAQ,EAAiB,CAAC;IAEzD,YAA4B,MAAc;QAAd,WAAM,GAAN,MAAM,CAAQ;IAAG,CAAC;IAEtC,UAAU,CAAC,KAAc;QAC/B,MAAM,EAAE,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC;QAC3B,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,GAAG,CAAC;YAAE,MAAM,IAAI,KAAK,CAAC,gCAAgC,CAAC,CAAC;IAC7E,CAAC;IAED,IAAI,CAAC,EAAY,EAAE,UAAyB;QAC1C,IAAI,CAAC,UAAU,CAAC,EAAE,CAAC,CAAC;QAEpB,MAAM,eAAe,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,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-0,0 +1,11 @@
|
|
|
1
|
+
import { type TagRules } from "./emitter";
|
|
2
|
+
import { type TagRegistryHolder } from "./schema";
|
|
3
|
+
declare const _default: import("@adeficior/data-modifier-core").ModuleConfig<{
|
|
4
|
+
loaders: {
|
|
5
|
+
tags: TagRegistryHolder;
|
|
6
|
+
};
|
|
7
|
+
emitters: {
|
|
8
|
+
tags: TagRules;
|
|
9
|
+
};
|
|
10
|
+
}>;
|
|
11
|
+
export default _default;
|
package/dist/module.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { defineModule } from "@adeficior/data-modifier-core";
|
|
2
|
+
import { name } from "../package.json";
|
|
3
|
+
import { TagEmitter } from "./emitter";
|
|
4
|
+
import { TagsLoader } from "./loader";
|
|
5
|
+
import {} from "./schema";
|
|
6
|
+
export default defineModule({
|
|
7
|
+
importModule: name,
|
|
8
|
+
types: {
|
|
9
|
+
loaders: {
|
|
10
|
+
tags: "TagRegistryHolder",
|
|
11
|
+
},
|
|
12
|
+
emitters: {
|
|
13
|
+
tags: "TagRules",
|
|
14
|
+
},
|
|
15
|
+
},
|
|
16
|
+
setup: (pack) => {
|
|
17
|
+
const loader = pack.loader("tags", () => new TagsLoader(pack.options.packFormat), "data/*/tags/**/*.json");
|
|
18
|
+
// TODO pass actual options
|
|
19
|
+
pack.emitter("tags", () => new TagEmitter(loader(), {}));
|
|
20
|
+
},
|
|
21
|
+
});
|
|
22
|
+
//# sourceMappingURL=module.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"module.js","sourceRoot":"","sources":["../src/module.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAC;AAC7D,OAAO,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAC;AACvC,OAAO,EAAE,UAAU,EAAiB,MAAM,WAAW,CAAC;AACtD,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AACtC,OAAO,EAA0B,MAAM,UAAU,CAAC;AAElD,eAAe,YAAY,CAOxB;IACD,YAAY,EAAE,IAAI;IAClB,KAAK,EAAE;QACL,OAAO,EAAE;YACP,IAAI,EAAE,mBAAmB;SAC1B;QACD,QAAQ,EAAE;YACR,IAAI,EAAE,UAAU;SACjB;KACF;IACD,KAAK,EAAE,CAAC,IAAI,EAAE,EAAE;QACd,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,CACxB,MAAM,EACN,GAAG,EAAE,CAAC,IAAI,UAAU,CAAC,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,EAC7C,uBAAuB,CACxB,CAAC;QAEF,2BAA2B;QAC3B,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,GAAG,EAAE,CAAC,IAAI,UAAU,CAAC,MAAM,EAAE,EAAE,EAAE,CAAC,CAAC,CAAC;IAC3D,CAAC;CACF,CAAC,CAAC"}
|
package/dist/options.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"options.js","sourceRoot":"","sources":["../src/options.ts"],"names":[],"mappings":"AAAA,OAAO,EAA0B,MAAM,mBAAmB,CAAC"}
|
package/dist/schema.d.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { type IdInput, type TagInput } from "@adeficior/data-modifier-core";
|
|
2
|
+
import { type InferIds, type RegistryId } from "@adeficior/data-modifier/generated";
|
|
3
|
+
export type TagDefinition = Readonly<{
|
|
4
|
+
replace?: boolean;
|
|
5
|
+
values?: TagEntry[];
|
|
6
|
+
remove?: TagEntry[];
|
|
7
|
+
}>;
|
|
8
|
+
export type TagEntry<T extends string = string> = T | `#${string}` | Readonly<{
|
|
9
|
+
required?: boolean;
|
|
10
|
+
id: T | `#${string}`;
|
|
11
|
+
}>;
|
|
12
|
+
export interface TagRegistryHolder {
|
|
13
|
+
registry<T extends RegistryId>(key: T): TagRegistry<T>;
|
|
14
|
+
}
|
|
15
|
+
export interface TagRegistry<T extends RegistryId> {
|
|
16
|
+
contains(id: TagInput, entry: IdInput<InferIds<T>>): boolean;
|
|
17
|
+
list(): string[];
|
|
18
|
+
get(id: TagInput): TagEntry<InferIds<T>>[] | undefined;
|
|
19
|
+
resolve(id: TagInput): TagEntry<InferIds<T>>[];
|
|
20
|
+
}
|
package/dist/schema.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema.js","sourceRoot":"","sources":["../src/schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAA+B,MAAM,+BAA+B,CAAC;AAC5E,OAAO,EAGN,MAAM,oCAAoC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./setup";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/testing/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { packFormatOf } from "@adeficior/data-modifier-core";
|
|
2
|
+
import { createTestDataResolver } from "@adeficior/testing";
|
|
3
|
+
import { beforeAll } from "bun:test";
|
|
4
|
+
import { TagsLoader } from "../loader";
|
|
5
|
+
import {} from "../schema";
|
|
6
|
+
export function setupTagRegistry(version) {
|
|
7
|
+
const loader = new TagsLoader(packFormatOf(version));
|
|
8
|
+
beforeAll(async () => {
|
|
9
|
+
const data = await createTestDataResolver(version, {
|
|
10
|
+
include: ["data/*/tags/**/*.json"],
|
|
11
|
+
});
|
|
12
|
+
await data.extract(loader);
|
|
13
|
+
});
|
|
14
|
+
return loader;
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=setup.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"setup.js","sourceRoot":"","sources":["../../src/testing/setup.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAC;AAC7D,OAAO,EAAE,sBAAsB,EAAE,MAAM,oBAAoB,CAAC;AAC5D,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AACrC,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AACvC,OAAO,EAA0B,MAAM,WAAW,CAAC;AAEnD,MAAM,UAAU,gBAAgB,CAAC,OAAe;IAC9C,MAAM,MAAM,GAAG,IAAI,UAAU,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC,CAAC;IAErD,SAAS,CAAC,KAAK,IAAI,EAAE;QACnB,MAAM,IAAI,GAAG,MAAM,sBAAsB,CAAC,OAAO,EAAE;YACjD,OAAO,EAAE,CAAC,uBAAuB,CAAC;SACnC,CAAC,CAAC;QAEH,MAAM,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;IAC7B,CAAC,CAAC,CAAC;IAEH,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@adeficior/data-modifier-tags",
|
|
3
|
+
"version": "2.0.0-rc.20260814115618",
|
|
4
|
+
"exports": {
|
|
5
|
+
".": "./dist/index.js",
|
|
6
|
+
"./testing": "./dist/testing/index.js"
|
|
7
|
+
},
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"files": [
|
|
10
|
+
"dist"
|
|
11
|
+
],
|
|
12
|
+
"typesVersions": {
|
|
13
|
+
"*": {
|
|
14
|
+
"testing": [
|
|
15
|
+
"./dist/testing/index.d.ts"
|
|
16
|
+
]
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
"type": "module",
|
|
20
|
+
"scripts": {
|
|
21
|
+
"build": "tsc --project tsconfig.build.json",
|
|
22
|
+
"check": "tsc --noEmit",
|
|
23
|
+
"dev": "bun run build --watch",
|
|
24
|
+
"lint": "eslint {src,test}",
|
|
25
|
+
"test": "bun test --timeout 10000",
|
|
26
|
+
"prune": "bun run datamod-dev --prune",
|
|
27
|
+
"prepare": "datamod-dev --configs && datamod-dev --types",
|
|
28
|
+
"test:ci": "bun run lint && bun run check && bun run test --coverage"
|
|
29
|
+
},
|
|
30
|
+
"devDependencies": {
|
|
31
|
+
"@adeficior/configs": "workspace:*",
|
|
32
|
+
"@adeficior/testing": "workspace:*",
|
|
33
|
+
"@adeficior/data-modifier-core": "workspace:*",
|
|
34
|
+
"@types/lodash-es": "catalog:"
|
|
35
|
+
},
|
|
36
|
+
"peerDependencies": {
|
|
37
|
+
"@adeficior/pack-resolver": "catalog:",
|
|
38
|
+
"typescript": "catalog:",
|
|
39
|
+
"lodash-es": "catalog:",
|
|
40
|
+
"@adeficior/data-modifier-core": "workspace:*"
|
|
41
|
+
}
|
|
42
|
+
}
|