amulet-core 2.0a8__cp312-cp312-win_amd64.whl → 2.0.1.0.1297307203.19.43.34808.0a0__cp312-cp312-win_amd64.whl

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.

Potentially problematic release.


This version of amulet-core might be problematic. Click here for more details.

Files changed (271) hide show
  1. amulet/core/__init__.py +36 -0
  2. amulet/core/__pyinstaller/hook-amulet.core.py +4 -0
  3. amulet/core/_amulet_core.cp312-win_amd64.pyd +0 -0
  4. amulet/core/_amulet_core.pyi +7 -0
  5. amulet/{_version.py → core/_version.py} +3 -3
  6. amulet/core/amulet_core.dll +0 -0
  7. amulet/core/amulet_core.lib +0 -0
  8. amulet/core/amulet_coreConfig.cmake +18 -0
  9. amulet/{biome.pyi → core/biome/__init__.pyi} +3 -3
  10. amulet/core/biome/biome.hpp +53 -0
  11. amulet/{block.pyi → core/block/__init__.pyi} +25 -26
  12. amulet/core/block/block.hpp +156 -0
  13. amulet/{block_entity.pyi → core/block_entity/__init__.pyi} +7 -7
  14. amulet/core/block_entity/block_entity.hpp +84 -0
  15. amulet/{errors.py → core/chunk/__init__.pyi} +37 -33
  16. amulet/core/chunk/chunk.hpp +126 -0
  17. amulet/core/chunk/component/__init__.pyi +18 -0
  18. amulet/core/chunk/component/biome_3d_component.hpp +96 -0
  19. amulet/core/chunk/component/block_component.hpp +101 -0
  20. amulet/core/chunk/component/block_component.pyi +28 -0
  21. amulet/core/chunk/component/block_entity_component.hpp +119 -0
  22. amulet/core/chunk/component/section_array_map.hpp +129 -0
  23. amulet/{chunk_components.pyi → core/chunk/component/section_array_map.pyi} +4 -24
  24. amulet/core/dll.hpp +21 -0
  25. amulet/core/entity/__init__.pyi +105 -0
  26. amulet/core/entity/entity.hpp +100 -0
  27. amulet/{palette → core/palette}/__init__.pyi +2 -2
  28. amulet/core/palette/biome_palette.hpp +65 -0
  29. amulet/{palette → core/palette}/biome_palette.pyi +8 -8
  30. amulet/core/palette/block_palette.hpp +71 -0
  31. amulet/{palette → core/palette}/block_palette.pyi +12 -10
  32. amulet/core/selection/__init__.pyi +8 -0
  33. amulet/core/selection/box.hpp +86 -0
  34. amulet/core/selection/box.pyi +215 -0
  35. amulet/core/selection/group.hpp +80 -0
  36. amulet/core/selection/group.pyi +213 -0
  37. amulet/{version.pyi → core/version/__init__.pyi} +58 -10
  38. amulet/core/version/version.hpp +204 -0
  39. {amulet_core-2.0a8.dist-info → amulet_core-2.0.1.0.1297307203.19.43.34808.0a0.dist-info}/METADATA +25 -20
  40. amulet_core-2.0.1.0.1297307203.19.43.34808.0a0.dist-info/RECORD +45 -0
  41. {amulet_core-2.0a8.dist-info → amulet_core-2.0.1.0.1297307203.19.43.34808.0a0.dist-info}/WHEEL +1 -1
  42. amulet_core-2.0.1.0.1297307203.19.43.34808.0a0.dist-info/entry_points.txt +2 -0
  43. amulet/__init__.cp312-win_amd64.pyd +0 -0
  44. amulet/__init__.py.cpp +0 -45
  45. amulet/__init__.pyi +0 -30
  46. amulet/__pyinstaller/hook-amulet.py +0 -4
  47. amulet/_init.py +0 -26
  48. amulet/biome.cpp +0 -36
  49. amulet/biome.hpp +0 -43
  50. amulet/biome.py.cpp +0 -122
  51. amulet/block.cpp +0 -435
  52. amulet/block.hpp +0 -119
  53. amulet/block.py.cpp +0 -377
  54. amulet/block_entity.cpp +0 -12
  55. amulet/block_entity.hpp +0 -56
  56. amulet/block_entity.py.cpp +0 -115
  57. amulet/chunk.cpp +0 -16
  58. amulet/chunk.hpp +0 -100
  59. amulet/chunk.py.cpp +0 -80
  60. amulet/chunk.pyi +0 -28
  61. amulet/chunk_components/biome_3d_component.cpp +0 -5
  62. amulet/chunk_components/biome_3d_component.hpp +0 -79
  63. amulet/chunk_components/block_component.cpp +0 -41
  64. amulet/chunk_components/block_component.hpp +0 -88
  65. amulet/chunk_components/block_entity_component.cpp +0 -5
  66. amulet/chunk_components/block_entity_component.hpp +0 -147
  67. amulet/chunk_components/section_array_map.cpp +0 -129
  68. amulet/chunk_components/section_array_map.hpp +0 -147
  69. amulet/collections/eq.py.hpp +0 -37
  70. amulet/collections/hash.py.hpp +0 -27
  71. amulet/collections/holder.py.hpp +0 -37
  72. amulet/collections/iterator.py.hpp +0 -80
  73. amulet/collections/mapping.py.hpp +0 -199
  74. amulet/collections/mutable_mapping.py.hpp +0 -226
  75. amulet/collections/sequence.py.hpp +0 -163
  76. amulet/collections.pyi +0 -40
  77. amulet/data_types.py +0 -29
  78. amulet/entity.py +0 -182
  79. amulet/game/__init__.py +0 -7
  80. amulet/game/_game.py +0 -152
  81. amulet/game/_universal/__init__.py +0 -1
  82. amulet/game/_universal/_biome.py +0 -17
  83. amulet/game/_universal/_block.py +0 -47
  84. amulet/game/_universal/_version.py +0 -68
  85. amulet/game/abc/__init__.py +0 -22
  86. amulet/game/abc/_block_specification.py +0 -150
  87. amulet/game/abc/biome.py +0 -213
  88. amulet/game/abc/block.py +0 -331
  89. amulet/game/abc/game_version_container.py +0 -25
  90. amulet/game/abc/json_interface.py +0 -27
  91. amulet/game/abc/version.py +0 -44
  92. amulet/game/bedrock/__init__.py +0 -1
  93. amulet/game/bedrock/_biome.py +0 -35
  94. amulet/game/bedrock/_block.py +0 -42
  95. amulet/game/bedrock/_version.py +0 -165
  96. amulet/game/java/__init__.py +0 -2
  97. amulet/game/java/_biome.py +0 -35
  98. amulet/game/java/_block.py +0 -60
  99. amulet/game/java/_version.py +0 -176
  100. amulet/game/translate/__init__.py +0 -12
  101. amulet/game/translate/_functions/__init__.py +0 -15
  102. amulet/game/translate/_functions/_code_functions/__init__.py +0 -0
  103. amulet/game/translate/_functions/_code_functions/_text.py +0 -553
  104. amulet/game/translate/_functions/_code_functions/banner_pattern.py +0 -67
  105. amulet/game/translate/_functions/_code_functions/bedrock_chest_connection.py +0 -152
  106. amulet/game/translate/_functions/_code_functions/bedrock_moving_block_pos.py +0 -88
  107. amulet/game/translate/_functions/_code_functions/bedrock_sign.py +0 -152
  108. amulet/game/translate/_functions/_code_functions/bedrock_skull_rotation.py +0 -16
  109. amulet/game/translate/_functions/_code_functions/custom_name.py +0 -146
  110. amulet/game/translate/_functions/_frozen.py +0 -66
  111. amulet/game/translate/_functions/_state.py +0 -54
  112. amulet/game/translate/_functions/_typing.py +0 -98
  113. amulet/game/translate/_functions/abc.py +0 -123
  114. amulet/game/translate/_functions/carry_nbt.py +0 -160
  115. amulet/game/translate/_functions/carry_properties.py +0 -80
  116. amulet/game/translate/_functions/code.py +0 -143
  117. amulet/game/translate/_functions/map_block_name.py +0 -66
  118. amulet/game/translate/_functions/map_nbt.py +0 -111
  119. amulet/game/translate/_functions/map_properties.py +0 -93
  120. amulet/game/translate/_functions/multiblock.py +0 -112
  121. amulet/game/translate/_functions/new_block.py +0 -42
  122. amulet/game/translate/_functions/new_entity.py +0 -43
  123. amulet/game/translate/_functions/new_nbt.py +0 -206
  124. amulet/game/translate/_functions/new_properties.py +0 -64
  125. amulet/game/translate/_functions/sequence.py +0 -51
  126. amulet/game/translate/_functions/walk_input_nbt.py +0 -331
  127. amulet/game/translate/_translator.py +0 -433
  128. amulet/img/__init__.py +0 -10
  129. amulet/img/missing_no.png +0 -0
  130. amulet/img/missing_pack.png +0 -0
  131. amulet/img/missing_world.png +0 -0
  132. amulet/io/binary_reader.hpp +0 -45
  133. amulet/io/binary_writer.hpp +0 -30
  134. amulet/item.py +0 -75
  135. amulet/level/__init__.pyi +0 -23
  136. amulet/level/_load.py +0 -100
  137. amulet/level/abc/__init__.py +0 -12
  138. amulet/level/abc/_chunk_handle.py +0 -358
  139. amulet/level/abc/_dimension.py +0 -86
  140. amulet/level/abc/_history/__init__.py +0 -1
  141. amulet/level/abc/_history/_cache.py +0 -224
  142. amulet/level/abc/_history/_history_manager.py +0 -291
  143. amulet/level/abc/_level/__init__.py +0 -5
  144. amulet/level/abc/_level/_compactable_level.py +0 -10
  145. amulet/level/abc/_level/_creatable_level.py +0 -28
  146. amulet/level/abc/_level/_disk_level.py +0 -17
  147. amulet/level/abc/_level/_level.py +0 -449
  148. amulet/level/abc/_level/_loadable_level.py +0 -42
  149. amulet/level/abc/_player_storage.py +0 -7
  150. amulet/level/abc/_raw_level.py +0 -187
  151. amulet/level/abc/_registry.py +0 -40
  152. amulet/level/java/__init__.pyi +0 -16
  153. amulet/level/java/_chunk_handle.py +0 -17
  154. amulet/level/java/_dimension.py +0 -20
  155. amulet/level/java/_level.py +0 -184
  156. amulet/level/java/_raw/__init__.pyi +0 -15
  157. amulet/level/java/_raw/_chunk.pyi +0 -23
  158. amulet/level/java/_raw/_constant.py +0 -9
  159. amulet/level/java/_raw/_data_pack/__init__.py +0 -2
  160. amulet/level/java/_raw/_data_pack/data_pack.py +0 -241
  161. amulet/level/java/_raw/_data_pack/data_pack_manager.py +0 -77
  162. amulet/level/java/_raw/_dimension.py +0 -86
  163. amulet/level/java/_raw/_level.py +0 -507
  164. amulet/level/java/_raw/_typing.py +0 -3
  165. amulet/level/java/_raw/java_chunk_decode.cpp +0 -531
  166. amulet/level/java/_raw/java_chunk_decode.hpp +0 -23
  167. amulet/level/java/_raw/java_chunk_encode.cpp +0 -25
  168. amulet/level/java/_raw/java_chunk_encode.hpp +0 -23
  169. amulet/level/java/anvil/__init__.py +0 -2
  170. amulet/level/java/anvil/_dimension.py +0 -170
  171. amulet/level/java/anvil/_region.py +0 -421
  172. amulet/level/java/anvil/_sector_manager.py +0 -223
  173. amulet/level/java/chunk.pyi +0 -81
  174. amulet/level/java/chunk_/_chunk.py +0 -260
  175. amulet/level/java/chunk_/components/inhabited_time.py +0 -12
  176. amulet/level/java/chunk_/components/last_update.py +0 -12
  177. amulet/level/java/chunk_/components/legacy_version.py +0 -12
  178. amulet/level/java/chunk_/components/light_populated.py +0 -12
  179. amulet/level/java/chunk_/components/named_height_2d.py +0 -37
  180. amulet/level/java/chunk_/components/status.py +0 -11
  181. amulet/level/java/chunk_/components/terrain_populated.py +0 -12
  182. amulet/level/java/chunk_components/data_version_component.cpp +0 -32
  183. amulet/level/java/chunk_components/data_version_component.hpp +0 -31
  184. amulet/level/java/chunk_components/java_raw_chunk_component.cpp +0 -56
  185. amulet/level/java/chunk_components/java_raw_chunk_component.hpp +0 -45
  186. amulet/level/java/chunk_components.pyi +0 -22
  187. amulet/level/java/java_chunk.cpp +0 -170
  188. amulet/level/java/java_chunk.hpp +0 -141
  189. amulet/level/java/long_array.hpp +0 -175
  190. amulet/level/java/long_array.pyi +0 -39
  191. amulet/level/temporary_level/__init__.py +0 -1
  192. amulet/level/temporary_level/_level.py +0 -16
  193. amulet/mesh/__init__.py +0 -0
  194. amulet/mesh/block/__init__.pyi +0 -301
  195. amulet/mesh/block/_cube.py +0 -198
  196. amulet/mesh/block/_missing_block.py +0 -20
  197. amulet/mesh/block/block_mesh.cpp +0 -107
  198. amulet/mesh/block/block_mesh.hpp +0 -207
  199. amulet/mesh/util.py +0 -17
  200. amulet/palette/biome_palette.hpp +0 -85
  201. amulet/palette/block_palette.cpp +0 -32
  202. amulet/palette/block_palette.hpp +0 -93
  203. amulet/player.py +0 -62
  204. amulet/pybind11/collections.hpp +0 -118
  205. amulet/pybind11/numpy.hpp +0 -26
  206. amulet/pybind11/py_module.hpp +0 -34
  207. amulet/pybind11/type_hints.hpp +0 -51
  208. amulet/pybind11/types.hpp +0 -25
  209. amulet/pybind11/typing.hpp +0 -7
  210. amulet/resource_pack/__init__.py +0 -63
  211. amulet/resource_pack/abc/__init__.py +0 -2
  212. amulet/resource_pack/abc/resource_pack.py +0 -38
  213. amulet/resource_pack/abc/resource_pack_manager.py +0 -85
  214. amulet/resource_pack/java/__init__.py +0 -2
  215. amulet/resource_pack/java/download_resources.py +0 -212
  216. amulet/resource_pack/java/java_vanilla_fix/assets/minecraft/textures/block/banner/banner_black.png +0 -0
  217. amulet/resource_pack/java/java_vanilla_fix/assets/minecraft/textures/block/banner/banner_blue.png +0 -0
  218. amulet/resource_pack/java/java_vanilla_fix/assets/minecraft/textures/block/banner/banner_brown.png +0 -0
  219. amulet/resource_pack/java/java_vanilla_fix/assets/minecraft/textures/block/banner/banner_cyan.png +0 -0
  220. amulet/resource_pack/java/java_vanilla_fix/assets/minecraft/textures/block/banner/banner_gray.png +0 -0
  221. amulet/resource_pack/java/java_vanilla_fix/assets/minecraft/textures/block/banner/banner_green.png +0 -0
  222. amulet/resource_pack/java/java_vanilla_fix/assets/minecraft/textures/block/banner/banner_light_blue.png +0 -0
  223. amulet/resource_pack/java/java_vanilla_fix/assets/minecraft/textures/block/banner/banner_light_gray.png +0 -0
  224. amulet/resource_pack/java/java_vanilla_fix/assets/minecraft/textures/block/banner/banner_lime.png +0 -0
  225. amulet/resource_pack/java/java_vanilla_fix/assets/minecraft/textures/block/banner/banner_magenta.png +0 -0
  226. amulet/resource_pack/java/java_vanilla_fix/assets/minecraft/textures/block/banner/banner_orange.png +0 -0
  227. amulet/resource_pack/java/java_vanilla_fix/assets/minecraft/textures/block/banner/banner_pink.png +0 -0
  228. amulet/resource_pack/java/java_vanilla_fix/assets/minecraft/textures/block/banner/banner_purple.png +0 -0
  229. amulet/resource_pack/java/java_vanilla_fix/assets/minecraft/textures/block/banner/banner_red.png +0 -0
  230. amulet/resource_pack/java/java_vanilla_fix/assets/minecraft/textures/block/banner/banner_white.png +0 -0
  231. amulet/resource_pack/java/java_vanilla_fix/assets/minecraft/textures/block/banner/banner_yellow.png +0 -0
  232. amulet/resource_pack/java/java_vanilla_fix/assets/minecraft/textures/block/barrier.png +0 -0
  233. amulet/resource_pack/java/java_vanilla_fix/assets/minecraft/textures/block/end_portal.png +0 -0
  234. amulet/resource_pack/java/java_vanilla_fix/assets/minecraft/textures/block/grass.png +0 -0
  235. amulet/resource_pack/java/java_vanilla_fix/assets/minecraft/textures/block/lava.png +0 -0
  236. amulet/resource_pack/java/java_vanilla_fix/assets/minecraft/textures/block/structure_void.png +0 -0
  237. amulet/resource_pack/java/java_vanilla_fix/assets/minecraft/textures/block/water.png +0 -0
  238. amulet/resource_pack/java/java_vanilla_fix/pack.png +0 -0
  239. amulet/resource_pack/java/resource_pack.py +0 -44
  240. amulet/resource_pack/java/resource_pack_manager.py +0 -563
  241. amulet/resource_pack/unknown_resource_pack.py +0 -10
  242. amulet/selection/__init__.py +0 -2
  243. amulet/selection/abstract_selection.py +0 -342
  244. amulet/selection/box.py +0 -852
  245. amulet/selection/group.py +0 -481
  246. amulet/utils/__init__.pyi +0 -23
  247. amulet/utils/call_spec/__init__.py +0 -24
  248. amulet/utils/call_spec/_call_spec.py +0 -257
  249. amulet/utils/cast.py +0 -10
  250. amulet/utils/comment_json.py +0 -188
  251. amulet/utils/format_utils.py +0 -41
  252. amulet/utils/generator.py +0 -18
  253. amulet/utils/matrix.py +0 -243
  254. amulet/utils/numpy.hpp +0 -36
  255. amulet/utils/numpy.pyi +0 -11
  256. amulet/utils/numpy_helpers.py +0 -19
  257. amulet/utils/shareable_lock.py +0 -335
  258. amulet/utils/signal/__init__.py +0 -10
  259. amulet/utils/signal/_signal.py +0 -228
  260. amulet/utils/task_manager.py +0 -235
  261. amulet/utils/typed_property.py +0 -111
  262. amulet/utils/weakref.py +0 -70
  263. amulet/utils/world_utils.py +0 -102
  264. amulet/version.cpp +0 -136
  265. amulet/version.hpp +0 -142
  266. amulet/version.py.cpp +0 -281
  267. amulet_core-2.0a8.dist-info/RECORD +0 -241
  268. amulet_core-2.0a8.dist-info/entry_points.txt +0 -2
  269. /amulet/{__pyinstaller → core/__pyinstaller}/__init__.py +0 -0
  270. /amulet/{py.typed → core/py.typed} +0 -0
  271. {amulet_core-2.0a8.dist-info → amulet_core-2.0.1.0.1297307203.19.43.34808.0a0.dist-info}/top_level.txt +0 -0
