sm-blueprint-lib 0.0.1__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.
- sm_blueprint_lib-0.0.1/.gitattributes +2 -0
- sm_blueprint_lib-0.0.1/.gitignore +160 -0
- sm_blueprint_lib-0.0.1/LICENSE +21 -0
- sm_blueprint_lib-0.0.1/PKG-INFO +16 -0
- sm_blueprint_lib-0.0.1/README.md +2 -0
- sm_blueprint_lib-0.0.1/pyproject.toml +23 -0
- sm_blueprint_lib-0.0.1/src/sm_blueprint_lib/__init__.py +138 -0
- sm_blueprint_lib-0.0.1/src/sm_blueprint_lib/bases/controllers/basecontroller.py +20 -0
- sm_blueprint_lib-0.0.1/src/sm_blueprint_lib/bases/controllers/baselogiccontroller.py +10 -0
- sm_blueprint_lib-0.0.1/src/sm_blueprint_lib/bases/controllers/logicgatecontroller.py +10 -0
- sm_blueprint_lib-0.0.1/src/sm_blueprint_lib/bases/controllers/sensorcontroller.py +24 -0
- sm_blueprint_lib-0.0.1/src/sm_blueprint_lib/bases/controllers/timercontroller.py +11 -0
- sm_blueprint_lib-0.0.1/src/sm_blueprint_lib/blueprint.py +31 -0
- sm_blueprint_lib-0.0.1/src/sm_blueprint_lib/body.py +13 -0
- sm_blueprint_lib-0.0.1/src/sm_blueprint_lib/bounds.py +10 -0
- sm_blueprint_lib-0.0.1/src/sm_blueprint_lib/constants.py +29 -0
- sm_blueprint_lib-0.0.1/src/sm_blueprint_lib/id.py +5 -0
- sm_blueprint_lib-0.0.1/src/sm_blueprint_lib/pos.py +16 -0
- sm_blueprint_lib-0.0.1/src/sm_blueprint_lib/prebuilds/adder.py +44 -0
- sm_blueprint_lib-0.0.1/src/sm_blueprint_lib/prebuilds/barrel_shifter.py +86 -0
- sm_blueprint_lib-0.0.1/src/sm_blueprint_lib/prebuilds/clock40hz.py +28 -0
- sm_blueprint_lib-0.0.1/src/sm_blueprint_lib/prebuilds/comparator.py +70 -0
- sm_blueprint_lib-0.0.1/src/sm_blueprint_lib/prebuilds/counter.py +68 -0
- sm_blueprint_lib-0.0.1/src/sm_blueprint_lib/prebuilds/decoder.py +56 -0
- sm_blueprint_lib-0.0.1/src/sm_blueprint_lib/prebuilds/distance_sensor.py +45 -0
- sm_blueprint_lib-0.0.1/src/sm_blueprint_lib/prebuilds/ram.py +90 -0
- sm_blueprint_lib-0.0.1/src/sm_blueprint_lib/prebuilds/register.py +72 -0
- sm_blueprint_lib-0.0.1/src/sm_blueprint_lib/prebuilds/rom.py +76 -0
- sm_blueprint_lib-0.0.1/src/sm_blueprint_lib/prebuilds/timer_ram_cached.py +386 -0
- sm_blueprint_lib-0.0.1/src/sm_blueprint_lib/prebuilds/timer_ram_multiclient.py +85 -0
- sm_blueprint_lib-0.0.1/test_connections.py +65 -0
- sm_blueprint_lib-0.0.1/test_prebuilds.py +89 -0
- sm_blueprint_lib-0.0.1/tests.py +122 -0
@@ -0,0 +1,160 @@
|
|
1
|
+
# Byte-compiled / optimized / DLL files
|
2
|
+
__pycache__/
|
3
|
+
*.py[cod]
|
4
|
+
*$py.class
|
5
|
+
|
6
|
+
# C extensions
|
7
|
+
*.so
|
8
|
+
|
9
|
+
# Distribution / packaging
|
10
|
+
.Python
|
11
|
+
build/
|
12
|
+
develop-eggs/
|
13
|
+
dist/
|
14
|
+
downloads/
|
15
|
+
eggs/
|
16
|
+
.eggs/
|
17
|
+
lib/
|
18
|
+
lib64/
|
19
|
+
parts/
|
20
|
+
sdist/
|
21
|
+
var/
|
22
|
+
wheels/
|
23
|
+
share/python-wheels/
|
24
|
+
*.egg-info/
|
25
|
+
.installed.cfg
|
26
|
+
*.egg
|
27
|
+
MANIFEST
|
28
|
+
|
29
|
+
# PyInstaller
|
30
|
+
# Usually these files are written by a python script from a template
|
31
|
+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
32
|
+
*.manifest
|
33
|
+
*.spec
|
34
|
+
|
35
|
+
# Installer logs
|
36
|
+
pip-log.txt
|
37
|
+
pip-delete-this-directory.txt
|
38
|
+
|
39
|
+
# Unit test / coverage reports
|
40
|
+
htmlcov/
|
41
|
+
.tox/
|
42
|
+
.nox/
|
43
|
+
.coverage
|
44
|
+
.coverage.*
|
45
|
+
.cache
|
46
|
+
nosetests.xml
|
47
|
+
coverage.xml
|
48
|
+
*.cover
|
49
|
+
*.py,cover
|
50
|
+
.hypothesis/
|
51
|
+
.pytest_cache/
|
52
|
+
cover/
|
53
|
+
|
54
|
+
# Translations
|
55
|
+
*.mo
|
56
|
+
*.pot
|
57
|
+
|
58
|
+
# Django stuff:
|
59
|
+
*.log
|
60
|
+
local_settings.py
|
61
|
+
db.sqlite3
|
62
|
+
db.sqlite3-journal
|
63
|
+
|
64
|
+
# Flask stuff:
|
65
|
+
instance/
|
66
|
+
.webassets-cache
|
67
|
+
|
68
|
+
# Scrapy stuff:
|
69
|
+
.scrapy
|
70
|
+
|
71
|
+
# Sphinx documentation
|
72
|
+
docs/_build/
|
73
|
+
|
74
|
+
# PyBuilder
|
75
|
+
.pybuilder/
|
76
|
+
target/
|
77
|
+
|
78
|
+
# Jupyter Notebook
|
79
|
+
.ipynb_checkpoints
|
80
|
+
|
81
|
+
# IPython
|
82
|
+
profile_default/
|
83
|
+
ipython_config.py
|
84
|
+
|
85
|
+
# pyenv
|
86
|
+
# For a library or package, you might want to ignore these files since the code is
|
87
|
+
# intended to run in multiple environments; otherwise, check them in:
|
88
|
+
# .python-version
|
89
|
+
|
90
|
+
# pipenv
|
91
|
+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
|
92
|
+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
|
93
|
+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
|
94
|
+
# install all needed dependencies.
|
95
|
+
#Pipfile.lock
|
96
|
+
|
97
|
+
# poetry
|
98
|
+
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
|
99
|
+
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
100
|
+
# commonly ignored for libraries.
|
101
|
+
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
|
102
|
+
#poetry.lock
|
103
|
+
|
104
|
+
# pdm
|
105
|
+
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
|
106
|
+
#pdm.lock
|
107
|
+
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
|
108
|
+
# in version control.
|
109
|
+
# https://pdm.fming.dev/#use-with-ide
|
110
|
+
.pdm.toml
|
111
|
+
|
112
|
+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
|
113
|
+
__pypackages__/
|
114
|
+
|
115
|
+
# Celery stuff
|
116
|
+
celerybeat-schedule
|
117
|
+
celerybeat.pid
|
118
|
+
|
119
|
+
# SageMath parsed files
|
120
|
+
*.sage.py
|
121
|
+
|
122
|
+
# Environments
|
123
|
+
.env
|
124
|
+
.venv
|
125
|
+
env/
|
126
|
+
venv/
|
127
|
+
ENV/
|
128
|
+
env.bak/
|
129
|
+
venv.bak/
|
130
|
+
|
131
|
+
# Spyder project settings
|
132
|
+
.spyderproject
|
133
|
+
.spyproject
|
134
|
+
|
135
|
+
# Rope project settings
|
136
|
+
.ropeproject
|
137
|
+
|
138
|
+
# mkdocs documentation
|
139
|
+
/site
|
140
|
+
|
141
|
+
# mypy
|
142
|
+
.mypy_cache/
|
143
|
+
.dmypy.json
|
144
|
+
dmypy.json
|
145
|
+
|
146
|
+
# Pyre type checker
|
147
|
+
.pyre/
|
148
|
+
|
149
|
+
# pytype static type analyzer
|
150
|
+
.pytype/
|
151
|
+
|
152
|
+
# Cython debug symbols
|
153
|
+
cython_debug/
|
154
|
+
|
155
|
+
# PyCharm
|
156
|
+
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
|
157
|
+
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
|
158
|
+
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
159
|
+
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
160
|
+
#.idea/
|
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2025 Maurice
|
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,16 @@
|
|
1
|
+
Metadata-Version: 2.4
|
2
|
+
Name: sm_blueprint_lib
|
3
|
+
Version: 0.0.1
|
4
|
+
Summary: Scrap Mechanic Library for Blueprint manipulation.
|
5
|
+
Project-URL: Homepage, https://github.com/pypa/sampleproject
|
6
|
+
Project-URL: Issues, https://github.com/pypa/sampleproject/issues
|
7
|
+
Author-email: Maurice <mauriciotorrez00@gmail.com>
|
8
|
+
License-Expression: MIT
|
9
|
+
License-File: LICENSE
|
10
|
+
Classifier: Operating System :: OS Independent
|
11
|
+
Classifier: Programming Language :: Python :: 3
|
12
|
+
Requires-Python: >=3.8
|
13
|
+
Description-Content-Type: text/markdown
|
14
|
+
|
15
|
+
# sm_blueprint_lib
|
16
|
+
Scrap Mechanic Library for Blueprint manipulation.
|
@@ -0,0 +1,23 @@
|
|
1
|
+
[build-system]
|
2
|
+
requires = ["hatchling"]
|
3
|
+
build-backend = "hatchling.build"
|
4
|
+
|
5
|
+
[project]
|
6
|
+
name = "sm_blueprint_lib"
|
7
|
+
version = "0.0.1"
|
8
|
+
authors = [
|
9
|
+
{ name="Maurice", email="mauriciotorrez00@gmail.com" },
|
10
|
+
]
|
11
|
+
description = "Scrap Mechanic Library for Blueprint manipulation."
|
12
|
+
readme = "README.md"
|
13
|
+
requires-python = ">=3.8"
|
14
|
+
classifiers = [
|
15
|
+
"Programming Language :: Python :: 3",
|
16
|
+
"Operating System :: OS Independent",
|
17
|
+
]
|
18
|
+
license = "MIT"
|
19
|
+
license-files = ["LICEN[CS]E*"]
|
20
|
+
|
21
|
+
[project.urls]
|
22
|
+
Homepage = "https://github.com/pypa/sampleproject"
|
23
|
+
Issues = "https://github.com/pypa/sampleproject/issues"
|
@@ -0,0 +1,138 @@
|
|
1
|
+
from dataclasses import asdict
|
2
|
+
from json import load, dump, loads, dumps
|
3
|
+
from math import ceil, log2
|
4
|
+
|
5
|
+
from numpy import ndarray
|
6
|
+
|
7
|
+
from sm_blueprint_lib.bases.parts.baseinteractablepart import BaseInteractablePart
|
8
|
+
from sm_blueprint_lib.blueprint import Blueprint
|
9
|
+
from sm_blueprint_lib.parts.barrierblock import BarrierBlock
|
10
|
+
from sm_blueprint_lib.parts.logicgate import LogicGate
|
11
|
+
from sm_blueprint_lib.parts.timer import Timer
|
12
|
+
from sm_blueprint_lib.pos import Pos
|
13
|
+
|
14
|
+
|
15
|
+
def load_blueprint(path):
|
16
|
+
"""Load a blueprint from a path file (normally a blueprint.json).
|
17
|
+
|
18
|
+
Args:
|
19
|
+
path (str): The path to the json file.
|
20
|
+
|
21
|
+
Returns:
|
22
|
+
Blueprint: The loaded blueprint.
|
23
|
+
"""
|
24
|
+
with open(path) as fp:
|
25
|
+
return Blueprint(**load(fp))
|
26
|
+
|
27
|
+
|
28
|
+
def save_blueprint(path, bp: Blueprint):
|
29
|
+
"""Save a blueprint to a file (normally a blueprint.json).
|
30
|
+
|
31
|
+
Args:
|
32
|
+
path (str): The path to save the json file.
|
33
|
+
bp (Blueprint): The blueprint to be saved.
|
34
|
+
"""
|
35
|
+
with open(path, mode="w") as fp:
|
36
|
+
return dump(asdict(bp), fp, sort_keys=True, separators=(',', ':'))
|
37
|
+
|
38
|
+
|
39
|
+
def load_string(str):
|
40
|
+
"""Load a blueprint from a json string.
|
41
|
+
|
42
|
+
Args:
|
43
|
+
str (str): The string to be loaded.
|
44
|
+
|
45
|
+
Returns:
|
46
|
+
Blueprint: The loaded blueprint.
|
47
|
+
"""
|
48
|
+
return Blueprint(**loads(str))
|
49
|
+
|
50
|
+
|
51
|
+
def dump_string(bp: Blueprint):
|
52
|
+
"""Dump a blueprint into a json-formatted string.
|
53
|
+
|
54
|
+
Args:
|
55
|
+
bp (Blueprint): The blueprint to be dumped.
|
56
|
+
|
57
|
+
Returns:
|
58
|
+
str: The json-formatted string.
|
59
|
+
"""
|
60
|
+
return dumps(asdict(bp), sort_keys=True, separators=(',', ':'))
|
61
|
+
|
62
|
+
|
63
|
+
def connect(_from, _to, *, parallel=True):
|
64
|
+
"""Connect interactable parts together, recursively.
|
65
|
+
|
66
|
+
Args:
|
67
|
+
_from (Any): Must be an instance of BaseInteractablePart or a subclass.
|
68
|
+
Also it can be any nested iterable of instances (list of parts, list of lists of parts, etc).
|
69
|
+
_to (Any): Must be an instance of BaseInteractablePart or a subclass.
|
70
|
+
Also it can be any nested iterable of instances (list of parts, list of lists of parts, etc).
|
71
|
+
parallel (bool, optional): Defines the behaviour of the connections in the following way:
|
72
|
+
|
73
|
+
With parallel=False, everything connects to everything:
|
74
|
+
from1 🔀 to1
|
75
|
+
|
76
|
+
from2 🔀 to2
|
77
|
+
|
78
|
+
With parallel=True, every row is connected respectively:
|
79
|
+
from1 → to1
|
80
|
+
|
81
|
+
from2 → to2
|
82
|
+
|
83
|
+
Also, if the dimensions does not match it tries to adapt (many to one, one to many, etc)
|
84
|
+
|
85
|
+
Defaults to True.
|
86
|
+
"""
|
87
|
+
if isinstance(_from, BaseInteractablePart) and isinstance(_to, BaseInteractablePart):
|
88
|
+
_from.connect(_to)
|
89
|
+
return
|
90
|
+
if parallel: # Try connect things row-by-row if possible (one to one, one to many, many to many)
|
91
|
+
if not isinstance(_from, BaseInteractablePart) and not isinstance(_to, BaseInteractablePart): # Assume both are sequence of parts
|
92
|
+
for subfrom, subto in zip(_from, _to):
|
93
|
+
connect(subfrom, subto, parallel=parallel)
|
94
|
+
elif not isinstance(_from, BaseInteractablePart): # Assume _from is a sequence of parts
|
95
|
+
for subfrom in _from:
|
96
|
+
connect(subfrom, _to, parallel=parallel)
|
97
|
+
else: # Assume _to is a sequence of parts
|
98
|
+
for subto in _to:
|
99
|
+
connect(_from, subto, parallel=parallel)
|
100
|
+
else: # Just connect everything to everything lol
|
101
|
+
if not isinstance(_from, BaseInteractablePart) and not isinstance(_to, BaseInteractablePart): # Assume both are sequence of parts
|
102
|
+
for subfrom in _from:
|
103
|
+
for subto in _to:
|
104
|
+
connect(subfrom, subto, parallel=parallel)
|
105
|
+
elif not isinstance(_from, BaseInteractablePart): # Assume _from is a sequence of parts
|
106
|
+
for subfrom in _from:
|
107
|
+
connect(subfrom, _to, parallel=parallel)
|
108
|
+
else: # Assume _to is a sequence of parts
|
109
|
+
for subto in _to:
|
110
|
+
connect(_from, subto, parallel=parallel)
|
111
|
+
|
112
|
+
|
113
|
+
def check_pos(pos):
|
114
|
+
if not isinstance(pos, Pos):
|
115
|
+
pos = Pos(*pos)
|
116
|
+
return pos
|
117
|
+
|
118
|
+
|
119
|
+
def get_bits_required(number: int | float):
|
120
|
+
"""Calculates how many bits are required to store this number.
|
121
|
+
|
122
|
+
Args:
|
123
|
+
number (int | float): The target number.
|
124
|
+
"""
|
125
|
+
return ceil(log2(number))
|
126
|
+
|
127
|
+
|
128
|
+
def num_to_bit_list(number: int, bit_length: int):
|
129
|
+
"""Converts a number to a numpy array of its bits.
|
130
|
+
|
131
|
+
Args:
|
132
|
+
number (int): The number to convert.
|
133
|
+
bit_length (int): The number of bits the list will have.
|
134
|
+
"""
|
135
|
+
output = ndarray(bit_length, dtype=bool)
|
136
|
+
for b in range(bit_length):
|
137
|
+
output[b] = bool((number >> b) & 1)
|
138
|
+
return output
|
@@ -0,0 +1,20 @@
|
|
1
|
+
from dataclasses import dataclass, field
|
2
|
+
from typing import Any, Optional
|
3
|
+
|
4
|
+
from sm_blueprint_lib.constants import get_new_id
|
5
|
+
from sm_blueprint_lib.id import ID
|
6
|
+
|
7
|
+
|
8
|
+
@dataclass
|
9
|
+
class BaseController:
|
10
|
+
"""Base class for controller objects (used in interactable parts and so)
|
11
|
+
"""
|
12
|
+
controllers: Optional[list[ID]] = field(kw_only=True, default=None)
|
13
|
+
id: int = field(kw_only=True, default_factory=get_new_id)
|
14
|
+
joints: Optional[list[ID]] = field(kw_only=True, default=None)
|
15
|
+
|
16
|
+
def __post_init__(self):
|
17
|
+
try:
|
18
|
+
self.controllers = [ID(**c) for c in self.controllers]
|
19
|
+
except TypeError:
|
20
|
+
pass
|
@@ -0,0 +1,10 @@
|
|
1
|
+
from dataclasses import dataclass, field
|
2
|
+
|
3
|
+
from sm_blueprint_lib.bases.controllers.basecontroller import BaseController
|
4
|
+
|
5
|
+
|
6
|
+
@dataclass
|
7
|
+
class BaseLogicController(BaseController):
|
8
|
+
"""Base class for Logic parts' Controllers (mostly Logic Gate and Timer)
|
9
|
+
"""
|
10
|
+
active: bool = field(kw_only=True, default=False)
|
@@ -0,0 +1,24 @@
|
|
1
|
+
from dataclasses import dataclass, field
|
2
|
+
|
3
|
+
from sm_blueprint_lib.bases.controllers.basecontroller import BaseController
|
4
|
+
|
5
|
+
|
6
|
+
@dataclass
|
7
|
+
class SensorController(BaseController):
|
8
|
+
"""Sensor's Controller
|
9
|
+
"""
|
10
|
+
audioEnable: bool
|
11
|
+
buttonMode: bool
|
12
|
+
color: str
|
13
|
+
colorMode: bool
|
14
|
+
range: int
|
15
|
+
|
16
|
+
def __post_init__(self):
|
17
|
+
super().__post_init__()
|
18
|
+
# if color given as (r, g, b) then convert to hex string
|
19
|
+
if not isinstance(self.color, str):
|
20
|
+
self.color = "%02X%02X%02X" % (
|
21
|
+
self.color[0], self.color[1], self.color[2])
|
22
|
+
self.audioEnable = bool(self.audioEnable)
|
23
|
+
self.buttonMode = bool(self.buttonMode)
|
24
|
+
self.colorMode = bool(self.colorMode)
|
@@ -0,0 +1,31 @@
|
|
1
|
+
from dataclasses import dataclass, field
|
2
|
+
|
3
|
+
from sm_blueprint_lib.bases.parts.basepart import BasePart
|
4
|
+
from sm_blueprint_lib.body import Body
|
5
|
+
from sm_blueprint_lib.constants import VERSION
|
6
|
+
|
7
|
+
|
8
|
+
@dataclass
|
9
|
+
class Blueprint:
|
10
|
+
bodies: list[Body] = field(default_factory=lambda: [Body()])
|
11
|
+
version: int = VERSION.BLUEPRINT_VERSION
|
12
|
+
|
13
|
+
def __post_init__(self):
|
14
|
+
try:
|
15
|
+
self.bodies = [Body(**body) for body in self.bodies]
|
16
|
+
except TypeError:
|
17
|
+
pass
|
18
|
+
|
19
|
+
def add(self, *obj, body=0):
|
20
|
+
"""Adds the object(s) to the blueprint.
|
21
|
+
|
22
|
+
Args:
|
23
|
+
obj (Any): Can be a instance of BasePart or a subclass. It also can be any nested iterable of instances (list of parts, list of lists of parts, etc).
|
24
|
+
body (int, optional): Specify in which blueprint's body the object will be placed. Defaults to 0.
|
25
|
+
"""
|
26
|
+
for subobj in obj:
|
27
|
+
if isinstance(subobj, BasePart):
|
28
|
+
self.bodies[body].childs.append(subobj)
|
29
|
+
else:
|
30
|
+
for subsubobj in subobj:
|
31
|
+
self.add(subsubobj, body=body)
|
@@ -0,0 +1,13 @@
|
|
1
|
+
from dataclasses import dataclass, field
|
2
|
+
|
3
|
+
from sm_blueprint_lib.bases.parts.basepart import BasePart
|
4
|
+
from sm_blueprint_lib.constants import SHAPEID
|
5
|
+
|
6
|
+
|
7
|
+
@dataclass
|
8
|
+
class Body:
|
9
|
+
childs: list[BasePart] = field(default_factory=list)
|
10
|
+
|
11
|
+
def __post_init__(self):
|
12
|
+
self.childs = [SHAPEID.SHAPEID_TO_CLASS[child["shapeId"]](**child)
|
13
|
+
for child in self.childs]
|
@@ -0,0 +1,29 @@
|
|
1
|
+
class SHAPEID:
|
2
|
+
BARRIER_BLOCK = "09ca2713-28ee-4119-9622-e85490034758"
|
3
|
+
LOGIC_GATE = "9f0f56e8-2c31-4d83-996c-d00a9b296c3f"
|
4
|
+
TIMER = "8f7fd0e7-c46e-4944-a414-7ce2437bb30f"
|
5
|
+
SENSOR5 = "20dcd41c-0a11-4668-9b00-97f278ce21af"
|
6
|
+
SWITCH = "7cf717d7-d167-4f2d-a6e7-6b2c70aa3986"
|
7
|
+
SHAPEID_TO_CLASS = {}
|
8
|
+
|
9
|
+
|
10
|
+
class AXIS:
|
11
|
+
DEFAULT_XAXIS = 1
|
12
|
+
DEFAULT_ZAXIS = 3
|
13
|
+
|
14
|
+
|
15
|
+
class VERSION:
|
16
|
+
BLUEPRINT_VERSION = 4
|
17
|
+
|
18
|
+
|
19
|
+
TICKS_PER_SECOND = 40
|
20
|
+
|
21
|
+
__global_id_counter = 0
|
22
|
+
"""Atempting to modify this global variable may cause to break your blueprints lol.
|
23
|
+
"""
|
24
|
+
|
25
|
+
|
26
|
+
def get_new_id():
|
27
|
+
global __global_id_counter
|
28
|
+
__global_id_counter = (new_id := __global_id_counter) + 1
|
29
|
+
return new_id
|
@@ -0,0 +1,16 @@
|
|
1
|
+
from dataclasses import dataclass
|
2
|
+
from typing import Sequence
|
3
|
+
|
4
|
+
|
5
|
+
@dataclass
|
6
|
+
class Pos:
|
7
|
+
"""Class that represents the position of a block (x, y, z)
|
8
|
+
"""
|
9
|
+
x: int
|
10
|
+
y: int
|
11
|
+
z: int
|
12
|
+
|
13
|
+
def __add__(self, o: "Pos" | Sequence):
|
14
|
+
if isinstance(o, Pos):
|
15
|
+
return Pos(self.x + o.x, self.y + o.y, self.z + o.z)
|
16
|
+
return Pos(self.x + o[0], self.y + o[1], self.z + o[2])
|
@@ -0,0 +1,44 @@
|
|
1
|
+
from typing import Sequence
|
2
|
+
from numpy import ndarray
|
3
|
+
from sm_blueprint_lib import get_bits_required, check_pos, connect, num_to_bit_list
|
4
|
+
from sm_blueprint_lib.blueprint import Blueprint
|
5
|
+
from sm_blueprint_lib.parts.logicgate import LogicGate
|
6
|
+
from sm_blueprint_lib.pos import Pos
|
7
|
+
|
8
|
+
|
9
|
+
def simple_adder_subtractor(bp: Blueprint,
|
10
|
+
bit_length: int,
|
11
|
+
pos: Pos | Sequence = (0, 0, 0)):
|
12
|
+
pos = check_pos(pos)
|
13
|
+
input_a = [LogicGate(pos+(x, 0, 2), "FF0000", 1)
|
14
|
+
for x in range(bit_length)]
|
15
|
+
input_b = [LogicGate(pos+(x, 0, 0), "FF0000", 2)
|
16
|
+
for x in range(bit_length)]
|
17
|
+
and_0 = [LogicGate(pos+(x, -1, 2), "000000", 0)
|
18
|
+
for x in range(bit_length)]
|
19
|
+
xor_0 = [LogicGate(pos+(x, -1, 0), "000000", 2)
|
20
|
+
for x in range(bit_length)]
|
21
|
+
or_0 = [LogicGate(pos+((x, -2, 0) if x + 1 != bit_length else (x+1, -2, 2)), "000000" if x + 1 != bit_length else "0000FF", 1)
|
22
|
+
for x in range(bit_length)]
|
23
|
+
and_1 = [LogicGate(pos+(x, -2, 1), "000000", 0)
|
24
|
+
for x in range(bit_length)]
|
25
|
+
xor_1 = [LogicGate(pos+(x, -2, 2), "0000FF", 2)
|
26
|
+
for x in range(bit_length)]
|
27
|
+
carry_in = LogicGate(pos+(-1, -2, 0), "FF0000", 1)
|
28
|
+
|
29
|
+
connect(input_a, and_0)
|
30
|
+
connect(input_a, xor_0)
|
31
|
+
connect(input_b, and_0)
|
32
|
+
connect(input_b, xor_0)
|
33
|
+
connect(and_0, or_0)
|
34
|
+
connect(xor_0, and_1)
|
35
|
+
connect(xor_0, xor_1)
|
36
|
+
connect(and_1, or_0)
|
37
|
+
connect(or_0, and_1[1:])
|
38
|
+
connect(or_0, xor_1[1:])
|
39
|
+
connect(carry_in, and_1[0])
|
40
|
+
connect(carry_in, xor_1[0])
|
41
|
+
connect(carry_in, input_b)
|
42
|
+
|
43
|
+
bp.add(input_a, input_b, and_0, xor_0, or_0, and_1, xor_1, carry_in)
|
44
|
+
return input_a, input_b, and_0, xor_0, or_0, and_1, xor_1, carry_in
|