sm-blueprint-lib 0.0.6__py3-none-any.whl → 0.0.8__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.
@@ -0,0 +1,5 @@
1
+ from .barrierblock import *
2
+ from .logicgate import *
3
+ from .sensor import *
4
+ # from .switch import * # not finished
5
+ from .timer import *
@@ -0,0 +1,12 @@
1
+ from .adder import *
2
+ from .barrel_shifter import *
3
+ from .clock40hz import *
4
+ from .comparator import *
5
+ from .counter import *
6
+ from .decoder import *
7
+ from .distance_sensor import *
8
+ from .ram import *
9
+ from .register import *
10
+ from .rom import *
11
+ from .timer_ram_cached import * # not finished
12
+ from .timer_ram_multiclient import *
sm_blueprint_lib/utils.py CHANGED
@@ -1,6 +1,7 @@
1
1
  from dataclasses import asdict
2
2
  from json import load, dump, loads, dumps
3
3
  from math import ceil, log2
4
+ from typing import Sequence
4
5
 
5
6
  from numpy import ndarray
6
7
 
@@ -12,7 +13,7 @@ from .parts.timer import Timer
12
13
  from .pos import Pos
13
14
 
14
15
 
15
- def load_blueprint(path):
16
+ def load_blueprint(path: str):
16
17
  """Load a blueprint from a path file (normally a blueprint.json).
17
18
 
18
19
  Args:
@@ -25,7 +26,7 @@ def load_blueprint(path):
25
26
  return Blueprint(**load(fp))
26
27
 
27
28
 
28
- def save_blueprint(path, bp: Blueprint):
29
+ def save_blueprint(bp: Blueprint, path: str):
29
30
  """Save a blueprint to a file (normally a blueprint.json).
30
31
 
31
32
  Args:
@@ -36,7 +37,7 @@ def save_blueprint(path, bp: Blueprint):
36
37
  return dump(asdict(bp), fp, sort_keys=True, separators=(',', ':'))
37
38
 
38
39
 
39
- def load_string(str):
40
+ def load_blueprint_from_string(str: str):
40
41
  """Load a blueprint from a json string.
41
42
 
42
43
  Args:
@@ -48,7 +49,7 @@ def load_string(str):
48
49
  return Blueprint(**loads(str))
49
50
 
50
51
 
51
- def dump_string(bp: Blueprint):
52
+ def dump_string_from_blueprint(bp: Blueprint):
52
53
  """Dump a blueprint into a json-formatted string.
53
54
 
54
55
  Args:
@@ -110,9 +111,17 @@ def connect(_from, _to, *, parallel=True):
110
111
  connect(_from, subto, parallel=parallel)
111
112
 
112
113
 
113
- def check_pos(pos):
114
+ def check_pos(pos: Sequence) -> Pos:
115
+ """Converts a Sequence into a Pos class if it wasn't already.
116
+
117
+ Args:
118
+ pos (Sequence): The Sequence to be converted.
119
+
120
+ Returns:
121
+ Pos: The converted Pos.
122
+ """
114
123
  if not isinstance(pos, Pos):
115
- pos = Pos(*pos)
124
+ pos = Pos(*list(pos))
116
125
  return pos
117
126
 
118
127
 
@@ -0,0 +1,99 @@
1
+ Metadata-Version: 2.4
2
+ Name: sm_blueprint_lib
3
+ Version: 0.0.8
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)
@@ -5,7 +5,7 @@ sm_blueprint_lib/bounds.py,sha256=fH-i8PdlZVg8qlEd3FmIf5mbx4RKhdBOFRAe5cSWWiI,18
5
5
  sm_blueprint_lib/constants.py,sha256=mll05HrWLGCETzvQlkDPRMBe5HJLAGn5rRkxs5gJ71E,710
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=g3psyklJ6D1PvyL-MQPDN1TqW7Q1JVr1eSuoIdJy0Ro,4819
8
+ sm_blueprint_lib/utils.py,sha256=oT4s7kpY7-OSFDFiJt48fr7Yp_dBkGz45iOBiwnNcHE,5109
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,13 @@ 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
19
  sm_blueprint_lib/parts/barrierblock.py,sha256=GPI8ArKKvzO6wnHfBfgmU4Ezcrw9SmtKR0p4mWczYiw,267
