beet-observer 0.2.1__py3-none-any.whl → 0.4.0__py3-none-any.whl

Sign up to get free protection for your applications and to get access to all the features.
beet_observer/__init__.py CHANGED
@@ -1,3 +1,3 @@
1
- __version__ = "0.2.1"
1
+ __version__ = "0.4.0"
2
2
 
3
3
  from .plugin import *
@@ -1,5 +1,6 @@
1
1
  from typing import Any
2
2
 
3
+ import beet.contrib.worldgen as wg
3
4
  from beet import Context, NamespaceProxy
4
5
 
5
6
 
@@ -48,6 +49,60 @@ def gen_dp_overlays(ctx: Context, ctx_overlay: Context, overlay_dir: str) -> Non
48
49
  ctx.data.point_of_interest_type_tags,
49
50
  ctx_overlay.data.point_of_interest_type_tags,
50
51
  ),
52
+ (ctx.data[wg.Dimension], ctx_overlay.data[wg.Dimension]),
53
+ (ctx.data[wg.DimensionType], ctx_overlay.data[wg.DimensionType]),
54
+ (ctx.data[wg.WorldgenBiome], ctx_overlay.data[wg.WorldgenBiome]),
55
+ (
56
+ ctx.data[wg.WorldgenConfiguredCarver],
57
+ ctx_overlay.data[wg.WorldgenConfiguredCarver],
58
+ ),
59
+ (
60
+ ctx.data[wg.WorldgenConfiguredFeature],
61
+ ctx_overlay.data[wg.WorldgenConfiguredFeature],
62
+ ),
63
+ (
64
+ ctx.data[wg.WorldgenDensityFunction],
65
+ ctx_overlay.data[wg.WorldgenDensityFunction],
66
+ ),
67
+ (ctx.data[wg.WorldgenNoise], ctx_overlay.data[wg.WorldgenNoise]),
68
+ (
69
+ ctx.data[wg.WorldgenNoiseSettings],
70
+ ctx_overlay.data[wg.WorldgenNoiseSettings],
71
+ ),
72
+ (
73
+ ctx.data[wg.WorldgenPlacedFeature],
74
+ ctx_overlay.data[wg.WorldgenPlacedFeature],
75
+ ),
76
+ (
77
+ ctx.data[wg.WorldgenProcessorList],
78
+ ctx_overlay.data[wg.WorldgenProcessorList],
79
+ ),
80
+ (ctx.data[wg.WorldgenStructure], ctx_overlay.data[wg.WorldgenStructure]),
81
+ (ctx.data[wg.WorldgenStructureSet], ctx_overlay.data[wg.WorldgenStructureSet]),
82
+ (
83
+ ctx.data[wg.WorldgenConfiguredSurfaceBuilder],
84
+ ctx_overlay.data[wg.WorldgenConfiguredSurfaceBuilder],
85
+ ),
86
+ (ctx.data[wg.WorldgenTemplatePool], ctx_overlay.data[wg.WorldgenTemplatePool]),
87
+ (ctx.data[wg.WorldgenWorldPreset], ctx_overlay.data[wg.WorldgenWorldPreset]),
88
+ (
89
+ ctx.data[wg.WorldgenFlatLevelGeneratorPreset],
90
+ ctx_overlay.data[wg.WorldgenFlatLevelGeneratorPreset],
91
+ ),
92
+ (ctx.data[wg.WorldgenBiomeTag], ctx_overlay.data[wg.WorldgenBiomeTag]),
93
+ (
94
+ ctx.data[wg.WorldgenStructureSetTag],
95
+ ctx_overlay.data[wg.WorldgenStructureSetTag],
96
+ ),
97
+ (ctx.data[wg.WorldgenStructureTag], ctx_overlay.data[wg.WorldgenStructureTag]),
98
+ (
99
+ ctx.data[wg.WorldgenConfiguredCarverTag],
100
+ ctx_overlay.data[wg.WorldgenConfiguredCarverTag],
101
+ ),
102
+ (
103
+ ctx.data[wg.WorldgenPlacedFeatureTag],
104
+ ctx_overlay.data[wg.WorldgenPlacedFeatureTag],
105
+ ),
51
106
  ]
