sm-blueprint-lib 0.0.7__tar.gz → 0.0.9__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.
Files changed (52) hide show
  1. sm_blueprint_lib-0.0.9/1to1andloop.png +0 -0
  2. sm_blueprint_lib-0.0.9/PKG-INFO +99 -0
  3. sm_blueprint_lib-0.0.9/README.md +84 -0
  4. sm_blueprint_lib-0.0.9/manytooneandmanytomany.png +0 -0
  5. {sm_blueprint_lib-0.0.7 → sm_blueprint_lib-0.0.9}/pyproject.toml +1 -1
  6. sm_blueprint_lib-0.0.9/rowtorowand1tomany.png +0 -0
  7. {sm_blueprint_lib-0.0.7 → sm_blueprint_lib-0.0.9}/src/sm_blueprint_lib/constants.py +1 -0
  8. {sm_blueprint_lib-0.0.7 → sm_blueprint_lib-0.0.9}/src/sm_blueprint_lib/parts/__init__.py +2 -1
  9. sm_blueprint_lib-0.0.9/src/sm_blueprint_lib/parts/button.py +9 -0
  10. sm_blueprint_lib-0.0.9/src/sm_blueprint_lib/parts/switch.py +9 -0
  11. {sm_blueprint_lib-0.0.7 → sm_blueprint_lib-0.0.9}/src/sm_blueprint_lib/utils.py +10 -5
  12. {sm_blueprint_lib-0.0.7 → sm_blueprint_lib-0.0.9}/test_connections.py +6 -2
  13. sm_blueprint_lib-0.0.7/PKG-INFO +0 -17
  14. sm_blueprint_lib-0.0.7/README.md +0 -2
  15. sm_blueprint_lib-0.0.7/src/sm_blueprint_lib/parts/switch.py +0 -9
  16. {sm_blueprint_lib-0.0.7 → sm_blueprint_lib-0.0.9}/.gitattributes +0 -0
  17. {sm_blueprint_lib-0.0.7 → sm_blueprint_lib-0.0.9}/.gitignore +0 -0
  18. {sm_blueprint_lib-0.0.7 → sm_blueprint_lib-0.0.9}/LICENSE +0 -0
  19. {sm_blueprint_lib-0.0.7 → sm_blueprint_lib-0.0.9}/src/sm_blueprint_lib/__init__.py +0 -0
  20. {sm_blueprint_lib-0.0.7 → sm_blueprint_lib-0.0.9}/src/sm_blueprint_lib/bases/controllers/basecontroller.py +0 -0
  21. {sm_blueprint_lib-0.0.7 → sm_blueprint_lib-0.0.9}/src/sm_blueprint_lib/bases/controllers/baselogiccontroller.py +0 -0
  22. {sm_blueprint_lib-0.0.7 → sm_blueprint_lib-0.0.9}/src/sm_blueprint_lib/bases/controllers/logicgatecontroller.py +0 -0
  23. {sm_blueprint_lib-0.0.7 → sm_blueprint_lib-0.0.9}/src/sm_blueprint_lib/bases/controllers/sensorcontroller.py +0 -0
  24. {sm_blueprint_lib-0.0.7 → sm_blueprint_lib-0.0.9}/src/sm_blueprint_lib/bases/controllers/timercontroller.py +0 -0
  25. {sm_blueprint_lib-0.0.7 → sm_blueprint_lib-0.0.9}/src/sm_blueprint_lib/bases/parts/baseboundablepart.py +0 -0
  26. {sm_blueprint_lib-0.0.7 → sm_blueprint_lib-0.0.9}/src/sm_blueprint_lib/bases/parts/baseinteractablepart.py +0 -0
  27. {sm_blueprint_lib-0.0.7 → sm_blueprint_lib-0.0.9}/src/sm_blueprint_lib/bases/parts/baselogicpart.py +0 -0
  28. {sm_blueprint_lib-0.0.7 → sm_blueprint_lib-0.0.9}/src/sm_blueprint_lib/bases/parts/basepart.py +0 -0
  29. {sm_blueprint_lib-0.0.7 → sm_blueprint_lib-0.0.9}/src/sm_blueprint_lib/blueprint.py +0 -0
  30. {sm_blueprint_lib-0.0.7 → sm_blueprint_lib-0.0.9}/src/sm_blueprint_lib/body.py +0 -0
  31. {sm_blueprint_lib-0.0.7 → sm_blueprint_lib-0.0.9}/src/sm_blueprint_lib/bounds.py +0 -0
  32. {sm_blueprint_lib-0.0.7 → sm_blueprint_lib-0.0.9}/src/sm_blueprint_lib/id.py +0 -0
  33. {sm_blueprint_lib-0.0.7 → sm_blueprint_lib-0.0.9}/src/sm_blueprint_lib/parts/barrierblock.py +0 -0
  34. {sm_blueprint_lib-0.0.7 → sm_blueprint_lib-0.0.9}/src/sm_blueprint_lib/parts/logicgate.py +0 -0
  35. {sm_blueprint_lib-0.0.7 → sm_blueprint_lib-0.0.9}/src/sm_blueprint_lib/parts/sensor.py +0 -0
  36. {sm_blueprint_lib-0.0.7 → sm_blueprint_lib-0.0.9}/src/sm_blueprint_lib/parts/timer.py +0 -0
  37. {sm_blueprint_lib-0.0.7 → sm_blueprint_lib-0.0.9}/src/sm_blueprint_lib/pos.py +0 -0
  38. {sm_blueprint_lib-0.0.7 → sm_blueprint_lib-0.0.9}/src/sm_blueprint_lib/prebuilds/__init__.py +0 -0
  39. {sm_blueprint_lib-0.0.7 → sm_blueprint_lib-0.0.9}/src/sm_blueprint_lib/prebuilds/adder.py +0 -0
  40. {sm_blueprint_lib-0.0.7 → sm_blueprint_lib-0.0.9}/src/sm_blueprint_lib/prebuilds/barrel_shifter.py +0 -0
  41. {sm_blueprint_lib-0.0.7 → sm_blueprint_lib-0.0.9}/src/sm_blueprint_lib/prebuilds/clock40hz.py +0 -0
  42. {sm_blueprint_lib-0.0.7 → sm_blueprint_lib-0.0.9}/src/sm_blueprint_lib/prebuilds/comparator.py +0 -0
  43. {sm_blueprint_lib-0.0.7 → sm_blueprint_lib-0.0.9}/src/sm_blueprint_lib/prebuilds/counter.py +0 -0
  44. {sm_blueprint_lib-0.0.7 → sm_blueprint_lib-0.0.9}/src/sm_blueprint_lib/prebuilds/decoder.py +0 -0
  45. {sm_blueprint_lib-0.0.7 → sm_blueprint_lib-0.0.9}/src/sm_blueprint_lib/prebuilds/distance_sensor.py +0 -0
  46. {sm_blueprint_lib-0.0.7 → sm_blueprint_lib-0.0.9}/src/sm_blueprint_lib/prebuilds/ram.py +0 -0
  47. {sm_blueprint_lib-0.0.7 → sm_blueprint_lib-0.0.9}/src/sm_blueprint_lib/prebuilds/register.py +0 -0
  48. {sm_blueprint_lib-0.0.7 → sm_blueprint_lib-0.0.9}/src/sm_blueprint_lib/prebuilds/rom.py +0 -0
  49. {sm_blueprint_lib-0.0.7 → sm_blueprint_lib-0.0.9}/src/sm_blueprint_lib/prebuilds/timer_ram_cached.py +0 -0
  50. {sm_blueprint_lib-0.0.7 → sm_blueprint_lib-0.0.9}/src/sm_blueprint_lib/prebuilds/timer_ram_multiclient.py +0 -0
  51. {sm_blueprint_lib-0.0.7 → sm_blueprint_lib-0.0.9}/test_prebuilds.py +0 -0
  52. {sm_blueprint_lib-0.0.7 → sm_blueprint_lib-0.0.9}/tests.py +0 -0