@@ -1,102 +0,0 @@
1
- from __future__ import annotations
2
-
3
- import math
4
- from typing import Optional
5
- import numpy
6
- from numpy import ndarray, zeros, uint8
7
- from amulet.data_types import ChunkCoordinates
8
-
9
-
10
- def block_coords_to_chunk_coords(
11
- *args: int, sub_chunk_size: int = 16
12
- ) -> tuple[int, ...]:
13
- """
14
- Converts the supplied block coordinates into chunk coordinates
15
-
16
- :param args: The coordinate of the block(s)
17
- :param sub_chunk_size: The dimension of the chunk (Optional. Default 16)
18
- :return: The resulting chunk coordinates in (x, z) order
19
- """
20
- return tuple(int(math.floor(coord / sub_chunk_size)) for coord in args)
21
-
22
-
23
- def chunk_coords_to_block_coords(
24
- x: int, z: int, chunk_x_size: int = 16, chunk_z_size: int = 16
25
- ) -> ChunkCoordinates:
26
- """
27
- Converts the supplied chunk coordinates into block coordinates
28
-
29
- :param x: The x coordinate of the chunk
30
- :param z: The z coordinate of the chunk
31
- :param chunk_x_size: The dimension of the chunk in the x direction (Optional. Default 16)
32
- :param chunk_z_size: The dimension of the chunk in the z direction (Optional. Default 16)
33
- :return: The resulting block coordinates in (x, z) order
34
- """
35
- return x * chunk_x_size, z * chunk_z_size
36
-
37
-
38
- def chunk_coords_to_region_coords(cx: int, cz: int) -> ChunkCoordinates:
39
- """
40
- Converts the supplied chunk coordinates into region coordinates
41
-
42
- :param cx: The x coordinate of the chunk
43
- :param cz: The z coordinate of the chunk
44
- :return: The resulting region coordinates in (x, z) order
45
- """
46
- return cx >> 5, cz >> 5
47
-
48
-
49
- def region_coords_to_chunk_coords(rx: int, rz: int) -> ChunkCoordinates:
50
- """
51
- Converts the supplied region coordinates into the minimum chunk coordinates of that region
52
-
53
- :param rx: The x coordinate of the region
54
- :param rz: The y coordinate of the region
55
- :return: The resulting minimum chunk coordinates of that region in (x, z) order
56
- """
57
- return rx << 5, rz << 5
58
-
59
-
60
- def blocks_slice_to_chunk_slice(
61
- blocks_slice: slice, chunk_shape: int, chunk_coord: int
62
- ) -> slice:
63
- """
64
- Converts the supplied blocks slice into chunk slice
65
-
66
- :param blocks_slice: The slice of the blocks
67
- :param chunk_shape: The shape of the chunk in this direction
68
- :param chunk_coord: The coordinate of the chunk in this direction
69
- :return: The resulting chunk slice
70
- """
71
- return slice(
72
- min(max(0, blocks_slice.start - chunk_coord * chunk_shape), chunk_shape),
73
- min(max(0, blocks_slice.stop - chunk_coord * chunk_shape), chunk_shape),
74
- )
75
-
76
-
77
- def from_nibble_array(arr: ndarray) -> ndarray:
78
- """
79
- Unpacks a flat nibble array into a full size numpy array
80
-
81
- :param arr: The nibble array
82
- :return: The resulting array
83
- """
84
- shape = arr.size
85
-
86
- new_arr = zeros((shape * 2), dtype=uint8)
87
-
88
- new_arr[::2] = arr & 0xF
89
- new_arr[1::2] = arr >> 4
90
-
91
- return new_arr
92
-
93
-
94
- def to_nibble_array(arr: ndarray) -> ndarray:
95
- """
96
- packs a full size numpy array into a nibble array.
97
-
98
- :param arr: Full numpy array
99
- :return: The nibble array
100
- """
101
- arr = arr.ravel()
102
- return (arr[::2] + (arr[1::2] << 4)).astype(uint8) # type: ignore
amulet/version.cpp DELETED
@@ -1,136 +0,0 @@
1
- #include <stdexcept>
2
- #include <cstdint>
3
- #include <compare>
4
-
5
- #include <amulet/version.hpp>
6
-
7
-
8
- namespace Amulet {
9
- void VersionNumber::serialise(BinaryWriter& writer) const {
10
- writer.writeNumeric<std::uint8_t>(1);
11
- writer.writeNumeric<std::uint64_t>(vec.size());
12
- for (const std::int64_t& v : vec){
13
- writer.writeNumeric<std::int64_t>(v);
14
- }
15
- }
16
- std::shared_ptr<VersionNumber> VersionNumber::deserialise(BinaryReader& reader){
17
- auto version_number = reader.readNumeric<std::uint8_t>();
18
- switch (version_number) {
19
- case 1:
20
- {
21
- std::uint64_t count;
22
- reader.readNumericInto(count);
23
- std::vector<std::int64_t> vec(count);
24
- for (size_t i = 0; i < count; i++) {
25
- reader.readNumericInto<std::int64_t>(vec[i]);
26
- }
27
- return std::make_shared<VersionNumber>(vec);
28
- }
29
- default:
30
- throw std::invalid_argument("Unsupported version " + std::to_string(version_number));
31
- }
32
- }
33
-
34
- std::int64_t VersionNumber::operator[](size_t index) const {
35
- if (index >= vec.size()) {
36
- return 0;
37
- }
38
- return vec[index];
39
- }
40
-
41
- std::string VersionNumber::toString() const {
42
- std::ostringstream oss;
43
- for (size_t i = 0; i < vec.size(); ++i) {
44
- if (i > 0){
45
- oss << '.';
46
- }
47
- oss << vec[i];
48
- }
49
- return oss.str();
50
- }
51
-
52
- std::vector<std::int64_t> VersionNumber::cropped_version() const {
53
- bool found_non_zero = false;
54
- std::vector<std::int64_t> out;
55
- for (auto it = vec.rbegin(); it != vec.rend(); ++it) {
56
- if (found_non_zero){
57
- out.push_back(*it);
58
- } else if (*it != 0) {
59
- found_non_zero = true;
60
- out.push_back(*it);
61
- }
62
- }
63
- std::reverse(out.begin(), out.end());
64
- return out;
65
- }
66
-
67
- std::vector<std::int64_t> VersionNumber::padded_version(size_t len) const {
68
- std::vector<std::int64_t> out(len);
69
- for (size_t i = 0; i < len; i++){
70
- out[i] = (*this)[i];
71
- }
72
- return out;
73
- }
74
-
75
- void PlatformVersionContainer::serialise(BinaryWriter& writer) const {
76
- writer.writeNumeric<std::uint8_t>(1);
77
- writer.writeSizeAndBytes(platform);
78
- version->serialise(writer);
79
- }
80
- std::shared_ptr<PlatformVersionContainer> PlatformVersionContainer::deserialise(BinaryReader& reader){
81
- auto version_number = reader.readNumeric<std::uint8_t>();
82
- switch (version_number) {
83
- case 1:
84
- {
85
- std::string platform = reader.readSizeAndBytes();
86
- auto version = VersionNumber::deserialise(reader);
87
- return std::make_shared<PlatformVersionContainer>(platform, version);
88
- }
89
- default:
90
- throw std::invalid_argument("Unsupported version " + std::to_string(version_number));
91
- }
92
- }
93
-
94
- void VersionRange::serialise(BinaryWriter& writer) const {
95
- writer.writeNumeric<std::uint8_t>(1);
96
- writer.writeSizeAndBytes(platform);
97
- min_version->serialise(writer);
98
- max_version->serialise(writer);
99
- }
100
- std::shared_ptr<VersionRange> VersionRange::deserialise(BinaryReader& reader) {
101
- auto version_number = reader.readNumeric<std::uint8_t>();
102
- switch (version_number) {
103
- case 1:
104
- {
105
- std::string platform = reader.readSizeAndBytes();
106
- auto min_version = VersionNumber::deserialise(reader);
107
- auto max_version = VersionNumber::deserialise(reader);
108
- return std::make_shared<VersionRange>(platform, min_version, max_version);
109
- }
110
- default:
111
- throw std::invalid_argument("Unsupported version " + std::to_string(version_number));
112
- }
113
- }
114
-
115
- bool VersionRange::contains(const PlatformType& platform_, const VersionNumber& version) const {
116
- return platform == platform_ && *min_version <= version && version <= *max_version;
117
- }
118
-
119
- void VersionRangeContainer::serialise(BinaryWriter& writer) const {
120
- writer.writeNumeric<std::uint8_t>(1);
121
- version_range->serialise(writer);
122
- }
123
- std::shared_ptr<VersionRangeContainer> VersionRangeContainer::deserialise(BinaryReader& reader) {
124
- auto version_number = reader.readNumeric<std::uint8_t>();
125
- switch (version_number) {
126
- case 1:
127
- {
128
- return std::make_shared<VersionRangeContainer>(
129
- VersionRange::deserialise(reader)
130
- );
131
- }
132
- default:
133
- throw std::invalid_argument("Unsupported version " + std::to_string(version_number));
134
- }
135
- }
136
- }
amulet/version.hpp DELETED
@@ -1,142 +0,0 @@
1
- #pragma once
2
-
3
- #include <cstdint>
4
- #include <vector>
5
- #include <string>
6
- #include <sstream>
7
- #include <memory>
8
- #include <algorithm>
9
- #include <initializer_list>
10
-
11
- #include <amulet/io/binary_reader.hpp>
12
- #include <amulet/io/binary_writer.hpp>
13
-
14
-
15
- namespace Amulet {
16
- typedef std::string PlatformType;
17
- class VersionNumber {
18
- private:
19
- std::vector<std::int64_t> vec;
20
- public:
21
- const std::vector<std::int64_t>& get_vector() const { return vec; }
22
-
23
- VersionNumber(std::initializer_list<std::int64_t> vec) : vec(vec) {};
24
- VersionNumber(const std::vector<std::int64_t>& vec) : vec(vec) {};
25
-
26
- void serialise(BinaryWriter&) const;
27
- static std::shared_ptr<VersionNumber> deserialise(BinaryReader&);
28
-
29
- std::vector<std::int64_t>::const_iterator begin() const { return vec.begin(); };
30
- std::vector<std::int64_t>::const_iterator end() const { return vec.end(); };
31
- std::vector<std::int64_t>::const_reverse_iterator rbegin() const { return vec.rbegin(); };
32
- std::vector<std::int64_t>::const_reverse_iterator rend() const { return vec.rend(); };
33
- size_t size() const { return vec.size(); };
34
- std::int64_t operator[](size_t index) const;
35
- auto operator<=>(const VersionNumber& other) const {
36
- size_t max_len = std::max(vec.size(), other.size());
37
- std::int64_t v1, v2;
38
- for (size_t i = 0; i < max_len; i++) {
39
- v1 = (*this)[i];
40
- v2 = other[i];
41
- if (v1 < v2) {
42
- // Less than
43
- return std::strong_ordering::less;
44
- }
45
- if (v1 > v2) {
46
- // Greater than
47
- return std::strong_ordering::greater;
48
- }
49
- }
50
- // equal
51
- return std::strong_ordering::equal;
52
- }
53
- bool operator==(const VersionNumber& other) const {
54
- return (*this <=> other) == 0;
55
- };
56
- std::string toString() const;
57
- std::vector<std::int64_t> cropped_version() const;
58
- std::vector<std::int64_t> padded_version(size_t len) const;
59
- };
60
-
61
- class PlatformVersionContainer {
62
- private:
63
- PlatformType platform;
64
- std::shared_ptr<VersionNumber> version;
65
- public:
66
- const PlatformType& get_platform() const { return platform; }
67
- std::shared_ptr<VersionNumber> get_version() const { return version; }
68
-
69
- template <typename versionT>
70
- PlatformVersionContainer(
71
- const PlatformType& platform,
72
- const versionT& version
73
- ) :
74
- platform(platform),
75
- version([&]{
76
- if constexpr (std::is_same_v<versionT, std::shared_ptr<VersionNumber>>){
77
- if (!version) { throw std::runtime_error("Version is nullptr"); }
78
- return version;
79
- }
80
- else {
81
- return std::make_shared<VersionNumber>(version);
82
- }
83
- }())
84
- {};
85
-
86
- void serialise(BinaryWriter&) const;
87
- static std::shared_ptr<PlatformVersionContainer> deserialise(BinaryReader&);
88
-
89
- auto operator<=>(const PlatformVersionContainer& other) const {
90
- auto cmp = platform <=> other.platform;
91
- if (cmp != 0) { return cmp; }
92
- return *version <=> *other.version;
93
- }
94
- bool operator==(const PlatformVersionContainer& other) const {
95
- return (*this <=> other) == 0;
96
- };
97
- };
98
-
99
- class VersionRange {
100
- private:
101
- PlatformType platform;
102
- std::shared_ptr<VersionNumber> min_version;
103
- std::shared_ptr<VersionNumber> max_version;
104
- public:
105
- const PlatformType& get_platform() const { return platform; }
106
- std::shared_ptr<VersionNumber> get_min_version() const { return min_version; }
107
- std::shared_ptr<VersionNumber> get_max_version() const { return max_version; }
108
-
109
- VersionRange(
110
- const PlatformType& platform,
111
- std::shared_ptr<VersionNumber> min_version,
112
- std::shared_ptr<VersionNumber> max_version
113
- ) :
114
- platform(platform),
115
- min_version(min_version),
116
- max_version(max_version)
117
- {
118
- if (*min_version > *max_version) {
119
- throw std::invalid_argument("min_version must be less than or equal to max_version");
120
- }
121
- };
122
-
123
- void serialise(BinaryWriter&) const;
124
- static std::shared_ptr<VersionRange> deserialise(BinaryReader&);
125
-
126
- bool contains(const PlatformType& platform_, const VersionNumber& version) const;
127
- };
128
-
129
- class VersionRangeContainer {
130
- private:
131
- std::shared_ptr<const VersionRange> version_range;
132
- public:
133
- std::shared_ptr<const VersionRange> get_version_range() const { return version_range; }
134
-
135
- VersionRangeContainer(
136
- std::shared_ptr<VersionRange> version_range
137
- ): version_range(version_range) {}
138
-
139
- void serialise(BinaryWriter&) const;
140
- static std::shared_ptr<VersionRangeContainer> deserialise(BinaryReader&);
141
- };
142
- }
amulet/version.py.cpp DELETED
@@ -1,281 +0,0 @@
1
- #include <sstream>
2
-
3
- #include <pybind11/pybind11.h>
4
- #include <pybind11/stl.h>
5
- #include <pybind11/operators.h>
6
-
7
- #include <amulet/collections/eq.py.hpp>
8
- #include <amulet/version.hpp>
9
-
10
- namespace py = pybind11;
11
-
12
- void init_version(py::module m_parent) {
13
- auto m = m_parent.def_submodule("version");
14
- py::options options;
15
-
16
- m.attr("PlatformType") = py::module::import("builtins").attr("str");
17
-
18
- py::class_<Amulet::VersionNumber, std::shared_ptr<Amulet::VersionNumber>> VersionNumber(m, "VersionNumber",
19
- "This class is designed to store semantic versions and data versions and allow comparisons between them.\n"
20
- "\n"
21
- ">>> v1 = VersionNumber(1, 0, 0)\n"
22
- ">>> v2 = VersionNumber(1, 0)\n"
23
- ">>> assert v2 == v1\n"
24
- "\n"
25
- "This class should also be used to store single number data versions.\n"
26
- ">>> v3 = VersionNumber(3578)"
27
- );
28
- options.disable_function_signatures();
29
- VersionNumber.def(
30
- py::init(
31
- [](py::args v){
32
- return std::make_shared<Amulet::VersionNumber>(
33
- v.cast<std::vector<std::int64_t>>()
34
- );
35
- }
36
- ),
37
- py::doc("__init__(self: amulet.version.VersionNumber, *args: typing.SupportsInt) -> None")
38
- );
39
-
40
- // Start collections.abc.Sequence
41
- VersionNumber.def(
42
- "__getitem__",
43
- &Amulet::VersionNumber::operator[],
44
- py::doc(
45
- "__getitem__(*args, **kwargs)\n"
46
- "Overloaded function.\n"
47
- "1. __getitem__(self: amulet.version.VersionNumber, item: typing.SupportsInt) -> int\n"
48
- "2. __getitem__(self: amulet.version.VersionNumber, item: slice) -> list[int]"
49
- )
50
- );
51
- VersionNumber.def(
52
- "__getitem__",
53
- [](const Amulet::VersionNumber& self, const py::slice &slice) -> std::vector<std::int64_t> {
54
- size_t start = 0, stop = 0, step = 0, slicelength = 0;
55
- if (!slice.compute(self.size(), &start, &stop, &step, &slicelength)) {
56
- throw py::error_already_set();
57
- }
58
- std::vector<std::int64_t> out(slicelength);
59
- for (size_t i = 0; i < slicelength; ++i) {
60
- out[i] = self[start];
61
- start += step;
62
- }
63
- return out;
64
- }
65
- );
66
- options.enable_function_signatures();
67
-
68
- VersionNumber.def(
69
- "__repr__",
70
- [](const Amulet::VersionNumber& self){
71
- std::ostringstream oss;
72
- auto& vec = self.get_vector();
73
- oss << "VersionNumber(";
74
- for (size_t i = 0; i < vec.size(); i++){
75
- if (i != 0){
76
- oss << ", ";
77
- }
78
- oss << vec[i];
79
- }
80
- oss << ")";
81
- return oss.str();
82
- }
83
- );
84
- VersionNumber.def(
85
- py::pickle(
86
- [](const Amulet::VersionNumber& self) {
87
- return py::bytes(Amulet::serialise(self));
88
- },
89
- [](py::bytes state){
90
- return Amulet::deserialise<Amulet::VersionNumber>(state.cast<std::string>());
91
- }
92
- )
93
- );
94
-
95
- VersionNumber.def(
96
- "__len__",
97
- &Amulet::VersionNumber::size
98
- );
99
-
100
- VersionNumber.def(
101
- "__contains__",
102
- [](const Amulet::VersionNumber& self, std::int64_t value) {
103
- for (auto it = self.begin(); it != self.end(); it++){
104
- if (*it == value) return true;
105
- }
106
- return false;
107
- }
108
- );
109
-
110
- VersionNumber.def(
111
- "__iter__",
112
- [](const Amulet::VersionNumber& self) {return py::make_iterator(self.begin(), self.end());},
113
- py::keep_alive<0, 1>() /* Essential: keep object alive while iterator exists */
114
- );
115
-
116
- VersionNumber.def(
117
- "__reversed__",
118
- [](const Amulet::VersionNumber& self) {return py::make_iterator(self.rbegin(), self.rend());},
119
- py::keep_alive<0, 1>() /* Essential: keep object alive while iterator exists */
120
- );
121
-
122
- VersionNumber.def(
123
- "index",
124
- [](const Amulet::VersionNumber& self, std::int64_t value, size_t start, size_t stop) {
125
- start = std::min(start, self.size());
126
- stop = std::min(stop, self.size());
127
- for (size_t i = start; i < stop; i++){
128
- if (self[i] == value) return i;
129
- }
130
- throw py::value_error(std::to_string(value) + " is not in VersionNumber.");
131
- },
132
- py::arg("value"), py::arg("start") = 0, py::arg("stop") = std::numeric_limits<size_t>::max()
133
- );
134
-
135
- VersionNumber.def(
136
- "count",
137
- [](const Amulet::VersionNumber& self, std::int64_t value) {
138
- size_t count = 0;
139
- for (size_t i = 0; i < self.size(); i++){
140
- if (self[i] == value) ++count;
141
- }
142
- return count;
143
- },
144
- py::arg("value")
145
- );
146
-
147
- // End collections.abc.Sequence
148
-
149
- VersionNumber.def(
150
- "__str__",
151
- &Amulet::VersionNumber::toString
152
- );
153
-
154
- Eq(VersionNumber);
155
- Eq_default(VersionNumber);
156
- VersionNumber.def(pybind11::self < pybind11::self);
157
- VersionNumber.def(pybind11::self > pybind11::self);
158
- VersionNumber.def(pybind11::self <= pybind11::self);
159
- VersionNumber.def(pybind11::self >= pybind11::self);
160
-
161
- VersionNumber.def(
162
- "cropped_version",
163
- [](const Amulet::VersionNumber& self) -> py::tuple {return py::cast(self.cropped_version());},
164
- py::doc("The version number with trailing zeros cut off.")
165
- );
166
-
167
- VersionNumber.def(
168
- "padded_version",
169
- [](const Amulet::VersionNumber& self, size_t len) -> py::tuple {return py::cast(self.padded_version(len));},
170
- py::doc("Get the version number padded with zeros to the given length."),
171
- py::arg("len")
172
- );
173
-
174
- VersionNumber.def(
175
- "__hash__",
176
- [](const Amulet::VersionNumber& self) {
177
- py::tuple py_tuple = py::cast(self.cropped_version());
178
- return py::hash(py_tuple);
179
- }
180
- );
181
-
182
- py::module::import("collections.abc").attr("Sequence").attr("register")(VersionNumber);
183
-
184
-
185
- py::class_<Amulet::PlatformVersionContainer, std::shared_ptr<Amulet::PlatformVersionContainer>> PlatformVersionContainer(m, "PlatformVersionContainer");
186
- PlatformVersionContainer.def(
187
- py::init<
188
- const Amulet::PlatformType&,
189
- std::shared_ptr<Amulet::VersionNumber>
190
- >(),
191
- py::arg("platform"),
192
- py::arg("version")
193
- );
194
- PlatformVersionContainer.def_property_readonly("platform", &Amulet::PlatformVersionContainer::get_platform);
195
- PlatformVersionContainer.def_property_readonly("version", &Amulet::PlatformVersionContainer::get_version);
196
- PlatformVersionContainer.def(
197
- "__repr__",
198
- [](const Amulet::PlatformVersionContainer& self){
199
- return "PlatformVersionContainer(" +
200
- py::repr(py::cast(self.get_platform())).cast<std::string>() + ", " +
201
- py::repr(py::cast(self.get_version())).cast<std::string>() +
202
- ")";
203
- }
204
- );
205
- PlatformVersionContainer.def(
206
- py::pickle(
207
- [](const Amulet::PlatformVersionContainer& self) -> py::bytes {
208
- return py::bytes(Amulet::serialise(self));
209
- },
210
- [](py::bytes state){
211
- return Amulet::deserialise<Amulet::PlatformVersionContainer>(state.cast<std::string>());
212
- }
213
- )
214
- );
215
-
216
-
217
- py::class_<Amulet::VersionRange, std::shared_ptr<Amulet::VersionRange>> VersionRange(m, "VersionRange");
218
- VersionRange.def(
219
- py::init<
220
- const Amulet::PlatformType&,
221
- std::shared_ptr<Amulet::VersionNumber>,
222
- std::shared_ptr<Amulet::VersionNumber>
223
- >(),
224
- py::arg("platform"),
225
- py::arg("min_version"),
226
- py::arg("max_version")
227
- );
228
- VersionRange.def_property_readonly("platform", &Amulet::VersionRange::get_platform);
229
- VersionRange.def_property_readonly("min_version", &Amulet::VersionRange::get_min_version);
230
- VersionRange.def_property_readonly("max_version", &Amulet::VersionRange::get_max_version);
231
- VersionRange.def(
232
- "contains",
233
- &Amulet::VersionRange::contains
234
- );
235
- VersionRange.def(
236
- "__repr__",
237
- [](const Amulet::VersionRange& self){
238
- return "VersionRange(" +
239
- py::repr(py::cast(self.get_platform())).cast<std::string>() + ", " +
240
- py::repr(py::cast(self.get_min_version())).cast<std::string>() + ", " +
241
- py::repr(py::cast(self.get_max_version())).cast<std::string>() +
242
- ")";
243
- }
244
- );
245
- VersionRange.def(
246
- py::pickle(
247
- [](const Amulet::VersionRange& self) -> py::bytes {
248
- return py::bytes(Amulet::serialise(self));
249
- },
250
- [](py::bytes state){
251
- return Amulet::deserialise<Amulet::VersionRange>(state.cast<std::string>());
252
- }
253
- )
254
- );
255
-
256
-
257
- py::class_<Amulet::VersionRangeContainer, std::shared_ptr<Amulet::VersionRangeContainer>> VersionRangeContainer(m, "VersionRangeContainer");
258
- VersionRangeContainer.def(
259
- py::init<
260
- std::shared_ptr<Amulet::VersionRange>
261
- >(),
262
- py::arg("version_range")
263
- );
264
- VersionRangeContainer.def_property_readonly("version_range", &Amulet::VersionRangeContainer::get_version_range);
265
- VersionRangeContainer.def(
266
- "__repr__",
267
- [](const Amulet::VersionRangeContainer& self){
268
- return "VersionRangeContainer(" + py::repr(py::cast(self.get_version_range())).cast<std::string>() + ")";
269
- }
270
- );
271
- VersionRangeContainer.def(
272
- py::pickle(
273
- [](const Amulet::VersionRangeContainer& self) -> py::bytes {
274
- return py::bytes(Amulet::serialise(self));
275
- },
276
- [](py::bytes state){
277
- return Amulet::deserialise<Amulet::VersionRangeContainer>(state.cast<std::string>());
278
- }
279
- )
280
- );
281
- }