sm-blueprint-lib 0.0.7__py3-none-any.whl → 0.0.9__py3-none-any.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.
@@ -4,6 +4,7 @@ class SHAPEID:
4
4
  TIMER = "8f7fd0e7-c46e-4944-a414-7ce2437bb30f"
5
5
  SENSOR5 = "20dcd41c-0a11-4668-9b00-97f278ce21af"
6
6
  SWITCH = "7cf717d7-d167-4f2d-a6e7-6b2c70aa3986"
7
+ BUTTON = "1e8d93a4-506b-470d-9ada-9c0a321e2db5"
7
8
  SHAPEID_TO_CLASS = {}
8
9
 
9
10
 
@@ -1,5 +1,6 @@
1
1
  from .barrierblock import *
2
2
  from .logicgate import *
3
3
  from .sensor import *
4
- # from .switch import * # not finished
4
+ from .switch import *
5
+ from .button import *
5
6
  from .timer import *
@@ -0,0 +1,9 @@
1
+ from dataclasses import dataclass, field
2
+
3
+ from ..bases.parts.baseinteractablepart import BaseInteractablePart
4
+ from ..constants import SHAPEID, AXIS
5
+
6
+
7
+ @dataclass
8
+ class Button(BaseInteractablePart):
9
+ shapeId: str = field(kw_only=True, default=SHAPEID.BUTTON)
@@ -1,9 +1,9 @@
1
1
  from dataclasses import dataclass, field
2
2
 
3
- from ..bases.parts.baseinteractablepart import BaseInteractablePart
3
+ from ..bases.parts.baselogicpart import BaseLogicPart
4
4
  from ..constants import SHAPEID
5
5
 
6
6
 
7
7
  @dataclass
8
- class Switch(BaseInteractablePart):
9
- raise NotImplemented
8
+ class Switch(BaseLogicPart):
9
+ shapeId: str = field(kw_only=True, default=SHAPEID.SWITCH)
sm_blueprint_lib/utils.py CHANGED
@@ -88,22 +88,27 @@ def connect(_from, _to, *, parallel=True):
88
88
  if isinstance(_from, BaseInteractablePart) and isinstance(_to, BaseInteractablePart):
89
89
  _from.connect(_to)
90
90
  return
91
- if parallel: # Try connect things row-by-row if possible (one to one, one to many, many to many)
92
- if not isinstance(_from, BaseInteractablePart) and not isinstance(_to, BaseInteractablePart): # Assume both are sequence of parts
91
+ # Try connect things row-by-row if possible (one to one, one to many, many to many)
92
+ if parallel:
93
+ # Assume both are sequence of parts
94
+ if not isinstance(_from, BaseInteractablePart) and not isinstance(_to, BaseInteractablePart):
93
95
  for subfrom, subto in zip(_from, _to):
94
96
  connect(subfrom, subto, parallel=parallel)
95
- elif not isinstance(_from, BaseInteractablePart): # Assume _from is a sequence of parts
97
+ # Assume _from is a sequence of parts
98
+ elif not isinstance(_from, BaseInteractablePart):
96
99
  for subfrom in _from:
97
100
  connect(subfrom, _to, parallel=parallel)
98
101
  else: # Assume _to is a sequence of parts
99
102
  for subto in _to:
100
103
  connect(_from, subto, parallel=parallel)
101
104
  else: # Just connect everything to everything lol
102
- if not isinstance(_from, BaseInteractablePart) and not isinstance(_to, BaseInteractablePart): # Assume both are sequence of parts
105
+ # Assume both are sequence of parts
106
+ if not isinstance(_from, BaseInteractablePart) and not isinstance(_to, BaseInteractablePart):
103
107
  for subfrom in _from:
104
108
  for subto in _to:
105
109
  connect(subfrom, subto, parallel=parallel)
106
- elif not isinstance(_from, BaseInteractablePart): # Assume _from is a sequence of parts
110
+ # Assume _from is a sequence of parts
111
+ elif not isinstance(_from, BaseInteractablePart):
107
112
  for subfrom in _from:
108
113
  connect(subfrom, _to, parallel=parallel)
109
114
  else: # Assume _to is a sequence of parts