Binary file
@@ -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)
@@ -0,0 +1,84 @@
1
+ # sm_blueprint_lib
2
+ Scrap Mechanic Library for Blueprint manipulation.
3
+
4
+ ## Instalation
5
+ ```sh
6
+ pip install sm_blueprint_lib
7
+ ```
8
+ ## Usage
9
+ ```python
10
+ import numpy as np
11
+
12
+ import sm_blueprint_lib as sm
13
+
14
+ # Create a Blueprint object to store your parts
15
+ bp = sm.Blueprint()
16
+
17
+ # Define your stuff as you like, ID's are generated automatically or u can create them manually
18
+ # The controller argument is converted to the needed LogicGateController class
19
+ # 0: and, 1: or, 2: xor, 3: nand, 4: nor, 5: xnor
20
+ single_and = sm.LogicGate(pos=(0, 0, 0), color="1122ff", controller=0)
21
+ single_or = sm.LogicGate(sm.Pos(0, 2, 0), "3322ff", 1)
22
+ single_self_wired_xor = sm.LogicGate(
23
+ pos=sm.Pos(0, 4, 0),
24
+ color="5522ff",
25
+ # Or define it explicitly
26
+ controller=sm.LogicGateController(mode=2, id=9999999, controllers=[sm.ID(9999999)])
27
+ )
28
+
29
+ # Create multiple gates at the same time
30
+ row_0 = [sm.LogicGate((x, 6, 0), "ffffff", 0) for x in range(10)]
31
+ row_1 = [sm.LogicGate((-1, 6, z + 1), "ffffff", 0) for z in range(10)]
32
+ # Define matrices using numpy
33
+ matrix = np.ndarray((10, 10), dtype=sm.LogicGate)
34
+ for x in range(10):
35
+ for z in range(10):
36
+ # Define custom rotation (xaxis, zaxis)
37
+ matrix[x, z] = sm.LogicGate(
38
+ (x, 8, z + 1), "000000", 5, xaxis=1, zaxis=2)
39
+
40
+ single_nor = sm.LogicGate(sm.Pos(0, 11, 0), "ee22ff", 4)
41
+
42
+ row_2 = [sm.LogicGate((x, 13, 0), "ffffff", 0) for x in range(10)]
43
+ row_3 = [sm.LogicGate((-1, 13, z + 1), "ffffff", 0) for z in range(10)]
44
+
45
+ # Simple Timer loop
46
+ loop = [sm.LogicGate((4, 0, 0), "987654"),
47
+ # TimerController can be passed as (seconds, ticks)
48
+ sm.Timer((5, 0, 0), "3210ff", (1, 0)),
49
+ sm.LogicGate((6, 0, 0), "eeddcc", 3)]
50
+
51
+ # Connect stuff
52
+ # 1 to 1
53
+ sm.connect(single_and, single_or)
54
+ sm.connect(single_or, single_self_wired_xor)
55
+ sm.connect(row_0, row_1) # With parallel=True (ie row to row)
56
+ # 1 to many
57
+ sm.connect(single_self_wired_xor, row_0)
58
+ sm.connect(row_0, matrix)
59
+ # Many to 1
60
+ sm.connect(matrix, single_nor)
61
+ # Many to many
62
+ # With parallel=False (ie everything connects to everything)
63
+ sm.connect(row_2, row_3, parallel=False)
64
+ # You can also chain single gate connections
65
+ loop[0].connect(loop[1]).connect(loop[2]).connect(loop[0])
66
+
67
+ # Put all parts into the blueprint
68
+ # Note that it doesn't care if it's a single gate or arrays
69
+ bp.add(single_and, single_or, single_self_wired_xor,
70
+ row_0, row_1, matrix, single_nor, row_2, row_3, loop)
71
+
72
+ # Finally, save the blueprint into a file or dump it as a string
73
+ print(sm.dump_string_from_blueprint(bp))
74
+ path = "path/to/your/blueprint/folder/blueprint.json"
75
+ sm.save_blueprint(bp, path)
76
+ ```
77
+
78
+ ### Results
79
+ #### 1 to 1 and loop
80
+ ![1 to 1 and loop](1to1andloop.png)
81
+ #### Row to row and 1 to many
82
+ ![row to row and 1 to many](rowtorowand1tomany.png)
83
+ #### Many to 1 and many to many
84
+ ![many to 1 and many to many](manytooneandmanytomany.png)
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "sm_blueprint_lib"
7
- version = "0.0.7"
7
+ version = "0.0.9"
8
8
  dependencies = ["numpy"]