52
107
  # for each file type, check for required overlays
53
108
  for registry, registry_overlay in file_types:
@@ -155,13 +210,18 @@ def gen_registry_overlay(
155
210
  ctx.data.overlays[default_dir][name] = registry[name]
156
211
  del registry[name]
157
212
  elif type == "addition":
158
- # move function from overlay pack to overlay in build pack
213
+ # move file from overlay pack to overlay in build pack
159
214
  ctx.data.overlays[overlay_dir][name] = registry_overlay[name]
160
215
  else:
161
216
  # check if files are exactly the same
162
- if registry[name] != registry_overlay[name]:
163
- # move function from overlay pack to overlay in build pack
164
- ctx.data.overlays[overlay_dir][name] = registry_overlay[name]
217
+ try:
218
+ if registry[name].data != registry_overlay[name].data:
219
+ # move file from overlay pack to overlay in build pack
220
+ ctx.data.overlays[overlay_dir][name] = registry_overlay[name]
221
+ except AttributeError:
222
+ if registry[name] != registry_overlay[name]:
223
+ # move file from overlay pack to overlay in build pack
224
+ ctx.data.overlays[overlay_dir][name] = registry_overlay[name]
165
225
 
166
226
  # remove file from overlay pack
167
227
  if name in registry_overlay:
@@ -1,5 +1,151 @@
1
- from beet import Context
1
+ from typing import Any
2
2
 
3
+ from beet import Context, NamespaceProxy
3
4
 
4
- def gen_rp_overlays(ctx: Context, ctx_overlay: Context, directory: str):
5
- return
5
+
6
+ def gen_rp_overlays(ctx: Context, ctx_overlay: Context, overlay_dir: str) -> None:
7
+ """
8
+ Generates overlays between two resource packs.
9
+
10
+ Keyword arguments:</br>
11
+ `ctx` -- the build context</br>
12
+ `ctx_overlay` -- the overlay context</br>
13
+ `overlay_dir` -- the directory of the overlay</br>
14
+ """
15
+ # create list of all resource pack file types
16
+ file_types: list[tuple[NamespaceProxy[Any], NamespaceProxy[Any]]] = [
17
+ (ctx.assets.blockstates, ctx_overlay.assets.blockstates),
18
+ (ctx.assets.models, ctx_overlay.assets.models),
19
+ (ctx.assets.languages, ctx_overlay.assets.languages),
20
+ (ctx.assets.fonts, ctx_overlay.assets.fonts),
21
+ (ctx.assets.glyph_sizes, ctx_overlay.assets.glyph_sizes),
22
+ (ctx.assets.true_type_fonts, ctx_overlay.assets.true_type_fonts),
23
+ (ctx.assets.shader_posts, ctx_overlay.assets.shader_posts),
24
+ (ctx.assets.shaders, ctx_overlay.assets.shaders),
25
+ (ctx.assets.fragment_shaders, ctx_overlay.assets.fragment_shaders),
26
+ (ctx.assets.vertex_shaders, ctx_overlay.assets.vertex_shaders),
27
+ (ctx.assets.glsl_shaders, ctx_overlay.assets.glsl_shaders),
28
+ (ctx.assets.texts, ctx_overlay.assets.texts),
29
+ (ctx.assets.textures_mcmeta, ctx_overlay.assets.textures_mcmeta),
30
+ (ctx.assets.textures, ctx_overlay.assets.textures),
31
+ (ctx.assets.sounds, ctx_overlay.assets.sounds),
32
+ (ctx.assets.particles, ctx_overlay.assets.particles),
33
+ (ctx.assets.atlases, ctx_overlay.assets.atlases),
34
+ ]
35
+ # for each file type, check for required overlays
36
+ for registry, registry_overlay in file_types:
37
+ check_registry(ctx, ctx_overlay, overlay_dir, registry, registry_overlay)
38
+
39
+ # get pack.mcmeta overlay entries
40
+ mcmeta: dict[str, dict[str, list[dict[str, Any]]]] = ctx.assets.mcmeta.data.copy()
41
+ if "overlays" not in mcmeta:
42
+ mcmeta["overlays"] = {}
43
+ if "entries" not in mcmeta["overlays"]:
44
+ mcmeta["overlays"]["entries"] = []
45
+ entries = mcmeta["overlays"]["entries"]
46
+
47
+ # add overlays to pack.mcmeta
48
+ for overlay in ctx.assets.overlays:
49
+ # check if it's the top-level overlay
50
+ if overlay == ctx.meta["observer"]["default_dir_rp"]:
51
+ # delete pack.mcmeta from overlay (required for tests)
52
+ default_dir = ctx.meta["observer"]["default_dir_rp"]
53
+ if ctx.assets.overlays[default_dir].mcmeta:
54
+ del ctx.assets.overlays[default_dir].mcmeta
55
+
56
+ # get pack format from build context
57
+ if "default_format" in ctx.meta["observer"]:
58
+ formats = ctx.meta["observer"]["default_format"]
59
+ else:
60
+ formats = ctx.assets.mcmeta.data["pack"]["pack_format"]
61
+ else:
62
+ # get formats from overlay pack
63
+ if "supported_formats" in ctx_overlay.assets.mcmeta.data["pack"]:
64
+ formats = ctx_overlay.assets.mcmeta.data["pack"]["supported_formats"]
65
+ else:
66
+ formats = ctx_overlay.assets.mcmeta.data["pack"]["pack_format"]
67
+
68
+ # update pack.mcmeta overlay entries
69
+ entries.append(
70
+ {
71
+ "formats": formats,
72
+ "directory": overlay,
73
+ }
74
+ )
75
+
76
+ # save overlay entries in pack.mcmeta
77
+ if len(entries) > 0:
78
+ ctx.assets.mcmeta.data.update({"overlays": {"entries": entries}})
79
+
80
+
81
+ def check_registry(
82
+ ctx: Context,
83
+ ctx_overlay: Context,
84
+ overlay_dir: str,
85
+ registry: NamespaceProxy[Any],
86
+ registry_overlay: NamespaceProxy[Any],
87
+ ) -> None:
88
+ """
89
+ Generates overlays for each namespace proxy.
90
+
91
+ Keyword arguments:</br>
92
+ `ctx` -- the build context</br>
93
+ `ctx_overlay` -- the overlay context</br>
94
+ `overlay_dir` -- the directory of the overlay</br>
95
+ `registry` -- the namespace proxy from the build context</br>
96
+ `registry_overlay` -- the namespace proxy from the overlay context</br>
97
+ """
98
+ # check each file in the build pack
99
+ for name in list(registry):
100
+ if name in registry_overlay:
101
+ # exists in both, so check if an overlay is needed
102
+ gen_registry_overlay(ctx, overlay_dir, name, registry, registry_overlay)
103
+ else:
104
+ # exists only in overlay, so create a deletion overlay
105
+ gen_registry_overlay(
106
+ ctx, overlay_dir, name, registry, registry_overlay, "deletion"
107
+ )
108
+
109
+ # for all remaining files (of this type) in the overlay pack, add to build pack as an overlay
110
+ for name in list(registry_overlay):
111
+ gen_registry_overlay(
112
+ ctx, overlay_dir, name, registry, registry_overlay, "addition"
113
+ )
114
+
115
+
116
+ def gen_registry_overlay(
117
+ ctx: Context,
118
+ overlay_dir: str,
119
+ name: str,
120
+ registry: NamespaceProxy[Any],
121
+ registry_overlay: NamespaceProxy[Any],
122
+ type: str = "",
123
+ ) -> None:
124
+ """
125
+ Checks if two functions have the same contents and generate an overlay if they don't.
126
+
127
+ Keyword arguments:</br>
128
+ `ctx` -- the build context</br>
129
+ `overlay_dir` -- the directory of the generated overlay</br>
130
+ `name` -- the name of the file</br>
131
+ `registry` -- the namespace proxy from the build context</br>
132
+ `registry_overlay` -- the namespace proxy from the overlay context</br>
133
+ `type` -- either "deletion" or "addition" (default: `""`)</br>
134
+ """
135
+ if type == "deletion":
136
+ # move file from build pack to overlay in build pack
137
+ default_dir = ctx.meta["observer"]["default_dir_rp"]
138
+ ctx.assets.overlays[default_dir][name] = registry[name]
139
+ del registry[name]
140
+ elif type == "addition":
141
+ # move function from overlay pack to overlay in build pack
142
+ ctx.assets.overlays[overlay_dir][name] = registry_overlay[name]
143
+ else:
144
+ # check if files are exactly the same
145
+ if registry[name] != registry_overlay[name]:
146
+ # move function from overlay pack to overlay in build pack
147
+ ctx.assets.overlays[overlay_dir][name] = registry_overlay[name]
148
+
149
+ # remove file from overlay pack
150
+ if name in registry_overlay:
151
+ del registry_overlay[name]
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: beet-observer
3
- Version: 0.2.1
3
+ Version: 0.4.0
4
4
  Summary: A beet plugin to automatically generate overlays from previous datapacks
5
5
  License: MIT
6
6
  Author: BPR02
@@ -12,6 +12,7 @@ Classifier: Programming Language :: Python :: 3.10
12
12
  Classifier: Programming Language :: Python :: 3.11
13
13
  Classifier: Programming Language :: Python :: 3.12
14
14
  Requires-Dist: beet (>=0.108.5)
15
+ Requires-Dist: pillow (>=11.0.0,<12.0.0)
15
16
  Description-Content-Type: text/markdown
16
17
 
17
18
  # Observer
@@ -0,0 +1,8 @@
1
+ beet_observer/__init__.py,sha256=N7xZKu7fP_rwtJSXJ8tHQgq_qJDbu7yWOKOXnldjr04,45
2
+ beet_observer/data_pack.py,sha256=CMTZ2DdBEIj15wC_prAQv3I-0Eptk0usTP237KuxfLk,9724
3
+ beet_observer/plugin.py,sha256=DGpWvV2q6yeJ_EyBLShigZl4dutN2yCFDKzzcCGiu8o,1808
4
+ beet_observer/resource_pack.py,sha256=9dAeZXlJrcaEiIJcPYnJhU7e0qMUqYNcxhIEhLDHUF4,6157
5
+ beet_observer-0.4.0.dist-info/LICENSE,sha256=oBbP6j7sgG9darFSRZxV7iO8yPR1aZiDspSK3mcLpXI,1062
6
+ beet_observer-0.4.0.dist-info/METADATA,sha256=B2ehMsXlmntYVO4SwaAjjJChjPumJUFMUT2a5fzSJ2k,674
7
+ beet_observer-0.4.0.dist-info/WHEEL,sha256=FMvqSimYX_P7y0a7UY-_Mc83r5zkBZsCYPm7Lr0Bsq4,88
8
+ beet_observer-0.4.0.dist-info/RECORD,,
@@ -1,8 +0,0 @@
1
- beet_observer/__init__.py,sha256=wrNZq4cbCCTtIPOQhShOufEQmAhkL5Ww1yOOzF74DTw,45
2
- beet_observer/data_pack.py,sha256=OYGy9vDePpWyDhVpTl2Y-P49UEhsivihOqo17dfNKTM,7166
3
- beet_observer/plugin.py,sha256=DGpWvV2q6yeJ_EyBLShigZl4dutN2yCFDKzzcCGiu8o,1808
4
- beet_observer/resource_pack.py,sha256=ePNdQjeMrEKEkLdDBsnHcMdrne8g505Cd8vfzX5S_cc,111
5
- beet_observer-0.2.1.dist-info/LICENSE,sha256=oBbP6j7sgG9darFSRZxV7iO8yPR1aZiDspSK3mcLpXI,1062
6
- beet_observer-0.2.1.dist-info/METADATA,sha256=WUsicEsv5Vs3qknF4a_rb9KuwQT2QR5WjMPP9lLHnIs,633
7
- beet_observer-0.2.1.dist-info/WHEEL,sha256=FMvqSimYX_P7y0a7UY-_Mc83r5zkBZsCYPm7Lr0Bsq4,88
8
- beet_observer-0.2.1.dist-info/RECORD,,