@@ -0,0 +1,99 @@
1
+ Metadata-Version: 2.4
2
+ Name: sm_blueprint_lib
3
+ Version: 0.0.9
4
+ Summary: Scrap Mechanic Library for Blueprint manipulation.
5
+ Project-URL: Homepage, https://github.com/MauriceTZ/sm_blueprint_lib
6
+ Project-URL: Issues, https://github.com/MauriceTZ/sm_blueprint_lib/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
+ Requires-Dist: numpy
14
+ Description-Content-Type: text/markdown
15
+
16
+ # sm_blueprint_lib
17
+ Scrap Mechanic Library for Blueprint manipulation.
18
+
19
+ ## Instalation
20
+ ```sh
21
+ pip install sm_blueprint_lib
22
+ ```
23
+ ## Usage
24
+ ```python
25
+ import numpy as np
26
+
27
+ import sm_blueprint_lib as sm
28
+
29
+ # Create a Blueprint object to store your parts
30
+ bp = sm.Blueprint()
31
+
32
+ # Define your stuff as you like, ID's are generated automatically or u can create them manually
33
+ # The controller argument is converted to the needed LogicGateController class
34
+ # 0: and, 1: or, 2: xor, 3: nand, 4: nor, 5: xnor
35
+ single_and = sm.LogicGate(pos=(0, 0, 0), color="1122ff", controller=0)
36
+ single_or = sm.LogicGate(sm.Pos(0, 2, 0), "3322ff", 1)
37
+ single_self_wired_xor = sm.LogicGate(
38
+ pos=sm.Pos(0, 4, 0),
39
+ color="5522ff",
40
+ # Or define it explicitly
41
+ controller=sm.LogicGateController(mode=2, id=9999999, controllers=[sm.ID(9999999)])
42
+ )
43
+
44
+ # Create multiple gates at the same time
45
+ row_0 = [sm.LogicGate((x, 6, 0), "ffffff", 0) for x in range(10)]
46
+ row_1 = [sm.LogicGate((-1, 6, z + 1), "ffffff", 0) for z in range(10)]
47
+ # Define matrices using numpy
48
+ matrix = np.ndarray((10, 10), dtype=sm.LogicGate)
49
+ for x in range(10):
50
+ for z in range(10):
51
+ # Define custom rotation (xaxis, zaxis)
52
+ matrix[x, z] = sm.LogicGate(
53
+ (x, 8, z + 1), "000000", 5, xaxis=1, zaxis=2)
54
+
55
+ single_nor = sm.LogicGate(sm.Pos(0, 11, 0), "ee22ff", 4)
56
+
57
+ row_2 = [sm.LogicGate((x, 13, 0), "ffffff", 0) for x in range(10)]
58
+ row_3 = [sm.LogicGate((-1, 13, z + 1), "ffffff", 0) for z in range(10)]
59
+
60
+ # Simple Timer loop
61
+ loop = [sm.LogicGate((4, 0, 0), "987654"),
62
+ # TimerController can be passed as (seconds, ticks)
63
+ sm.Timer((5, 0, 0), "3210ff", (1, 0)),
64
+ sm.LogicGate((6, 0, 0), "eeddcc", 3)]
65
+
66
+ # Connect stuff
67
+ # 1 to 1
68
+ sm.connect(single_and, single_or)
69
+ sm.connect(single_or, single_self_wired_xor)
70
+ sm.connect(row_0, row_1) # With parallel=True (ie row to row)
71
+ # 1 to many
72
+ sm.connect(single_self_wired_xor, row_0)
73
+ sm.connect(row_0, matrix)
74
+ # Many to 1
75
+ sm.connect(matrix, single_nor)
76
+ # Many to many
77
+ # With parallel=False (ie everything connects to everything)
78
+ sm.connect(row_2, row_3, parallel=False)
79
+ # You can also chain single gate connections
80
+ loop[0].connect(loop[1]).connect(loop[2]).connect(loop[0])
81
+
82
+ # Put all parts into the blueprint
83
+ # Note that it doesn't care if it's a single gate or arrays
84
+ bp.add(single_and, single_or, single_self_wired_xor,
85
+ row_0, row_1, matrix, single_nor, row_2, row_3, loop)
86
+
87
+ # Finally, save the blueprint into a file or dump it as a string
88
+ print(sm.dump_string_from_blueprint(bp))
89
+ path = "path/to/your/blueprint/folder/blueprint.json"
90
+ sm.save_blueprint(bp, path)
91
+ ```
92
+
93
+ ### Results
94
+ #### 1 to 1 and loop
95
+ ![1 to 1 and loop](1to1andloop.png)
96
+ #### Row to row and 1 to many
97
+ ![row to row and 1 to many](rowtorowand1tomany.png)
98
+ #### Many to 1 and many to many
99
+ ![many to 1 and many to many](manytooneandmanytomany.png)
@@ -2,10 +2,10 @@ sm_blueprint_lib/__init__.py,sha256=yTdxFiDVUYCQoW_vakHBbtoQQfHhYkyGlziEO_BIRWE,
2
2
  sm_blueprint_lib/blueprint.py,sha256=fmdB4XKXF-f-iSoq5ckcLdQAX90ftkfvDuOSzHTB_44,1080