9
9
  authors = [
10
10
  { name="Maurice", email="mauriciotorrez00@gmail.com" },
@@ -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)
@@ -0,0 +1,9 @@
1
+ from dataclasses import dataclass, field
2
+
3
+ from ..bases.parts.baselogicpart import BaseLogicPart
4
+ from ..constants import SHAPEID
5
+
6
+
7
+ @dataclass
8
+ class Switch(BaseLogicPart):
9
+ shapeId: str = field(kw_only=True, default=SHAPEID.SWITCH)
@@ -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
@@ -2,7 +2,7 @@ from pprint import pp
2
2
 
3
3
  from numpy import ndarray
4
4
 
5
- from src.sm_blueprint_lib import Timer, LogicGate, BarrierBlock, Blueprint, save_blueprint, dump_string_from_blueprint, connect
5
+ from src.sm_blueprint_lib import Timer, LogicGate, BarrierBlock, Switch, Button, Blueprint, save_blueprint, dump_string_from_blueprint, connect
6
6
 
7
7
  size = 10
8
8
  l0 = [
@@ -31,15 +31,19 @@ for x in range(size):
31
31
  base = BarrierBlock((0, -1, -1), "000000", (size+1, size+1, 1))
32
32
  zero = BarrierBlock((0, -1, 0), "000000", (1, 1, 1))
33
33
 
34
+ s = Switch((10, 10, 0), "ff0000")
35
+ b = Button((9, 9, 0), "ff0000")
36
+
34
37
  bp = Blueprint()
35
38
 
39
+ connect(s, l1)
36
40
  connect(l0, l1)
37
41
  connect(l0, l3)
38
42
  connect(l3, l2[-1])
39
43
  connect(l1, l2, parallel=False)
40
44
  connect(l3.T, l1)
41
45
 
42
- bp.add(l0, l1, l2, base, zero, l3)
46
+ bp.add(l0, l1, l2, base, zero, l3, s, b)
43
47
 
44
48
  # bp.add(l0)
45
49
  # bp.add(l1)
@@ -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.
@@ -1,2 +0,0 @@
1
- # sm_blueprint_lib
2
- Scrap Mechanic Library for Blueprint manipulation.
@@ -1,9 +0,0 @@
1
- from dataclasses import dataclass, field
2
-
3
- from ..bases.parts.baseinteractablepart import BaseInteractablePart
4
- from ..constants import SHAPEID
5
-
6
-
7
- @dataclass
8
- class Switch(BaseInteractablePart):
9
- raise NotImplemented