VertexEngine-JSON 1.0.0__tar.gz

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.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Tyrel Miguel Gomez.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,34 @@
1
+ Metadata-Version: 2.4
2
+ Name: VertexEngine-JSON
3
+ Version: 1.0.0
4
+ Summary: JSON Extension of VertexEngine.
5
+ Project-URL: Homepage, https://vertexengine-zii6.onrender.com/
6
+ Project-URL: Documentation, https://vertexenginedocs.netlify.app/
7
+ Project-URL: Repository, https://github.com/VertexEngine-Projects/VertexEngine-JSON
8
+ Keywords: vertexengine,json,serialization,game-engine
9
+ Classifier: Development Status :: 5 - Production/Stable
10
+ Classifier: Intended Audience :: Developers
11
+ Classifier: Topic :: Games/Entertainment
12
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
13
+ Classifier: License :: OSI Approved :: MIT License
14
+ Classifier: Programming Language :: Python :: 3
15
+ Classifier: Programming Language :: Python :: 3.10
16
+ Classifier: Programming Language :: Python :: 3.11
17
+ Classifier: Programming Language :: Python :: 3.12
18
+ Classifier: Programming Language :: Python :: 3.13
19
+ Classifier: Programming Language :: Python :: 3.14
20
+ Classifier: Operating System :: OS Independent
21
+ Requires-Python: >=3.10
22
+ Description-Content-Type: text/markdown
23
+ License-File: LICENSE
24
+ Requires-Dist: VertexEngine>=1.5.0
25
+ Dynamic: license-file
26
+
27
+ # What is This
28
+ This is an extension of VertexEngine that adds JSON tooling to it. It makes game development easier as you can easily make save files. It is also open source like VertexEngine and is created by the same author of VertexEngine.
29
+
30
+ # Dependencies
31
+ All you need is VertexEngine! This is an extension of VertexEngine so you need VertexEngine to use this package.
32
+
33
+ # License
34
+ The license is the MIT License. For more information, read the LICENSE file.
@@ -0,0 +1,8 @@
1
+ # What is This
2
+ This is an extension of VertexEngine that adds JSON tooling to it. It makes game development easier as you can easily make save files. It is also open source like VertexEngine and is created by the same author of VertexEngine.
3
+
4
+ # Dependencies
5
+ All you need is VertexEngine! This is an extension of VertexEngine so you need VertexEngine to use this package.
6
+
7
+ # License
8
+ The license is the MIT License. For more information, read the LICENSE file.
@@ -0,0 +1,33 @@
1
+ [build-system]
2
+ requires = ["setuptools >= 77.0.3"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "VertexEngine-JSON"
7
+ version = "1.0.0"
8
+ description = "JSON Extension of VertexEngine."
9
+ readme = "README.md"
10
+ requires-python = ">=3.10"
11
+ keywords = ["vertexengine", "json", "serialization", "game-engine"]
12
+ classifiers = [
13
+ "Development Status :: 5 - Production/Stable",
14
+ "Intended Audience :: Developers",
15
+ "Topic :: Games/Entertainment",
16
+ "Topic :: Software Development :: Libraries :: Python Modules",
17
+ "License :: OSI Approved :: MIT License",
18
+ "Programming Language :: Python :: 3",
19
+ "Programming Language :: Python :: 3.10",
20
+ "Programming Language :: Python :: 3.11",
21
+ "Programming Language :: Python :: 3.12",
22
+ "Programming Language :: Python :: 3.13",
23
+ "Programming Language :: Python :: 3.14",
24
+ "Operating System :: OS Independent"
25
+ ]
26
+ dependencies = [
27
+ "VertexEngine>=1.5.0"
28
+ ]
29
+
30
+ [project.urls]
31
+ Homepage = "https://vertexengine-zii6.onrender.com/"
32
+ Documentation = "https://vertexenginedocs.netlify.app/"
33
+ Repository = "https://github.com/VertexEngine-Projects/VertexEngine-JSON"
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,21 @@
1
+ from ._operation_data import (
2
+ add_data,
3
+ dict_to_json,
4
+ get_data,
5
+ merge_data,
6
+ mutate_object,
7
+ remove_object,
8
+ split_object,
9
+ swap_data,
10
+ )
11
+
12
+ __all__ = [
13
+ "add_data",
14
+ "dict_to_json",
15
+ "get_data",
16
+ "merge_data",
17
+ "mutate_object",
18
+ "remove_object",
19
+ "split_object",
20
+ "swap_data",
21
+ ]
@@ -0,0 +1,163 @@
1
+ import json
2
+ from copy import deepcopy
3
+ from pathlib import Path
4
+ from typing import Any, Iterable
5
+
6
+ def _load_json(path: str | Path) -> dict[str, Any]:
7
+ file_path = Path(path)
8
+ if not file_path.exists():
9
+ return {}
10
+
11
+ try:
12
+ data = file_path.read_text(encoding="utf-8")
13
+ except OSError:
14
+ return {}
15
+
16
+ if not data.strip():
17
+ return {}
18
+
19
+ parsed = json.loads(data)
20
+ if not isinstance(parsed, dict):
21
+ raise ValueError("JSON root must be an object/dictionary.")
22
+ return parsed
23
+
24
+
25
+ def _save_json(path: str | Path, data: dict[str, Any]) -> dict[str, Any]:
26
+ file_path = Path(path)
27
+ file_path.parent.mkdir(parents=True, exist_ok=True)
28
+ file_path.write_text(json.dumps(data, indent=2, ensure_ascii=False), encoding="utf-8")
29
+ return data
30
+
31
+
32
+ def add_data(file_path: str | Path, data: dict[str, Any]) -> dict[str, Any]:
33
+ if not isinstance(data, dict):
34
+ raise TypeError("data must be a dictionary.")
35
+
36
+ payload = _load_json(file_path)
37
+ payload.update(deepcopy(data))
38
+ return _save_json(file_path, payload)
39
+
40
+
41
+ def get_data(file_path: str | Path, object_name: str, key: str | None = None, default: Any = None) -> Any:
42
+ payload = _load_json(file_path)
43
+ if object_name not in payload:
44
+ return default
45
+
46
+ value = payload[object_name]
47
+ if key is None:
48
+ return value
49
+
50
+ if not isinstance(value, dict):
51
+ return default
52
+
53
+ return value.get(key, default)
54
+
55
+
56
+ def remove_object(file_path: str | Path, object_name: str) -> dict[str, Any]:
57
+ payload = _load_json(file_path)
58
+ payload.pop(object_name, None)
59
+ return _save_json(file_path, payload)
60
+
61
+
62
+ def merge_data(file_path: str | Path, object_name: str, new_data: dict[str, Any]) -> dict[str, Any]:
63
+ if not isinstance(new_data, dict):
64
+ raise TypeError("new_data must be a dictionary.")
65
+
66
+ payload = _load_json(file_path)
67
+ existing = payload.get(object_name)
68
+ if existing is None:
69
+ payload[object_name] = deepcopy(new_data)
70
+ elif isinstance(existing, dict):
71
+ existing.update(deepcopy(new_data))
72
+ else:
73
+ payload[object_name] = deepcopy(new_data)
74
+
75
+ return _save_json(file_path, payload)
76
+
77
+
78
+ def split_object(file_path: str | Path, object_name: str, groups: dict[str, Iterable[str]]) -> dict[str, Any]:
79
+ payload = _load_json(file_path)
80
+ source = payload.get(object_name)
81
+ if source is None:
82
+ raise KeyError(f"Object '{object_name}' does not exist.")
83
+ if not isinstance(source, dict):
84
+ raise TypeError(f"Object '{object_name}' is not a dictionary.")
85
+
86
+ split_payload = {}
87
+ for new_name, keys in groups.items():
88
+ selected = {key: deepcopy(source[key]) for key in keys if key in source}
89
+ split_payload[new_name] = selected
90
+
91
+ payload.pop(object_name, None)
92
+ payload.update(split_payload)
93
+ return _save_json(file_path, payload)
94
+
95
+
96
+ def mutate_object(
97
+ file_path: str | Path,
98
+ object_name: str,
99
+ changes: dict[str, Any],
100
+ *,
101
+ new_name: str | None = None,
102
+ ) -> dict[str, Any]:
103
+ if not isinstance(changes, dict):
104
+ raise TypeError("changes must be a dictionary.")
105
+
106
+ payload = _load_json(file_path)
107
+ source = payload.get(object_name)
108
+ if source is None:
109
+ raise KeyError(f"Object '{object_name}' does not exist.")
110
+ if not isinstance(source, dict):
111
+ raise TypeError(f"Object '{object_name}' is not a dictionary.")
112
+
113
+ mutated = deepcopy(source)
114
+ mutated.update(deepcopy(changes))
115
+
116
+ target_name = new_name or f"{object_name}_copy"
117
+ payload[target_name] = mutated
118
+ return _save_json(file_path, payload)
119
+
120
+
121
+ def swap_data(file_path: str | Path, first_object: str, second_object: str, key: str) -> dict[str, Any]:
122
+ payload = _load_json(file_path)
123
+ first = payload.get(first_object)
124
+ second = payload.get(second_object)
125
+
126
+ if not isinstance(first, dict) or not isinstance(second, dict):
127
+ raise TypeError("Both objects must be dictionaries.")
128
+ if key not in first or key not in second:
129
+ return payload
130
+
131
+ first[key], second[key] = second[key], first[key]
132
+ return _save_json(file_path, payload)
133
+
134
+
135
+ def dict_to_json(file_path: str | Path, data: dict[str, Any]) -> str:
136
+ """
137
+ Converts a dictionary to JSON and saves it to a file.
138
+
139
+ Args:
140
+ file_path: Path where the JSON file will be saved
141
+ data: Dictionary to convert and save
142
+
143
+ Returns:
144
+ The JSON string representation of the data
145
+ """
146
+ if not isinstance(data, dict):
147
+ raise TypeError("data must be a dictionary.")
148
+
149
+ _save_json(file_path, data)
150
+ json_string = json.dumps(data, indent=2, ensure_ascii=False)
151
+ return json_string
152
+
153
+
154
+ __all__ = [
155
+ "add_data",
156
+ "get_data",
157
+ "remove_object",
158
+ "merge_data",
159
+ "split_object",
160
+ "mutate_object",
161
+ "swap_data",
162
+ "dict_to_json",
163
+ ]
@@ -0,0 +1,107 @@
1
+ import json
2
+ from copy import deepcopy
3
+ from pathlib import Path
4
+ from typing import Any, Iterable
5
+
6
+
7
+ def _load_json(path: str | Path) -> dict[str, Any]:
8
+ """Load JSON from a file, returning an empty dict if file doesn't exist or is empty."""
9
+ file_path = Path(path)
10
+ if not file_path.exists():
11
+ return {}
12
+
13
+ try:
14
+ data = file_path.read_text(encoding="utf-8")
15
+ except OSError:
16
+ return {}
17
+
18
+ if not data.strip():
19
+ return {}
20
+
21
+ parsed = json.loads(data)
22
+ if not isinstance(parsed, dict):
23
+ raise ValueError("JSON root must be an object/dictionary.")
24
+ return parsed
25
+
26
+
27
+ def _save_json(path: str | Path, data: dict[str, Any]) -> dict[str, Any]:
28
+ """Save JSON data to a file, creating parent directories as needed."""
29
+ file_path = Path(path)
30
+ file_path.parent.mkdir(parents=True, exist_ok=True)
31
+ file_path.write_text(json.dumps(data, indent=2, ensure_ascii=False), encoding="utf-8")
32
+ return data
33
+
34
+
35
+ def merge_file(files: Iterable[str | Path], output_path: str | Path) -> dict[str, Any]:
36
+ """
37
+ Merges multiple JSON files into a single file.
38
+
39
+ Args:
40
+ files: Iterable of file paths to merge
41
+ output_path: Path where the merged result will be saved
42
+
43
+ Returns:
44
+ The merged dictionary
45
+ """
46
+ merged: dict[str, Any] = {}
47
+
48
+ for file_path in files:
49
+ data = _load_json(file_path)
50
+ merged.update(deepcopy(data))
51
+
52
+ return _save_json(output_path, merged)
53
+
54
+
55
+ def folder_to_file(folder: str | Path, output_path: str | Path, *, extension: str = "*.json") -> dict[str, Any]:
56
+ """
57
+ Merges all JSON files in a folder into a single file.
58
+
59
+ Args:
60
+ folder: Path to the folder containing JSON files
61
+ output_path: Path where the merged result will be saved
62
+ extension: File pattern to match (default: "*.json")
63
+
64
+ Returns:
65
+ The merged dictionary
66
+ """
67
+ folder_path = Path(folder)
68
+ if not folder_path.is_dir():
69
+ raise ValueError(f"Folder '{folder_path}' does not exist or is not a directory.")
70
+
71
+ json_files = sorted(folder_path.glob(extension))
72
+ return merge_file(json_files, output_path)
73
+
74
+
75
+ def add_data(file_path: str | Path, object_names: Iterable[str], data: dict[str, Any]) -> dict[str, Any]:
76
+ """
77
+ Adds data to a set of JSON objects in a specific JSON file.
78
+
79
+ Args:
80
+ file_path: Path to the JSON file
81
+ object_names: Iterable of object names to add data to
82
+ data: Dictionary of data to add to each object
83
+
84
+ Returns:
85
+ The updated payload
86
+ """
87
+ if not isinstance(data, dict):
88
+ raise TypeError("data must be a dictionary.")
89
+
90
+ payload = _load_json(file_path)
91
+ data_copy = deepcopy(data)
92
+
93
+ for object_name in object_names:
94
+ if object_name not in payload:
95
+ payload[object_name] = {}
96
+
97
+ if isinstance(payload[object_name], dict):
98
+ payload[object_name].update(data_copy)
99
+
100
+ return _save_json(file_path, payload)
101
+
102
+
103
+ __all__ = [
104
+ "merge_file",
105
+ "folder_to_file",
106
+ "add_data",
107
+ ]
@@ -0,0 +1,34 @@
1
+ Metadata-Version: 2.4
2
+ Name: VertexEngine-JSON
3
+ Version: 1.0.0
4
+ Summary: JSON Extension of VertexEngine.
5
+ Project-URL: Homepage, https://vertexengine-zii6.onrender.com/
6
+ Project-URL: Documentation, https://vertexenginedocs.netlify.app/
7
+ Project-URL: Repository, https://github.com/VertexEngine-Projects/VertexEngine-JSON
8
+ Keywords: vertexengine,json,serialization,game-engine
9
+ Classifier: Development Status :: 5 - Production/Stable
10
+ Classifier: Intended Audience :: Developers
11
+ Classifier: Topic :: Games/Entertainment
12
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
13
+ Classifier: License :: OSI Approved :: MIT License
14
+ Classifier: Programming Language :: Python :: 3
15
+ Classifier: Programming Language :: Python :: 3.10
16
+ Classifier: Programming Language :: Python :: 3.11
17
+ Classifier: Programming Language :: Python :: 3.12
18
+ Classifier: Programming Language :: Python :: 3.13
19
+ Classifier: Programming Language :: Python :: 3.14
20
+ Classifier: Operating System :: OS Independent
21
+ Requires-Python: >=3.10
22
+ Description-Content-Type: text/markdown
23
+ License-File: LICENSE
24
+ Requires-Dist: VertexEngine>=1.5.0
25
+ Dynamic: license-file
26
+
27
+ # What is This
28
+ This is an extension of VertexEngine that adds JSON tooling to it. It makes game development easier as you can easily make save files. It is also open source like VertexEngine and is created by the same author of VertexEngine.
29
+
30
+ # Dependencies
31
+ All you need is VertexEngine! This is an extension of VertexEngine so you need VertexEngine to use this package.
32
+
33
+ # License
34
+ The license is the MIT License. For more information, read the LICENSE file.
@@ -0,0 +1,12 @@
1
+ LICENSE
2
+ README.md
3
+ pyproject.toml
4
+ src/VertexEngine/json/__init__.py
5
+ src/VertexEngine/json/_operation_data.py
6
+ src/VertexEngine/json_files/__init__.py
7
+ src/VertexEngine/json_files/_operation_data.py
8
+ src/VertexEngine_JSON.egg-info/PKG-INFO
9
+ src/VertexEngine_JSON.egg-info/SOURCES.txt
10
+ src/VertexEngine_JSON.egg-info/dependency_links.txt
11
+ src/VertexEngine_JSON.egg-info/requires.txt
12
+ src/VertexEngine_JSON.egg-info/top_level.txt
@@ -0,0 +1 @@
1
+ VertexEngine>=1.5.0