3
3
  sm_blueprint_lib/body.py,sha256=sjnS0e1V0bZEhODA6XOxPH2oCt3xrFLQZ47PGhKjD_w,365
4
4
  sm_blueprint_lib/bounds.py,sha256=fH-i8PdlZVg8qlEd3FmIf5mbx4RKhdBOFRAe5cSWWiI,183
5
- sm_blueprint_lib/constants.py,sha256=mll05HrWLGCETzvQlkDPRMBe5HJLAGn5rRkxs5gJ71E,710
5
+ sm_blueprint_lib/constants.py,sha256=LVAilqV6SR5c8FGurqwk7csI5z9l1eAjgSCg5h4HQuI,763
6
6
  sm_blueprint_lib/id.py,sha256=5sBHC8qZJnCaizSBs4KGS1dnZHOSdoq5wkuIpuYNRnw,71
7
7
  sm_blueprint_lib/pos.py,sha256=W0yaIg_nYgRqFwSkHlpd7Tfr69XSVwjTY1DfICHXoDo,411
8
- sm_blueprint_lib/utils.py,sha256=oT4s7kpY7-OSFDFiJt48fr7Yp_dBkGz45iOBiwnNcHE,5109
8
+ sm_blueprint_lib/utils.py,sha256=LzsOZfzfpeAgFQczApqtHm3iZ25N9HUWx2Vus95dUqM,5139
9
9
  sm_blueprint_lib/bases/controllers/basecontroller.py,sha256=VFS5J7kGQ8vfWBFjiTPVfXXjyMwJ1VqA3mYuh7Z_8ak,624
10
10
  sm_blueprint_lib/bases/controllers/baselogiccontroller.py,sha256=lDoDt9NKFu01CqyJE09_bq9oDeYK7T-fERO54kd-sFA,290
11
11
  sm_blueprint_lib/bases/controllers/logicgatecontroller.py,sha256=wzw8kdt65Zg6ucNNy47V3-okYod_ea2NH8erfjRu7uw,223
@@ -15,11 +15,12 @@ sm_blueprint_lib/bases/parts/baseboundablepart.py,sha256=jNx_btmkCTksT6FcpHQxEVJ
15
15
  sm_blueprint_lib/bases/parts/baseinteractablepart.py,sha256=VXINrObIr6Y2tFIOI59cB_-625rPwtKZdGDmaa3EgQ8,574
16
16
  sm_blueprint_lib/bases/parts/baselogicpart.py,sha256=al9nLCg8YiLKWd_c_ZQmq9f6sazjF6RNbuGGbYROOps,498
17
17
  sm_blueprint_lib/bases/parts/basepart.py,sha256=hzJBcB4uol65THzEZEGq4d2N9SbK1S4XiMghEuB6cuc,1126
18
- sm_blueprint_lib/parts/__init__.py,sha256=3MW-wlhw2BepJ4bo1_xSAe2DzsfQ1yh-U3UnjWgZm2w,140
18
+ sm_blueprint_lib/parts/__init__.py,sha256=Ij9tismamOFKYyAI-RxcCc97L78XJCxPb6Yto4SPSN8,146
19
19
  sm_blueprint_lib/parts/barrierblock.py,sha256=GPI8ArKKvzO6wnHfBfgmU4Ezcrw9SmtKR0p4mWczYiw,267
