sm-blueprint-lib 0.0.5__tar.gz → 0.0.7__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.5 → sm_blueprint_lib-0.0.7}/.gitignore +0 -1
- {sm_blueprint_lib-0.0.5 → sm_blueprint_lib-0.0.7}/PKG-INFO +1 -1
- {sm_blueprint_lib-0.0.5 → sm_blueprint_lib-0.0.7}/pyproject.toml +1 -1
- sm_blueprint_lib-0.0.7/src/sm_blueprint_lib/__init__.py +10 -0
- {sm_blueprint_lib-0.0.5 → sm_blueprint_lib-0.0.7}/src/sm_blueprint_lib/bases/controllers/basecontroller.py +2 -2
- {sm_blueprint_lib-0.0.5 → sm_blueprint_lib-0.0.7}/src/sm_blueprint_lib/bases/controllers/baselogiccontroller.py +1 -1
- {sm_blueprint_lib-0.0.5 → sm_blueprint_lib-0.0.7}/src/sm_blueprint_lib/bases/controllers/logicgatecontroller.py +1 -1
- {sm_blueprint_lib-0.0.5 → sm_blueprint_lib-0.0.7}/src/sm_blueprint_lib/bases/controllers/sensorcontroller.py +1 -1
- {sm_blueprint_lib-0.0.5 → sm_blueprint_lib-0.0.7}/src/sm_blueprint_lib/bases/controllers/timercontroller.py +1 -1
- sm_blueprint_lib-0.0.7/src/sm_blueprint_lib/bases/parts/baseboundablepart.py +23 -0
- sm_blueprint_lib-0.0.7/src/sm_blueprint_lib/bases/parts/baseinteractablepart.py +19 -0
- sm_blueprint_lib-0.0.7/src/sm_blueprint_lib/bases/parts/baselogicpart.py +13 -0
- sm_blueprint_lib-0.0.7/src/sm_blueprint_lib/bases/parts/basepart.py +34 -0
- {sm_blueprint_lib-0.0.5 → sm_blueprint_lib-0.0.7}/src/sm_blueprint_lib/blueprint.py +3 -3
- {sm_blueprint_lib-0.0.5 → sm_blueprint_lib-0.0.7}/src/sm_blueprint_lib/body.py +2 -2
- sm_blueprint_lib-0.0.7/src/sm_blueprint_lib/parts/__init__.py +5 -0
- sm_blueprint_lib-0.0.7/src/sm_blueprint_lib/parts/barrierblock.py +9 -0
- sm_blueprint_lib-0.0.7/src/sm_blueprint_lib/parts/logicgate.py +24 -0
- sm_blueprint_lib-0.0.7/src/sm_blueprint_lib/parts/sensor.py +24 -0
- sm_blueprint_lib-0.0.7/src/sm_blueprint_lib/parts/switch.py +9 -0
- sm_blueprint_lib-0.0.7/src/sm_blueprint_lib/parts/timer.py +20 -0
- sm_blueprint_lib-0.0.7/src/sm_blueprint_lib/prebuilds/__init__.py +12 -0
- {sm_blueprint_lib-0.0.5 → sm_blueprint_lib-0.0.7}/src/sm_blueprint_lib/prebuilds/adder.py +4 -4
- {sm_blueprint_lib-0.0.5 → sm_blueprint_lib-0.0.7}/src/sm_blueprint_lib/prebuilds/barrel_shifter.py +4 -4
- {sm_blueprint_lib-0.0.5 → sm_blueprint_lib-0.0.7}/src/sm_blueprint_lib/prebuilds/clock40hz.py +4 -4
- {sm_blueprint_lib-0.0.5 → sm_blueprint_lib-0.0.7}/src/sm_blueprint_lib/prebuilds/comparator.py +4 -4
- {sm_blueprint_lib-0.0.5 → sm_blueprint_lib-0.0.7}/src/sm_blueprint_lib/prebuilds/counter.py +4 -4
- {sm_blueprint_lib-0.0.5 → sm_blueprint_lib-0.0.7}/src/sm_blueprint_lib/prebuilds/decoder.py +4 -4
- {sm_blueprint_lib-0.0.5 → sm_blueprint_lib-0.0.7}/src/sm_blueprint_lib/prebuilds/distance_sensor.py +6 -6
- {sm_blueprint_lib-0.0.5 → sm_blueprint_lib-0.0.7}/src/sm_blueprint_lib/prebuilds/ram.py +5 -5
- {sm_blueprint_lib-0.0.5 → sm_blueprint_lib-0.0.7}/src/sm_blueprint_lib/prebuilds/register.py +5 -5
- {sm_blueprint_lib-0.0.5 → sm_blueprint_lib-0.0.7}/src/sm_blueprint_lib/prebuilds/rom.py +6 -6
- {sm_blueprint_lib-0.0.5 → sm_blueprint_lib-0.0.7}/src/sm_blueprint_lib/prebuilds/timer_ram_cached.py +13 -13
- {sm_blueprint_lib-0.0.5 → sm_blueprint_lib-0.0.7}/src/sm_blueprint_lib/prebuilds/timer_ram_multiclient.py +9 -9
- {sm_blueprint_lib-0.0.5 → sm_blueprint_lib-0.0.7}/src/sm_blueprint_lib/utils.py +15 -6
- {sm_blueprint_lib-0.0.5 → sm_blueprint_lib-0.0.7}/test_connections.py +2 -2
- {sm_blueprint_lib-0.0.5 → sm_blueprint_lib-0.0.7}/test_prebuilds.py +16 -16
- {sm_blueprint_lib-0.0.5 → sm_blueprint_lib-0.0.7}/tests.py +5 -5
- sm_blueprint_lib-0.0.5/src/sm_blueprint_lib/__init__.py +0 -0
- {sm_blueprint_lib-0.0.5 → sm_blueprint_lib-0.0.7}/.gitattributes +0 -0
- {sm_blueprint_lib-0.0.5 → sm_blueprint_lib-0.0.7}/LICENSE +0 -0
- {sm_blueprint_lib-0.0.5 → sm_blueprint_lib-0.0.7}/README.md +0 -0
- {sm_blueprint_lib-0.0.5 → sm_blueprint_lib-0.0.7}/src/sm_blueprint_lib/bounds.py +0 -0
- {sm_blueprint_lib-0.0.5 → sm_blueprint_lib-0.0.7}/src/sm_blueprint_lib/constants.py +0 -0
- {sm_blueprint_lib-0.0.5 → sm_blueprint_lib-0.0.7}/src/sm_blueprint_lib/id.py +0 -0
- {sm_blueprint_lib-0.0.5 → sm_blueprint_lib-0.0.7}/src/sm_blueprint_lib/pos.py +0 -0
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.4
|
2
2
|
Name: sm_blueprint_lib
|
3
|
-
Version: 0.0.
|
3
|
+
Version: 0.0.7
|
4
4
|
Summary: Scrap Mechanic Library for Blueprint manipulation.
|
5
5
|
Project-URL: Homepage, https://github.com/MauriceTZ/sm_blueprint_lib
|
6
6
|
Project-URL: Issues, https://github.com/MauriceTZ/sm_blueprint_lib/issues
|
@@ -0,0 +1,23 @@
|
|
1
|
+
from dataclasses import dataclass, field
|
2
|
+
|
3
|
+
from .basepart import BasePart
|
4
|
+
from ...bounds import Bounds
|
5
|
+
from ...constants import AXIS
|
6
|
+
|
7
|
+
|
8
|
+
@dataclass
|
9
|
+
class BaseBoundablePart(BasePart):
|
10
|
+
"""Base class for all Boundable parts (those that are draggable)
|
11
|
+
"""
|
12
|
+
bounds: Bounds
|
13
|
+
xaxis: int = field(kw_only=True, default=AXIS.DEFAULT_XAXIS)
|
14
|
+
zaxis: int = field(kw_only=True, default=AXIS.DEFAULT_ZAXIS)
|
15
|
+
|
16
|
+
def __post_init__(self):
|
17
|
+
super().__post_init__()
|
18
|
+
if not isinstance(self.bounds, Bounds):
|
19
|
+
try:
|
20
|
+
self.bounds = Bounds(**self.bounds)
|
21
|
+
except TypeError:
|
22
|
+
self.bounds = Bounds(
|
23
|
+
self.bounds[0], self.bounds[1], self.bounds[2])
|
@@ -0,0 +1,19 @@
|
|
1
|
+
from dataclasses import dataclass, field
|
2
|
+
|
3
|
+
from ..controllers.basecontroller import BaseController
|
4
|
+
from .basepart import BasePart
|
5
|
+
from ...id import ID
|
6
|
+
|
7
|
+
|
8
|
+
@dataclass
|
9
|
+
class BaseInteractablePart(BasePart):
|
10
|
+
"""Base class for Interactable parts
|
11
|
+
"""
|
12
|
+
controller: BaseController = field(default_factory=BaseController)
|
13
|
+
|
14
|
+
def connect(self, o: "BaseInteractablePart"):
|
15
|
+
if not self.controller.controllers:
|
16
|
+
self.controller.controllers = []
|
17
|
+
|
18
|
+
self.controller.controllers.append(ID(o.controller.id))
|
19
|
+
return o
|
@@ -0,0 +1,13 @@
|
|
1
|
+
from dataclasses import dataclass, field
|
2
|
+
|
3
|
+
from .baseinteractablepart import BaseInteractablePart
|
4
|
+
from ..controllers.baselogiccontroller import BaseLogicController
|
5
|
+
|
6
|
+
|
7
|
+
@dataclass
|
8
|
+
class BaseLogicPart(BaseInteractablePart):
|
9
|
+
"""Base class for Logic parts with active state (mostly Logic Gate and Timer)
|
10
|
+
"""
|
11
|
+
controller: BaseLogicController = field(default_factory=BaseLogicController)
|
12
|
+
xaxis: int = field(kw_only=True, default=1)
|
13
|
+
zaxis: int = field(kw_only=True, default=-2)
|
@@ -0,0 +1,34 @@
|
|
1
|
+
from dataclasses import dataclass, field
|
2
|
+
|
3
|
+
from ...constants import AXIS, SHAPEID
|
4
|
+
from ...pos import Pos
|
5
|
+
|
6
|
+
|
7
|
+
@dataclass
|
8
|
+
class BasePart:
|
9
|
+
"""Base class for all in-game parts
|
10
|
+
"""
|
11
|
+
shapeId: str
|
12
|
+
pos: Pos
|
13
|
+
color: str
|
14
|
+
xaxis: int = field(kw_only=True, default=AXIS.DEFAULT_XAXIS)
|
15
|
+
zaxis: int = field(kw_only=True, default=AXIS.DEFAULT_ZAXIS)
|
16
|
+
|
17
|
+
def __post_init__(self):
|
18
|
+
# if pos given as {"x": ..., "y": ..., "z": ...} or (x, y, z) then convert to Pos class
|
19
|
+
if not isinstance(self.pos, Pos):
|
20
|
+
try:
|
21
|
+
self.pos = Pos(**self.pos)
|
22
|
+
except TypeError:
|
23
|
+
self.pos = Pos(self.pos[0], self.pos[1], self.pos[2])
|
24
|
+
# if color given as (r, g, b) then convert to hex string
|
25
|
+
if not isinstance(self.color, str):
|
26
|
+
self.color = "%02X%02X%02X" % (
|
27
|
+
self.color[0], self.color[1], self.color[2])
|
28
|
+
|
29
|
+
def __init_subclass__(cls):
|
30
|
+
super().__init_subclass__()
|
31
|
+
try:
|
32
|
+
SHAPEID.SHAPEID_TO_CLASS[cls.shapeId.default] = cls
|
33
|
+
except AttributeError:
|
34
|
+
pass
|
@@ -1,8 +1,8 @@
|
|
1
1
|
from dataclasses import dataclass, field
|
2
2
|
|
3
|
-
from bases.parts.basepart import BasePart
|
4
|
-
from body import Body
|
5
|
-
from constants import VERSION
|
3
|
+
from .bases.parts.basepart import BasePart
|
4
|
+
from .body import Body
|
5
|
+
from .constants import VERSION
|
6
6
|
|
7
7
|
|
8
8
|
@dataclass
|
@@ -0,0 +1,9 @@
|
|
1
|
+
from dataclasses import dataclass, field
|
2
|
+
|
3
|
+
from ..bases.parts.baseboundablepart import BaseBoundablePart
|
4
|
+
from ..constants import SHAPEID
|
5
|
+
|
6
|
+
|
7
|
+
@dataclass
|
8
|
+
class BarrierBlock(BaseBoundablePart):
|
9
|
+
shapeId: str = field(kw_only=True, default=SHAPEID.BARRIER_BLOCK)
|
@@ -0,0 +1,24 @@
|
|
1
|
+
from dataclasses import dataclass, field
|
2
|
+
|
3
|
+
from ..bases.parts.baselogicpart import BaseLogicPart
|
4
|
+
from ..bases.controllers.logicgatecontroller import LogicGateController
|
5
|
+
from ..constants import SHAPEID
|
6
|
+
|
7
|
+
|
8
|
+
@dataclass
|
9
|
+
class LogicGate(BaseLogicPart):
|
10
|
+
controller: LogicGateController = field(
|
11
|
+
default_factory=LogicGateController)
|
12
|
+
shapeId: str = field(kw_only=True, default=SHAPEID.LOGIC_GATE)
|
13
|
+
|
14
|
+
def __post_init__(self):
|
15
|
+
super().__post_init__()
|
16
|
+
# Can specify mode as a dict, a tuple (mode,) or just the parameter mode
|
17
|
+
if not isinstance(self.controller, LogicGateController):
|
18
|
+
try:
|
19
|
+
self.controller = LogicGateController(**self.controller)
|
20
|
+
except TypeError:
|
21
|
+
try:
|
22
|
+
self.controller = LogicGateController(*self.controller)
|
23
|
+
except TypeError:
|
24
|
+
self.controller = LogicGateController(self.controller)
|
@@ -0,0 +1,24 @@
|
|
1
|
+
from dataclasses import dataclass, field
|
2
|
+
|
3
|
+
from ..bases.controllers.sensorcontroller import SensorController
|
4
|
+
from ..bases.parts.baseinteractablepart import BaseInteractablePart
|
5
|
+
from ..constants import SHAPEID
|
6
|
+
|
7
|
+
|
8
|
+
@dataclass
|
9
|
+
class Sensor5(BaseInteractablePart):
|
10
|
+
controller: SensorController = field(
|
11
|
+
default_factory=SensorController)
|
12
|
+
shapeId: str = field(kw_only=True, default=SHAPEID.SENSOR5)
|
13
|
+
|
14
|
+
def __post_init__(self):
|
15
|
+
super().__post_init__()
|
16
|
+
# Can specify sensor controller as a dict, a tuple (audioEnable, buttonMode, color, colorMode, range) or just the parameter mode
|
17
|
+
if not isinstance(self.controller, SensorController):
|
18
|
+
try:
|
19
|
+
self.controller = SensorController(**self.controller)
|
20
|
+
except TypeError:
|
21
|
+
try:
|
22
|
+
self.controller = SensorController(*self.controller)
|
23
|
+
except TypeError:
|
24
|
+
self.controller = SensorController(self.controller)
|
@@ -0,0 +1,20 @@
|
|
1
|
+
from dataclasses import dataclass, field
|
2
|
+
|
3
|
+
from ..bases.controllers.timercontroller import TimerController
|
4
|
+
from ..bases.parts.baselogicpart import BaseLogicPart
|
5
|
+
from ..constants import SHAPEID
|
6
|
+
|
7
|
+
|
8
|
+
@dataclass
|
9
|
+
class Timer(BaseLogicPart):
|
10
|
+
controller: TimerController = field(default_factory=TimerController)
|
11
|
+
shapeId: str = field(kw_only=True, default=SHAPEID.TIMER)
|
12
|
+
|
13
|
+
def __post_init__(self):
|
14
|
+
super().__post_init__()
|
15
|
+
# Can provide seconds and ticks as a the TimerController class itself, a dict or a tuple (seconds, tick)
|
16
|
+
if not isinstance(self.controller, TimerController):
|
17
|
+
try:
|
18
|
+
self.controller = TimerController(**self.controller)
|
19
|
+
except TypeError:
|
20
|
+
self.controller = TimerController(*self.controller)
|
@@ -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 *
|
@@ -1,9 +1,9 @@
|
|
1
1
|
from typing import Sequence
|
2
2
|
from numpy import ndarray
|
3
|
-
from utils import get_bits_required, check_pos, connect, num_to_bit_list
|
4
|
-
from blueprint import Blueprint
|
5
|
-
from parts.logicgate import LogicGate
|
6
|
-
from pos import Pos
|
3
|
+
from ..utils import get_bits_required, check_pos, connect, num_to_bit_list
|
4
|
+
from ..blueprint import Blueprint
|
5
|
+
from ..parts.logicgate import LogicGate
|
6
|
+
from ..pos import Pos
|
7
7
|
|
8
8
|
|
9
9
|
def simple_adder_subtractor(bp: Blueprint,
|
{sm_blueprint_lib-0.0.5 → sm_blueprint_lib-0.0.7}/src/sm_blueprint_lib/prebuilds/barrel_shifter.py
RENAMED
@@ -1,9 +1,9 @@
|
|
1
1
|
from typing import Sequence
|
2
2
|
from numpy import ndarray
|
3
|
-
from utils import get_bits_required, check_pos, connect, num_to_bit_list
|
4
|
-
from blueprint import Blueprint
|
5
|
-
from parts.logicgate import LogicGate
|
6
|
-
from pos import Pos
|
3
|
+
from ..utils import get_bits_required, check_pos, connect, num_to_bit_list
|
4
|
+
from ..blueprint import Blueprint
|
5
|
+
from ..parts.logicgate import LogicGate
|
6
|
+
from ..pos import Pos
|
7
7
|
|
8
8
|
|
9
9
|
def barrel_shifter(bp: Blueprint, bit_length: int, num_bit_shift: int, pos: Pos | Sequence = (0, 0, 0)):
|
{sm_blueprint_lib-0.0.5 → sm_blueprint_lib-0.0.7}/src/sm_blueprint_lib/prebuilds/clock40hz.py
RENAMED
@@ -1,9 +1,9 @@
|
|
1
1
|
from typing import Sequence
|
2
2
|
from numpy import ndarray
|
3
|
-
from utils import get_bits_required, check_pos, connect, num_to_bit_list
|
4
|
-
from blueprint import Blueprint
|
5
|
-
from parts.logicgate import LogicGate
|
6
|
-
from pos import Pos
|
3
|
+
from ..utils import get_bits_required, check_pos, connect, num_to_bit_list
|
4
|
+
from ..blueprint import Blueprint
|
5
|
+
from ..parts.logicgate import LogicGate
|
6
|
+
from ..pos import Pos
|
7
7
|
|
8
8
|
|
9
9
|
def clock40hz(bp: Blueprint, bit_length: int, pos: Pos | Sequence = (0, 0, 0)):
|
{sm_blueprint_lib-0.0.5 → sm_blueprint_lib-0.0.7}/src/sm_blueprint_lib/prebuilds/comparator.py
RENAMED
@@ -1,9 +1,9 @@
|
|
1
1
|
from typing import Sequence
|
2
2
|
from numpy import ndarray
|
3
|
-
from utils import check_pos, connect
|
4
|
-
from blueprint import Blueprint
|
5
|
-
from parts.logicgate import LogicGate
|
6
|
-
from pos import Pos
|
3
|
+
from ..utils import check_pos, connect
|
4
|
+
from ..blueprint import Blueprint
|
5
|
+
from ..parts.logicgate import LogicGate
|
6
|
+
from ..pos import Pos
|
7
7
|
|
8
8
|
|
9
9
|
def comparator(bp: Blueprint,
|
@@ -1,9 +1,9 @@
|
|
1
1
|
from typing import Sequence
|
2
2
|
from numpy import ndarray
|
3
|
-
from utils import get_bits_required, check_pos, connect, num_to_bit_list
|
4
|
-
from blueprint import Blueprint
|
5
|
-
from parts.logicgate import LogicGate
|
6
|
-
from pos import Pos
|
3
|
+
from ..utils import get_bits_required, check_pos, connect, num_to_bit_list
|
4
|
+
from ..blueprint import Blueprint
|
5
|
+
from ..parts.logicgate import LogicGate
|
6
|
+
from ..pos import Pos
|
7
7
|
|
8
8
|
|
9
9
|
def counter(bp: Blueprint,
|
@@ -1,9 +1,9 @@
|
|
1
1
|
from typing import Sequence
|
2
2
|
from numpy import ndarray
|
3
|
-
from utils import get_bits_required, check_pos, connect, num_to_bit_list
|
4
|
-
from blueprint import Blueprint
|
5
|
-
from parts.logicgate import LogicGate
|
6
|
-
from pos import Pos
|
3
|
+
from ..utils import get_bits_required, check_pos, connect, num_to_bit_list
|
4
|
+
from ..blueprint import Blueprint
|
5
|
+
from ..parts.logicgate import LogicGate
|
6
|
+
from ..pos import Pos
|
7
7
|
|
8
8
|
|
9
9
|
def decoder(bp: Blueprint, num_address: int, pos: Pos | Sequence = (0, 0, 0),
|
{sm_blueprint_lib-0.0.5 → sm_blueprint_lib-0.0.7}/src/sm_blueprint_lib/prebuilds/distance_sensor.py
RENAMED
@@ -1,11 +1,11 @@
|
|
1
1
|
from typing import Sequence
|
2
2
|
from numpy import array, ndarray
|
3
|
-
from utils import get_bits_required, check_pos, connect, num_to_bit_list
|
4
|
-
from blueprint import Blueprint
|
5
|
-
from parts.logicgate import LogicGate
|
6
|
-
from parts.sensor import Sensor5
|
7
|
-
from parts.timer import Timer
|
8
|
-
from pos import Pos
|
3
|
+
from ..utils import get_bits_required, check_pos, connect, num_to_bit_list
|
4
|
+
from ..blueprint import Blueprint
|
5
|
+
from ..parts.logicgate import LogicGate
|
6
|
+
from ..parts.sensor import Sensor5
|
7
|
+
from ..parts.timer import Timer
|
8
|
+
from ..pos import Pos
|
9
9
|
|
10
10
|
|
11
11
|
def distance_sensor(bp: Blueprint,
|
@@ -1,11 +1,11 @@
|
|
1
1
|
from itertools import cycle
|
2
2
|
from typing import Sequence
|
3
3
|
from numpy import ndarray
|
4
|
-
from utils import get_bits_required, check_pos, connect
|
5
|
-
from blueprint import Blueprint
|
6
|
-
from parts.logicgate import LogicGate
|
7
|
-
from pos import Pos
|
8
|
-
from prebuilds.decoder import decoder
|
4
|
+
from ..utils import get_bits_required, check_pos, connect
|
5
|
+
from ..blueprint import Blueprint
|
6
|
+
from ..parts.logicgate import LogicGate
|
7
|
+
from ..pos import Pos
|
8
|
+
from ..prebuilds.decoder import decoder
|
9
9
|
|
10
10
|
|
11
11
|
def ram(bp: Blueprint, bit_length: int, num_address: int, pos: Pos | Sequence = (0, 0, 0),
|
{sm_blueprint_lib-0.0.5 → sm_blueprint_lib-0.0.7}/src/sm_blueprint_lib/prebuilds/register.py
RENAMED
@@ -1,10 +1,10 @@
|
|
1
1
|
from typing import Sequence
|
2
2
|
from numpy import ndarray
|
3
|
-
from utils import check_pos
|
4
|
-
from blueprint import Blueprint
|
5
|
-
from parts.logicgate import LogicGate
|
6
|
-
from pos import Pos
|
7
|
-
from prebuilds.counter import counter, counter_decrement
|
3
|
+
from ..utils import check_pos
|
4
|
+
from ..blueprint import Blueprint
|
5
|
+
from ..parts.logicgate import LogicGate
|
6
|
+
from ..pos import Pos
|
7
|
+
from ..prebuilds.counter import counter, counter_decrement
|
8
8
|
|
9
9
|
|
10
10
|
def register(bp: Blueprint,
|
@@ -2,12 +2,12 @@ from itertools import batched, cycle
|
|
2
2
|
from math import ceil
|
3
3
|
from typing import Sequence
|
4
4
|
from numpy import ndarray
|
5
|
-
from utils import get_bits_required, check_pos, connect, num_to_bit_list
|
6
|
-
from blueprint import Blueprint
|
7
|
-
from parts.logicgate import LogicGate
|
8
|
-
from prebuilds.decoder import decoder
|
9
|
-
from parts.timer import Timer
|
10
|
-
from pos import Pos
|
5
|
+
from ..utils import get_bits_required, check_pos, connect, num_to_bit_list
|
6
|
+
from ..blueprint import Blueprint
|
7
|
+
from ..parts.logicgate import LogicGate
|
8
|
+
from ..prebuilds.decoder import decoder
|
9
|
+
from ..parts.timer import Timer
|
10
|
+
from ..pos import Pos
|
11
11
|
|
12
12
|
|
13
13
|
def rom(
|
{sm_blueprint_lib-0.0.5 → sm_blueprint_lib-0.0.7}/src/sm_blueprint_lib/prebuilds/timer_ram_cached.py
RENAMED
@@ -1,19 +1,19 @@
|
|
1
1
|
from itertools import cycle
|
2
2
|
from typing import Sequence
|
3
3
|
from numpy import array, clip, ndarray
|
4
|
-
from utils import get_bits_required, check_pos, connect, num_to_bit_list
|
5
|
-
from bases.parts.baseinteractablepart import BaseInteractablePart
|
6
|
-
from bases.parts.baselogicpart import BaseLogicPart
|
7
|
-
from blueprint import Blueprint
|
8
|
-
from constants import TICKS_PER_SECOND
|
9
|
-
from parts.logicgate import LogicGate
|
10
|
-
from parts.timer import Timer
|
11
|
-
from pos import Pos
|
12
|
-
from prebuilds.clock40hz import clock40hz
|
13
|
-
from prebuilds.counter import counter
|
14
|
-
from prebuilds.decoder import decoder
|
15
|
-
from prebuilds.ram import ram
|
16
|
-
from prebuilds.register import register
|
4
|
+
from ..utils import get_bits_required, check_pos, connect, num_to_bit_list
|
5
|
+
from ..bases.parts.baseinteractablepart import BaseInteractablePart
|
6
|
+
from ..bases.parts.baselogicpart import BaseLogicPart
|
7
|
+
from ..blueprint import Blueprint
|
8
|
+
from ..constants import TICKS_PER_SECOND
|
9
|
+
from ..parts.logicgate import LogicGate
|
10
|
+
from ..parts.timer import Timer
|
11
|
+
from ..pos import Pos
|
12
|
+
from ..prebuilds.clock40hz import clock40hz
|
13
|
+
from ..prebuilds.counter import counter
|
14
|
+
from ..prebuilds.decoder import decoder
|
15
|
+
from ..prebuilds.ram import ram
|
16
|
+
from ..prebuilds.register import register
|
17
17
|
|
18
18
|
|
19
19
|
def timer_ram_cached(
|
@@ -1,14 +1,14 @@
|
|
1
1
|
from typing import Sequence
|
2
2
|
from numpy import ndarray
|
3
|
-
from utils import get_bits_required, check_pos, connect
|
4
|
-
from blueprint import Blueprint
|
5
|
-
from parts.logicgate import LogicGate
|
6
|
-
from parts.timer import Timer
|
7
|
-
from pos import Pos
|
8
|
-
from prebuilds.clock40hz import clock40hz
|
9
|
-
from prebuilds.decoder import decoder
|
10
|
-
from prebuilds.ram import ram
|
11
|
-
from prebuilds.register import register
|
3
|
+
from ..utils import get_bits_required, check_pos, connect
|
4
|
+
from ..blueprint import Blueprint
|
5
|
+
from ..parts.logicgate import LogicGate
|
6
|
+
from ..parts.timer import Timer
|
7
|
+
from ..pos import Pos
|
8
|
+
from ..prebuilds.clock40hz import clock40hz
|
9
|
+
from ..prebuilds.decoder import decoder
|
10
|
+
from ..prebuilds.ram import ram
|
11
|
+
from ..prebuilds.register import register
|
12
12
|
|
13
13
|
|
14
14
|
def timer_ram_multiclient(bp: Blueprint, bit_length: int, num_address: int, num_clients=1, pos: Pos | Sequence = (0, 0, 0)):
|
@@ -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(
|
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
|
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
|
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
|
|
@@ -2,7 +2,7 @@ from pprint import pp
|
|
2
2
|
|
3
3
|
from numpy import ndarray
|
4
4
|
|
5
|
-
from sm_blueprint_lib import Timer, LogicGate, BarrierBlock, Blueprint, save_blueprint,
|
5
|
+
from src.sm_blueprint_lib import Timer, LogicGate, BarrierBlock, Blueprint, save_blueprint, dump_string_from_blueprint, connect
|
6
6
|
|
7
7
|
size = 10
|
8
8
|
l0 = [
|
@@ -62,4 +62,4 @@ bp.add(l0, l1, l2, base, zero, l3)
|
|
62
62
|
|
63
63
|
print(len(bp.bodies[0].childs))
|
64
64
|
path = r"C:\Users\mauri\AppData\Roaming\Axolot Games\Scrap Mechanic\User\User_76561198400983548\Blueprints\c35f6e4e-52cb-4b00-8afa-f0ffd3fbb012\blueprint.json"
|
65
|
-
save_blueprint(
|
65
|
+
save_blueprint(bp, path)
|
@@ -4,21 +4,21 @@ from math import sin
|
|
4
4
|
from typing import Sequence
|
5
5
|
|
6
6
|
from numpy import array
|
7
|
-
from sm_blueprint_lib import Blueprint, connect, num_to_bit_list, save_blueprint
|
8
|
-
from sm_blueprint_lib.parts.logicgate import LogicGate
|
9
|
-
from sm_blueprint_lib.pos import Pos
|
10
|
-
from sm_blueprint_lib.prebuilds.adder import simple_adder_subtractor
|
11
|
-
from sm_blueprint_lib.prebuilds.barrel_shifter import barrel_shifter
|
12
|
-
from sm_blueprint_lib.prebuilds.clock40hz import clock40hz
|
13
|
-
from sm_blueprint_lib.prebuilds.comparator import comparator
|
14
|
-
from sm_blueprint_lib.prebuilds.counter import counter
|
15
|
-
from sm_blueprint_lib.prebuilds.distance_sensor import distance_sensor, distance_sensor_raycast
|
16
|
-
from sm_blueprint_lib.prebuilds.ram import ram
|
17
|
-
from sm_blueprint_lib.prebuilds.decoder import decoder
|
18
|
-
from sm_blueprint_lib.prebuilds.register import counter_register, register
|
19
|
-
from sm_blueprint_lib.prebuilds.rom import rom
|
20
|
-
from sm_blueprint_lib.prebuilds.timer_ram_multiclient import timer_ram_multiclient
|
21
|
-
from sm_blueprint_lib.prebuilds.timer_ram_cached import timer_ram_cached
|
7
|
+
from src.sm_blueprint_lib import Blueprint, connect, num_to_bit_list, save_blueprint
|
8
|
+
from src.sm_blueprint_lib.parts.logicgate import LogicGate
|
9
|
+
from src.sm_blueprint_lib.pos import Pos
|
10
|
+
from src.sm_blueprint_lib.prebuilds.adder import simple_adder_subtractor
|
11
|
+
from src.sm_blueprint_lib.prebuilds.barrel_shifter import barrel_shifter
|
12
|
+
from src.sm_blueprint_lib.prebuilds.clock40hz import clock40hz
|
13
|
+
from src.sm_blueprint_lib.prebuilds.comparator import comparator
|
14
|
+
from src.sm_blueprint_lib.prebuilds.counter import counter
|
15
|
+
from src.sm_blueprint_lib.prebuilds.distance_sensor import distance_sensor, distance_sensor_raycast
|
16
|
+
from src.sm_blueprint_lib.prebuilds.ram import ram
|
17
|
+
from src.sm_blueprint_lib.prebuilds.decoder import decoder
|
18
|
+
from src.sm_blueprint_lib.prebuilds.register import counter_register, register
|
19
|
+
from src.sm_blueprint_lib.prebuilds.rom import rom
|
20
|
+
from src.sm_blueprint_lib.prebuilds.timer_ram_multiclient import timer_ram_multiclient
|
21
|
+
from src.sm_blueprint_lib.prebuilds.timer_ram_cached import timer_ram_cached
|
22
22
|
|
23
23
|
|
24
24
|
bp = Blueprint()
|
@@ -86,4 +86,4 @@ timer_ram_cached(bp,
|
|
86
86
|
|
87
87
|
print(f"Prebuild size: {len(bp.bodies[0].childs)} parts")
|
88
88
|
path = r"C:\Users\mauri\AppData\Roaming\Axolot Games\Scrap Mechanic\User\User_76561198400983548\Blueprints\c35f6e4e-52cb-4b00-8afa-f0ffd3fbb012\blueprint.json"
|
89
|
-
save_blueprint(
|
89
|
+
save_blueprint(bp, path)
|
@@ -2,7 +2,7 @@ import json
|
|
2
2
|
from pprint import pp
|
3
3
|
|
4
4
|
|
5
|
-
from sm_blueprint_lib import load_blueprint, save_blueprint,
|
5
|
+
from src.sm_blueprint_lib import load_blueprint, save_blueprint, load_blueprint_from_string
|
6
6
|
# from sm.bases.controllers.basecontroller import BaseController
|
7
7
|
# from sm.bases.controllers.baselogiccontroller import BaseLogicController
|
8
8
|
# from sm.bases.parts.baselogicpart import BaseLogicPart
|
@@ -13,8 +13,8 @@ from sm_blueprint_lib import load_blueprint, save_blueprint, load_string
|
|
13
13
|
# import sm.parts.barrierblock
|
14
14
|
# from dataclasses import asdict
|
15
15
|
|
16
|
-
from sm_blueprint_lib.constants import SHAPEID
|
17
|
-
from sm_blueprint_lib.parts.sensor import Sensor5
|
16
|
+
from src.sm_blueprint_lib.constants import SHAPEID
|
17
|
+
from src.sm_blueprint_lib.parts.sensor import Sensor5
|
18
18
|
# from sm.bases.parts.baseinteractablepart import BaseInteractablePart
|
19
19
|
# from sm.parts.logicgate import LogicGate
|
20
20
|
|
@@ -61,7 +61,7 @@ with open(path) as fp:
|
|
61
61
|
|
62
62
|
|
63
63
|
j = '{"bodies":[{"childs":[{"bounds":{"x":2,"y":2,"z":1},"color":"CE9E0C","pos":{"x":-13,"y":-7,"z":2},"shapeId":"09ca2713-28ee-4119-9622-e85490034758","xaxis":1,"zaxis":3},{"color":"DF7F01","controller":{"active":false,"controllers":[{"id":7227441}],"id":7227439,"joints":null,"seconds":2,"ticks":1},"pos":{"x":-12,"y":-5,"z":3},"shapeId":"8f7fd0e7-c46e-4944-a414-7ce2437bb30f","xaxis":1,"zaxis":-2},{"color":"DF7F01","controller":{"active":true,"controllers":[{"id":7227439}],"id":7227440,"joints":null,"mode":3},"pos":{"x":-12,"y":-6,"z":3},"shapeId":"9f0f56e8-2c31-4d83-996c-d00a9b296c3f","xaxis":1,"zaxis":-2},{"color":"DF7F01","controller":{"active":false,"controllers":[{"id":7227440}],"id":7227441,"joints":null,"mode":0},"pos":{"x":-13,"y":-6,"z":3},"shapeId":"9f0f56e8-2c31-4d83-996c-d00a9b296c3f","xaxis":1,"zaxis":-2}]}],"version":4}'
|
64
|
-
bp =
|
64
|
+
bp = load_blueprint_from_string(j)
|
65
65
|
pp(bp)
|
66
66
|
|
67
67
|
pp(Sensor5((1,2,3), (255,255,255), (False, True, (255,0,0), False, 1)))
|
@@ -115,7 +115,7 @@ pp(Sensor5((1,2,3), (255,255,255), (False, True, (255,0,0), False, 1)))
|
|
115
115
|
# bp = load_blueprint(path)
|
116
116
|
# pp(bp)
|
117
117
|
# pp(json.dumps(asdict(bp)))
|
118
|
-
# save_blueprint(
|
118
|
+
# save_blueprint(bp, path)
|
119
119
|
|
120
120
|
# pp(sm.constants.SHAPEID.SHAPEID_TO_CLASS)
|
121
121
|
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|