19
20
  sm_blueprint_lib/parts/logicgate.py,sha256=In7-d-lCx1zJIT-7S0Mh7s32lj7xZ6wxObJMnKJKQQ4,960
20
21
  sm_blueprint_lib/parts/sensor.py,sha256=ZJY5xo0NB6wAwgzS7EO-xgsukXYbwV7ptbGOqLfeBKQ,1008
21
22
  sm_blueprint_lib/parts/switch.py,sha256=3Yo1xMKV5kWnptgnAA1XR_VU2ft-10EuKR62nzvZ0gI,225
22
23
  sm_blueprint_lib/parts/timer.py,sha256=gw9XaWvP2yW3egT72BGowMu-CZFUY-Hke-Dwg0lsxjM,806
24
+ sm_blueprint_lib/prebuilds/__init__.py,sha256=iPrsPMiuoluIDvdLGuQmEJ-I11D5qk563ANKr3md1GM,337
23
25
  sm_blueprint_lib/prebuilds/adder.py,sha256=Rq-006N_oD5ExIwQelgfrBKd7g8zFVxk4tj2lZEp82w,1750
24
26
  sm_blueprint_lib/prebuilds/barrel_shifter.py,sha256=BOvsUg9o6YzVrclmGNzhSbt9eQL23GJHHVyNxkXbcaE,3556
25
27
  sm_blueprint_lib/prebuilds/clock40hz.py,sha256=ygG8ieqpFzGMnuY5CBTs60liAYyAsBx-YIlb0gl3SXM,844
@@ -32,7 +34,7 @@ sm_blueprint_lib/prebuilds/register.py,sha256=MAiplmiA2L_VJaxCX2E8QuancnoqvyLY-v
32
34
  sm_blueprint_lib/prebuilds/rom.py,sha256=4dxAaNxRX60kDW17NKew-TJkPB7EMfHuK_zVIm6N-jo,3700
33
35
  sm_blueprint_lib/prebuilds/timer_ram_cached.py,sha256=PG53hDKYS00fur5vazh7iOs2Gm4G_URJLX7d9xWJOe4,19057
34
36
  sm_blueprint_lib/prebuilds/timer_ram_multiclient.py,sha256=NlQeJB6ilEGJDrIOfkFmPWd7afDR_0CUZH7RQpjyA4s,4200
35
- sm_blueprint_lib-0.0.6.dist-info/METADATA,sha256=PuNO-nrz_OB8Iq0BGapU0yrouBhfC5d0bbkxfkv8yXM,611
36
- sm_blueprint_lib-0.0.6.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
37
- sm_blueprint_lib-0.0.6.dist-info/licenses/LICENSE,sha256=DWhaodryTSEv07KdWbanCMaEujOXYxnj-IEhmgTkOq0,1084
38
- sm_blueprint_lib-0.0.6.dist-info/RECORD,,
37
+ sm_blueprint_lib-0.0.8.dist-info/METADATA,sha256=a8b9VUFkqtRqzOTuWkomOeOb6y6r7VerAgp7ZNuOGs0,3378
38
+ sm_blueprint_lib-0.0.8.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
39
+ sm_blueprint_lib-0.0.8.dist-info/licenses/LICENSE,sha256=DWhaodryTSEv07KdWbanCMaEujOXYxnj-IEhmgTkOq0,1084
40
+ sm_blueprint_lib-0.0.8.dist-info/RECORD,,
@@ -1,17 +0,0 @@
1
- Metadata-Version: 2.4
2
- Name: sm_blueprint_lib
3
- Version: 0.0.6
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.