20
+ sm_blueprint_lib/parts/button.py,sha256=cZomy4n90XZqpUO4IkZff3kIbVkP9yGvscIysfBBxSg,269
20
21
  sm_blueprint_lib/parts/logicgate.py,sha256=In7-d-lCx1zJIT-7S0Mh7s32lj7xZ6wxObJMnKJKQQ4,960
21
22
  sm_blueprint_lib/parts/sensor.py,sha256=ZJY5xo0NB6wAwgzS7EO-xgsukXYbwV7ptbGOqLfeBKQ,1008
22
- sm_blueprint_lib/parts/switch.py,sha256=3Yo1xMKV5kWnptgnAA1XR_VU2ft-10EuKR62nzvZ0gI,225
23
+ sm_blueprint_lib/parts/switch.py,sha256=VkPfvux1TeLTZawmYEHMLGnXxk-lqgB6qb2hwpICjms,242
23
24
  sm_blueprint_lib/parts/timer.py,sha256=gw9XaWvP2yW3egT72BGowMu-CZFUY-Hke-Dwg0lsxjM,806
24
25
  sm_blueprint_lib/prebuilds/__init__.py,sha256=iPrsPMiuoluIDvdLGuQmEJ-I11D5qk563ANKr3md1GM,337
25
26
  sm_blueprint_lib/prebuilds/adder.py,sha256=Rq-006N_oD5ExIwQelgfrBKd7g8zFVxk4tj2lZEp82w,1750
@@ -34,7 +35,7 @@ sm_blueprint_lib/prebuilds/register.py,sha256=MAiplmiA2L_VJaxCX2E8QuancnoqvyLY-v
34
35
  sm_blueprint_lib/prebuilds/rom.py,sha256=4dxAaNxRX60kDW17NKew-TJkPB7EMfHuK_zVIm6N-jo,3700
35
36
  sm_blueprint_lib/prebuilds/timer_ram_cached.py,sha256=PG53hDKYS00fur5vazh7iOs2Gm4G_URJLX7d9xWJOe4,19057
36
37
  sm_blueprint_lib/prebuilds/timer_ram_multiclient.py,sha256=NlQeJB6ilEGJDrIOfkFmPWd7afDR_0CUZH7RQpjyA4s,4200
37
- sm_blueprint_lib-0.0.7.dist-info/METADATA,sha256=QBI7t4D3xRFccTybjqgAnnACBTcg0oQMJX4MuzDD9-0,611
38
- sm_blueprint_lib-0.0.7.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
39
- sm_blueprint_lib-0.0.7.dist-info/licenses/LICENSE,sha256=DWhaodryTSEv07KdWbanCMaEujOXYxnj-IEhmgTkOq0,1084
40
- sm_blueprint_lib-0.0.7.dist-info/RECORD,,
38
+ sm_blueprint_lib-0.0.9.dist-info/METADATA,sha256=xpVz1qUOkZeVorjGXLrFhj6AaMUr3UpIbL-JgAAXHls,3378
39
+ sm_blueprint_lib-0.0.9.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
40
+ sm_blueprint_lib-0.0.9.dist-info/licenses/LICENSE,sha256=DWhaodryTSEv07KdWbanCMaEujOXYxnj-IEhmgTkOq0,1084
41
+ sm_blueprint_lib-0.0.9.dist-info/RECORD,,
@@ -1,17 +0,0 @@
1
- Metadata-Version: 2.4
2
- Name: sm_blueprint_lib
3
- Version: 0.0.7
4
- Summary: Scrap Mechanic Library for Blueprint manipulation.
5
- Project-URL: Homepage, https://github.com/MauriceTZ/sm_blueprint_lib
6
- Project-URL: Issues, https://github.com/MauriceTZ/sm_blueprint_lib/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
- Requires-Dist: numpy
14
- Description-Content-Type: text/markdown
15
-
16
- # sm_blueprint_lib
17
- Scrap Mechanic Library for Blueprint manipulation.