logic-arrows-lac 0.1.0__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.
- logic_arrows_lac-0.1.0/MANIFEST.in +3 -0
- logic_arrows_lac-0.1.0/PKG-INFO +269 -0
- logic_arrows_lac-0.1.0/README.md +255 -0
- logic_arrows_lac-0.1.0/examples/create_circuit.py +33 -0
- logic_arrows_lac-0.1.0/examples/runtime_test.py +34 -0
- logic_arrows_lac-0.1.0/pyproject.toml +34 -0
- logic_arrows_lac-0.1.0/setup.cfg +4 -0
- logic_arrows_lac-0.1.0/src/lac/__init__.py +1034 -0
- logic_arrows_lac-0.1.0/src/lac/headless/build.bat +19 -0
- logic_arrows_lac-0.1.0/src/lac/headless/build.sh +12 -0
- logic_arrows_lac-0.1.0/src/lac/headless/lasim.cpp +459 -0
- logic_arrows_lac-0.1.0/src/lac/headless/stub/glad.h +0 -0
- logic_arrows_lac-0.1.0/src/lac/headless/stub/raylib.h +90 -0
- logic_arrows_lac-0.1.0/src/lac/headless/stub/raymath.h +1 -0
- logic_arrows_lac-0.1.0/src/lac/headless/stub/rlgl.h +0 -0
- logic_arrows_lac-0.1.0/src/logic_arrows_lac.egg-info/PKG-INFO +269 -0
- logic_arrows_lac-0.1.0/src/logic_arrows_lac.egg-info/SOURCES.txt +17 -0
- logic_arrows_lac-0.1.0/src/logic_arrows_lac.egg-info/dependency_links.txt +1 -0
- logic_arrows_lac-0.1.0/src/logic_arrows_lac.egg-info/top_level.txt +1 -0
|
@@ -0,0 +1,269 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: logic-arrows-lac
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Python blueprint builder and headless simulation interface for Logic Arrows 3D
|
|
5
|
+
Keywords: logic-arrows-3d,blueprint,circuit,simulation
|
|
6
|
+
Classifier: Development Status :: 3 - Alpha
|
|
7
|
+
Classifier: Intended Audience :: Developers
|
|
8
|
+
Classifier: Operating System :: OS Independent
|
|
9
|
+
Classifier: Programming Language :: Python :: 3
|
|
10
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
11
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
12
|
+
Requires-Python: >=3.9
|
|
13
|
+
Description-Content-Type: text/markdown
|
|
14
|
+
|
|
15
|
+
# Logic Arrows 3D — Python blueprint API + headless simulator
|
|
16
|
+
|
|
17
|
+
This folder lets you create native `.labp` blueprints with Python and optionally run the game's real C++ simulation without launching the graphical game. The game source itself is not modified.
|
|
18
|
+
|
|
19
|
+
## Install from PyPI
|
|
20
|
+
|
|
21
|
+
Once published, install the Python API with:
|
|
22
|
+
|
|
23
|
+
```powershell
|
|
24
|
+
py -m pip install logic-arrows-lac
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
Then import it as `lac` (the PyPI distribution name and Python import name are allowed to differ):
|
|
28
|
+
|
|
29
|
+
```python
|
|
30
|
+
from lac import Blueprint, Block, Dir
|
|
31
|
+
|
|
32
|
+
bp = Blueprint()
|
|
33
|
+
bp.place(Block.SOURCE, (0, 0, 0))
|
|
34
|
+
bp.wire((1, 0, 0), (5, 0, 0), end=Dir.X)
|
|
35
|
+
bp.place(Block.BULB, (6, 0, 0))
|
|
36
|
+
bp.save("my_circuit.labp")
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
The package has no third-party runtime Python dependencies; blueprint creation and `.labp` writing use the Python standard library.
|
|
40
|
+
|
|
41
|
+
## Package contents
|
|
42
|
+
|
|
43
|
+
The installed Python package includes the headless C++ runner source, build scripts, and graphics stub headers. It does **not** bundle a precompiled `lasim` executable: that executable must be built against the matching Logic Arrows 3D game headers on the machine where it will run. Creating and saving `.labp` files does not require a C++ compiler or game source headers.
|
|
44
|
+
|
|
45
|
+
For development, the project source tree is:
|
|
46
|
+
|
|
47
|
+
```text
|
|
48
|
+
logic-arrows-lac/
|
|
49
|
+
pyproject.toml
|
|
50
|
+
README.md
|
|
51
|
+
MANIFEST.in
|
|
52
|
+
src/
|
|
53
|
+
lac/
|
|
54
|
+
__init__.py
|
|
55
|
+
headless/
|
|
56
|
+
lasim.cpp
|
|
57
|
+
build.bat
|
|
58
|
+
build.sh
|
|
59
|
+
stub/
|
|
60
|
+
examples/
|
|
61
|
+
create_circuit.py
|
|
62
|
+
runtime_test.py
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
## Build the headless simulator (Windows, Linux and macOS)
|
|
66
|
+
|
|
67
|
+
Requirements:
|
|
68
|
+
|
|
69
|
+
- Python installed with this package.
|
|
70
|
+
- A C++20 MinGW-w64 `g++` compiler on Windows (or g++ on Linux/macOS).
|
|
71
|
+
- zlib development headers and library.
|
|
72
|
+
- The matching Logic Arrows 3D source `include` directory.
|
|
73
|
+
|
|
74
|
+
Find the installed headless folder with:
|
|
75
|
+
|
|
76
|
+
```powershell
|
|
77
|
+
py -c "import lac; from pathlib import Path; print(Path(lac.__file__).parent / 'headless')"
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
For example, assign that printed path to `$headless`, then build into your current project folder so you do not need to write into Python's installation directory:
|
|
81
|
+
|
|
82
|
+
```powershell
|
|
83
|
+
$headless = py -c "import lac; from pathlib import Path; print(Path(lac.__file__).parent / 'headless')"
|
|
84
|
+
& "$headless\build.bat" "C:\path\to\Logic Arrows 3D\include" ".\lasim.exe"
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
On Linux/macOS, use the packaged `build.sh` similarly, supplying the game include path and an output executable path. The script compiles against the game's headers and uses the packaged graphics stub headers. The simulation logic comes from the game's actual `World` and `BlueprintManager` code.
|
|
88
|
+
|
|
89
|
+
If your game project is still inside a ZIP, extract it first. Pass the path to the extracted `include` directory, not the project root and not the `src` directory.
|
|
90
|
+
|
|
91
|
+
## Create a `.labp` blueprint with Python
|
|
92
|
+
|
|
93
|
+
Run the included non-test example from this folder after installing the package (or running `py -m pip install -e .` from the project root):
|
|
94
|
+
|
|
95
|
+
```powershell
|
|
96
|
+
python .\examples\create_circuit.py .\output\source_to_bulb.labp
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
It creates a source, a line of arrows, and a bulb. `output` is created automatically by `Blueprint.save()`.
|
|
100
|
+
|
|
101
|
+
Or create your own Python script after installing the package:
|
|
102
|
+
|
|
103
|
+
```python
|
|
104
|
+
from lac import Blueprint, Block, Dir
|
|
105
|
+
|
|
106
|
+
bp = Blueprint()
|
|
107
|
+
bp.place(Block.SOURCE, (0, 0, 0))
|
|
108
|
+
bp.wire((1, 0, 0), (5, 0, 0), end=Dir.X)
|
|
109
|
+
bp.place(Block.BULB, (6, 0, 0))
|
|
110
|
+
bp.save("my_circuit.labp")
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
Coordinates are `(x, y, z)`, with `y` vertical. Blueprint coordinates must be non-negative. `Dir.X`, `Dir.Z`, `Dir.NX`, `Dir.NZ`, `Dir.Y`, and `Dir.NY` specify the six directions.
|
|
114
|
+
|
|
115
|
+
## Use the `.labp` in the actual game
|
|
116
|
+
|
|
117
|
+
The game looks for blueprints in its `blueprints` folder (relative to the game's working directory):
|
|
118
|
+
|
|
119
|
+
1. Copy the generated `.labp` file into `<game working directory>\blueprints\`.
|
|
120
|
+
2. Launch the game and open the blueprint picker with the backtick key (`).
|
|
121
|
+
3. Select your blueprint. The game loads it into the placement preview.
|
|
122
|
+
4. Aim and click the left mouse button to place it. Hold Left Shift to move the preview; right-click or Backspace cancels.
|
|
123
|
+
|
|
124
|
+
The `.labp` is the native file the game loads. A `.tests.json` file is not required to place a blueprint in the game.
|
|
125
|
+
|
|
126
|
+
## Main Python building API
|
|
127
|
+
|
|
128
|
+
### Place blocks
|
|
129
|
+
|
|
130
|
+
```python
|
|
131
|
+
bp.place(Block.ARROW, (1, 0, 0), facing=Dir.X)
|
|
132
|
+
bp.place(Block.CAPACITOR, (2, 0, 0), N=10, K=2)
|
|
133
|
+
bp.place(Block.PULSE_STRETCHER, (3, 0, 0), D=8)
|
|
134
|
+
bp.place(Block.KEY_BUTTON, (4, 0, 0), facing=Dir.X, key=65) # A key
|
|
135
|
+
bp.place(Block.BULB, (5, 0, 0), roll=1, mirrored=True)
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
Available block names are:
|
|
139
|
+
|
|
140
|
+
`ARROW`, `SOURCE`, `DETECTOR`, `BLUE_ARROW`, `BLOCKER`, `I_SPLITTER`, `T_SPLITTER`, `L_SPLITTER`, `DIAGONAL_ARROW`, `AND`, `NOT`, `XOR`, `TRANSMITTER`, `LATCH`, `BLUE_I_SPLITTER`, `BLUE_L_SPLITTER`, `DIAGONAL_SPLITTER`, `TFLIPFLOP`, `DELAY_ARROW`, `PULSE_GENERATOR` (alias `PULSE`), `DIRECTIONAL_BUTTON`, `QUAD_BUTTON`, `KEY_BUTTON`, `LIGHT_BULB` (alias `BULB`), `CONNECTIVE_LIGHT_BULB`, `INTERVAL_BLOCK`, `DIAGONAL_BLOCKER`, `LINKED_ARROW`, `WALL`, `CAPACITOR`, `PULSE_STRETCHER`, `PALETTE_BULB`, and `MIXER`.
|
|
141
|
+
|
|
142
|
+
Block-specific options are validated by `place()`: `N`/`K` for capacitors, `D` for pulse stretchers, `key` for key buttons, `cover_tile` and `fill` for bulbs, `fill` for walls, and `palette` for palette bulbs. `roll` is 0–3; `mirrored` is a boolean.
|
|
143
|
+
|
|
144
|
+
### Block orientation: `facing`, `roll`, and `mirrored`
|
|
145
|
+
|
|
146
|
+
`facing` sets a block's forward direction. Use one of the six `Dir` values:
|
|
147
|
+
|
|
148
|
+
- `Dir.X`: +X
|
|
149
|
+
- `Dir.Z`: +Z
|
|
150
|
+
- `Dir.NX`: -X
|
|
151
|
+
- `Dir.NZ`: -Z
|
|
152
|
+
- `Dir.Y`: +Y (up)
|
|
153
|
+
- `Dir.NY`: -Y (down)
|
|
154
|
+
|
|
155
|
+
For blocks with a rotatable lateral axis, `roll` rotates that axis around the forward direction in 90-degree steps:
|
|
156
|
+
|
|
157
|
+
| `roll` | Lateral direction |
|
|
158
|
+
|---:|---|
|
|
159
|
+
| `0` | local right |
|
|
160
|
+
| `1` | local up |
|
|
161
|
+
| `2` | local left (negative local right) |
|
|
162
|
+
| `3` | local down (negative local up) |
|
|
163
|
+
|
|
164
|
+
The local right/up directions depend on `facing`:
|
|
165
|
+
|
|
166
|
+
| `facing` | `roll=0` (right) | `roll=1` (up) |
|
|
167
|
+
|---|---|---|
|
|
168
|
+
| `Dir.X` (+X) | +Z | +Y |
|
|
169
|
+
| `Dir.Z` (+Z) | -X | +Y |
|
|
170
|
+
| `Dir.NX` (-X) | -Z | +Y |
|
|
171
|
+
| `Dir.NZ` (-Z) | +X | +Y |
|
|
172
|
+
| `Dir.Y` (+Y) | +Z | -X |
|
|
173
|
+
| `Dir.NY` (-Y) | +Z | +X |
|
|
174
|
+
|
|
175
|
+
For `roll=2` or `roll=3`, use the opposite of the corresponding table direction. `mirrored=True` reverses the lateral direction again, without changing the forward direction.
|
|
176
|
+
|
|
177
|
+
`roll` changes simulation routing for `BLUE_ARROW`, `BLUE_I_SPLITTER`, `BLUE_L_SPLITTER`, `DIAGONAL_ARROW`, `DIAGONAL_SPLITTER`, and `DIAGONAL_BLOCKER`. For diagonal blocks, the target offset is the forward step plus the selected lateral step.
|
|
178
|
+
|
|
179
|
+
**Diagonal blocker example** — at `(10, 10, 10)`, facing +X:
|
|
180
|
+
|
|
181
|
+
```python
|
|
182
|
+
# Forward +X, lateral +Z: blocks (11, 10, 11)
|
|
183
|
+
bp.place(Block.DIAGONAL_BLOCKER, (10, 10, 10), facing=Dir.X, roll=0)
|
|
184
|
+
|
|
185
|
+
# Forward +X, lateral +Y: blocks (11, 11, 10)
|
|
186
|
+
bp.place(Block.DIAGONAL_BLOCKER, (10, 10, 10), facing=Dir.X, roll=1)
|
|
187
|
+
|
|
188
|
+
# Mirroring reverses the lateral step: blocks (11, 10, 9)
|
|
189
|
+
bp.place(
|
|
190
|
+
Block.DIAGONAL_BLOCKER,
|
|
191
|
+
(10, 10, 10),
|
|
192
|
+
facing=Dir.X,
|
|
193
|
+
roll=0,
|
|
194
|
+
mirrored=True,
|
|
195
|
+
)
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
**Diagonal signal blocks** use the same orientation rule:
|
|
199
|
+
|
|
200
|
+
```python
|
|
201
|
+
# Sends along the diagonal target (forward + lateral)
|
|
202
|
+
bp.place(Block.DIAGONAL_ARROW, (0, 0, 0), facing=Dir.X, roll=0)
|
|
203
|
+
|
|
204
|
+
# Splitter sends one output forward and another forward + lateral
|
|
205
|
+
bp.place(Block.DIAGONAL_SPLITTER, (0, 0, 0), facing=Dir.X, roll=0)
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
For the examples above, `Dir.X` with `roll=0` makes the diagonal branch point toward +X/+Z; setting `mirrored=True` makes it +X/-Z. Change `facing` and `roll` to orient the diagonal in other planes.
|
|
209
|
+
|
|
210
|
+
### Lay wires and splitters
|
|
211
|
+
|
|
212
|
+
```python
|
|
213
|
+
bp.wire((1, 0, 0), (5, 0, 0), end=Dir.X)
|
|
214
|
+
bp.split((6, 0, 0), Dir.X, [Dir.X, Dir.Y])
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
`wire()` fills each cell between listed points with arrows; each segment must be straight along one axis. `split()` chooses a supported splitter orientation from the requested output directions.
|
|
218
|
+
|
|
219
|
+
### Add links and palettes
|
|
220
|
+
|
|
221
|
+
```python
|
|
222
|
+
bp.place(Block.LINKED_ARROW, (0, 0, 2), facing=Dir.X)
|
|
223
|
+
bp.place(Block.LINKED_ARROW, (8, 0, 2), facing=Dir.X)
|
|
224
|
+
bp.link((0, 0, 2), (8, 0, 2))
|
|
225
|
+
|
|
226
|
+
palette_id = bp.add_palette([
|
|
227
|
+
(255, 80, 80, 255),
|
|
228
|
+
(80, 160, 255, 255),
|
|
229
|
+
])
|
|
230
|
+
bp.place(Block.PALETTE_BULB, (9, 0, 2), palette=palette_id)
|
|
231
|
+
bp.save("linked_palette_demo.labp")
|
|
232
|
+
```
|
|
233
|
+
|
|
234
|
+
`bp.link(source, target)` validates supported link types and graph constraints. Palette bulbs and mixers can be linked to mixers according to the game's link rules.
|
|
235
|
+
|
|
236
|
+
### Save
|
|
237
|
+
|
|
238
|
+
```python
|
|
239
|
+
path = bp.save("my_circuit.labp")
|
|
240
|
+
print(path)
|
|
241
|
+
```
|
|
242
|
+
|
|
243
|
+
`save()` writes the native Base64-wrapped binary `.labp`. It does not launch the game and does not need the headless executable. If probes, scheduled actions or assertions are present, `save()` also writes a separate `.tests.json` sidecar; the game ignores that sidecar.
|
|
244
|
+
|
|
245
|
+
## Run a circuit without opening the game
|
|
246
|
+
|
|
247
|
+
After building the runner, run a saved blueprint directly:
|
|
248
|
+
|
|
249
|
+
```powershell
|
|
250
|
+
.\lasim.exe .\output\source_to_bulb.labp 100
|
|
251
|
+
```
|
|
252
|
+
|
|
253
|
+
The final number is the number of simulation ticks. This loads the `.labp`, constructs the real simulation `World`, and calls `World::Tick()` repeatedly. It does not render a window.
|
|
254
|
+
|
|
255
|
+
To inspect signal changes, add named probes in the Python script before saving:
|
|
256
|
+
|
|
257
|
+
```python
|
|
258
|
+
bp.probe("source", (0, 0, 0))
|
|
259
|
+
bp.probe("lamp", (6, 0, 0))
|
|
260
|
+
bp.save("output/source_to_bulb.labp")
|
|
261
|
+
```
|
|
262
|
+
|
|
263
|
+
Then run the headless command. It prints a trace line when a probed state changes. `probe()` is just trace output; it does not create an assertion or change the `.labp` circuit.
|
|
264
|
+
|
|
265
|
+
You can also call `bp.run(ticks=100, runner=r".\lasim.exe")` from Python after the runner has been built. The `runner` argument is useful when you built the executable outside the installed package. It returns a `SimulationResult` with `.trace`, `.stdout`, and `.stderr`.
|
|
266
|
+
|
|
267
|
+
## Runtime tests (optional)
|
|
268
|
+
|
|
269
|
+
Runtime tests are optional and are separate from creating/placing a blueprint. See `examples/runtime_test.py` and the test API section in the previous headless README if you want assertions and scheduled inputs.
|
|
@@ -0,0 +1,255 @@
|
|
|
1
|
+
# Logic Arrows 3D — Python blueprint API + headless simulator
|
|
2
|
+
|
|
3
|
+
This folder lets you create native `.labp` blueprints with Python and optionally run the game's real C++ simulation without launching the graphical game. The game source itself is not modified.
|
|
4
|
+
|
|
5
|
+
## Install from PyPI
|
|
6
|
+
|
|
7
|
+
Once published, install the Python API with:
|
|
8
|
+
|
|
9
|
+
```powershell
|
|
10
|
+
py -m pip install logic-arrows-lac
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
Then import it as `lac` (the PyPI distribution name and Python import name are allowed to differ):
|
|
14
|
+
|
|
15
|
+
```python
|
|
16
|
+
from lac import Blueprint, Block, Dir
|
|
17
|
+
|
|
18
|
+
bp = Blueprint()
|
|
19
|
+
bp.place(Block.SOURCE, (0, 0, 0))
|
|
20
|
+
bp.wire((1, 0, 0), (5, 0, 0), end=Dir.X)
|
|
21
|
+
bp.place(Block.BULB, (6, 0, 0))
|
|
22
|
+
bp.save("my_circuit.labp")
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
The package has no third-party runtime Python dependencies; blueprint creation and `.labp` writing use the Python standard library.
|
|
26
|
+
|
|
27
|
+
## Package contents
|
|
28
|
+
|
|
29
|
+
The installed Python package includes the headless C++ runner source, build scripts, and graphics stub headers. It does **not** bundle a precompiled `lasim` executable: that executable must be built against the matching Logic Arrows 3D game headers on the machine where it will run. Creating and saving `.labp` files does not require a C++ compiler or game source headers.
|
|
30
|
+
|
|
31
|
+
For development, the project source tree is:
|
|
32
|
+
|
|
33
|
+
```text
|
|
34
|
+
logic-arrows-lac/
|
|
35
|
+
pyproject.toml
|
|
36
|
+
README.md
|
|
37
|
+
MANIFEST.in
|
|
38
|
+
src/
|
|
39
|
+
lac/
|
|
40
|
+
__init__.py
|
|
41
|
+
headless/
|
|
42
|
+
lasim.cpp
|
|
43
|
+
build.bat
|
|
44
|
+
build.sh
|
|
45
|
+
stub/
|
|
46
|
+
examples/
|
|
47
|
+
create_circuit.py
|
|
48
|
+
runtime_test.py
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
## Build the headless simulator (Windows, Linux and macOS)
|
|
52
|
+
|
|
53
|
+
Requirements:
|
|
54
|
+
|
|
55
|
+
- Python installed with this package.
|
|
56
|
+
- A C++20 MinGW-w64 `g++` compiler on Windows (or g++ on Linux/macOS).
|
|
57
|
+
- zlib development headers and library.
|
|
58
|
+
- The matching Logic Arrows 3D source `include` directory.
|
|
59
|
+
|
|
60
|
+
Find the installed headless folder with:
|
|
61
|
+
|
|
62
|
+
```powershell
|
|
63
|
+
py -c "import lac; from pathlib import Path; print(Path(lac.__file__).parent / 'headless')"
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
For example, assign that printed path to `$headless`, then build into your current project folder so you do not need to write into Python's installation directory:
|
|
67
|
+
|
|
68
|
+
```powershell
|
|
69
|
+
$headless = py -c "import lac; from pathlib import Path; print(Path(lac.__file__).parent / 'headless')"
|
|
70
|
+
& "$headless\build.bat" "C:\path\to\Logic Arrows 3D\include" ".\lasim.exe"
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
On Linux/macOS, use the packaged `build.sh` similarly, supplying the game include path and an output executable path. The script compiles against the game's headers and uses the packaged graphics stub headers. The simulation logic comes from the game's actual `World` and `BlueprintManager` code.
|
|
74
|
+
|
|
75
|
+
If your game project is still inside a ZIP, extract it first. Pass the path to the extracted `include` directory, not the project root and not the `src` directory.
|
|
76
|
+
|
|
77
|
+
## Create a `.labp` blueprint with Python
|
|
78
|
+
|
|
79
|
+
Run the included non-test example from this folder after installing the package (or running `py -m pip install -e .` from the project root):
|
|
80
|
+
|
|
81
|
+
```powershell
|
|
82
|
+
python .\examples\create_circuit.py .\output\source_to_bulb.labp
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
It creates a source, a line of arrows, and a bulb. `output` is created automatically by `Blueprint.save()`.
|
|
86
|
+
|
|
87
|
+
Or create your own Python script after installing the package:
|
|
88
|
+
|
|
89
|
+
```python
|
|
90
|
+
from lac import Blueprint, Block, Dir
|
|
91
|
+
|
|
92
|
+
bp = Blueprint()
|
|
93
|
+
bp.place(Block.SOURCE, (0, 0, 0))
|
|
94
|
+
bp.wire((1, 0, 0), (5, 0, 0), end=Dir.X)
|
|
95
|
+
bp.place(Block.BULB, (6, 0, 0))
|
|
96
|
+
bp.save("my_circuit.labp")
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
Coordinates are `(x, y, z)`, with `y` vertical. Blueprint coordinates must be non-negative. `Dir.X`, `Dir.Z`, `Dir.NX`, `Dir.NZ`, `Dir.Y`, and `Dir.NY` specify the six directions.
|
|
100
|
+
|
|
101
|
+
## Use the `.labp` in the actual game
|
|
102
|
+
|
|
103
|
+
The game looks for blueprints in its `blueprints` folder (relative to the game's working directory):
|
|
104
|
+
|
|
105
|
+
1. Copy the generated `.labp` file into `<game working directory>\blueprints\`.
|
|
106
|
+
2. Launch the game and open the blueprint picker with the backtick key (`).
|
|
107
|
+
3. Select your blueprint. The game loads it into the placement preview.
|
|
108
|
+
4. Aim and click the left mouse button to place it. Hold Left Shift to move the preview; right-click or Backspace cancels.
|
|
109
|
+
|
|
110
|
+
The `.labp` is the native file the game loads. A `.tests.json` file is not required to place a blueprint in the game.
|
|
111
|
+
|
|
112
|
+
## Main Python building API
|
|
113
|
+
|
|
114
|
+
### Place blocks
|
|
115
|
+
|
|
116
|
+
```python
|
|
117
|
+
bp.place(Block.ARROW, (1, 0, 0), facing=Dir.X)
|
|
118
|
+
bp.place(Block.CAPACITOR, (2, 0, 0), N=10, K=2)
|
|
119
|
+
bp.place(Block.PULSE_STRETCHER, (3, 0, 0), D=8)
|
|
120
|
+
bp.place(Block.KEY_BUTTON, (4, 0, 0), facing=Dir.X, key=65) # A key
|
|
121
|
+
bp.place(Block.BULB, (5, 0, 0), roll=1, mirrored=True)
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
Available block names are:
|
|
125
|
+
|
|
126
|
+
`ARROW`, `SOURCE`, `DETECTOR`, `BLUE_ARROW`, `BLOCKER`, `I_SPLITTER`, `T_SPLITTER`, `L_SPLITTER`, `DIAGONAL_ARROW`, `AND`, `NOT`, `XOR`, `TRANSMITTER`, `LATCH`, `BLUE_I_SPLITTER`, `BLUE_L_SPLITTER`, `DIAGONAL_SPLITTER`, `TFLIPFLOP`, `DELAY_ARROW`, `PULSE_GENERATOR` (alias `PULSE`), `DIRECTIONAL_BUTTON`, `QUAD_BUTTON`, `KEY_BUTTON`, `LIGHT_BULB` (alias `BULB`), `CONNECTIVE_LIGHT_BULB`, `INTERVAL_BLOCK`, `DIAGONAL_BLOCKER`, `LINKED_ARROW`, `WALL`, `CAPACITOR`, `PULSE_STRETCHER`, `PALETTE_BULB`, and `MIXER`.
|
|
127
|
+
|
|
128
|
+
Block-specific options are validated by `place()`: `N`/`K` for capacitors, `D` for pulse stretchers, `key` for key buttons, `cover_tile` and `fill` for bulbs, `fill` for walls, and `palette` for palette bulbs. `roll` is 0–3; `mirrored` is a boolean.
|
|
129
|
+
|
|
130
|
+
### Block orientation: `facing`, `roll`, and `mirrored`
|
|
131
|
+
|
|
132
|
+
`facing` sets a block's forward direction. Use one of the six `Dir` values:
|
|
133
|
+
|
|
134
|
+
- `Dir.X`: +X
|
|
135
|
+
- `Dir.Z`: +Z
|
|
136
|
+
- `Dir.NX`: -X
|
|
137
|
+
- `Dir.NZ`: -Z
|
|
138
|
+
- `Dir.Y`: +Y (up)
|
|
139
|
+
- `Dir.NY`: -Y (down)
|
|
140
|
+
|
|
141
|
+
For blocks with a rotatable lateral axis, `roll` rotates that axis around the forward direction in 90-degree steps:
|
|
142
|
+
|
|
143
|
+
| `roll` | Lateral direction |
|
|
144
|
+
|---:|---|
|
|
145
|
+
| `0` | local right |
|
|
146
|
+
| `1` | local up |
|
|
147
|
+
| `2` | local left (negative local right) |
|
|
148
|
+
| `3` | local down (negative local up) |
|
|
149
|
+
|
|
150
|
+
The local right/up directions depend on `facing`:
|
|
151
|
+
|
|
152
|
+
| `facing` | `roll=0` (right) | `roll=1` (up) |
|
|
153
|
+
|---|---|---|
|
|
154
|
+
| `Dir.X` (+X) | +Z | +Y |
|
|
155
|
+
| `Dir.Z` (+Z) | -X | +Y |
|
|
156
|
+
| `Dir.NX` (-X) | -Z | +Y |
|
|
157
|
+
| `Dir.NZ` (-Z) | +X | +Y |
|
|
158
|
+
| `Dir.Y` (+Y) | +Z | -X |
|
|
159
|
+
| `Dir.NY` (-Y) | +Z | +X |
|
|
160
|
+
|
|
161
|
+
For `roll=2` or `roll=3`, use the opposite of the corresponding table direction. `mirrored=True` reverses the lateral direction again, without changing the forward direction.
|
|
162
|
+
|
|
163
|
+
`roll` changes simulation routing for `BLUE_ARROW`, `BLUE_I_SPLITTER`, `BLUE_L_SPLITTER`, `DIAGONAL_ARROW`, `DIAGONAL_SPLITTER`, and `DIAGONAL_BLOCKER`. For diagonal blocks, the target offset is the forward step plus the selected lateral step.
|
|
164
|
+
|
|
165
|
+
**Diagonal blocker example** — at `(10, 10, 10)`, facing +X:
|
|
166
|
+
|
|
167
|
+
```python
|
|
168
|
+
# Forward +X, lateral +Z: blocks (11, 10, 11)
|
|
169
|
+
bp.place(Block.DIAGONAL_BLOCKER, (10, 10, 10), facing=Dir.X, roll=0)
|
|
170
|
+
|
|
171
|
+
# Forward +X, lateral +Y: blocks (11, 11, 10)
|
|
172
|
+
bp.place(Block.DIAGONAL_BLOCKER, (10, 10, 10), facing=Dir.X, roll=1)
|
|
173
|
+
|
|
174
|
+
# Mirroring reverses the lateral step: blocks (11, 10, 9)
|
|
175
|
+
bp.place(
|
|
176
|
+
Block.DIAGONAL_BLOCKER,
|
|
177
|
+
(10, 10, 10),
|
|
178
|
+
facing=Dir.X,
|
|
179
|
+
roll=0,
|
|
180
|
+
mirrored=True,
|
|
181
|
+
)
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
**Diagonal signal blocks** use the same orientation rule:
|
|
185
|
+
|
|
186
|
+
```python
|
|
187
|
+
# Sends along the diagonal target (forward + lateral)
|
|
188
|
+
bp.place(Block.DIAGONAL_ARROW, (0, 0, 0), facing=Dir.X, roll=0)
|
|
189
|
+
|
|
190
|
+
# Splitter sends one output forward and another forward + lateral
|
|
191
|
+
bp.place(Block.DIAGONAL_SPLITTER, (0, 0, 0), facing=Dir.X, roll=0)
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
For the examples above, `Dir.X` with `roll=0` makes the diagonal branch point toward +X/+Z; setting `mirrored=True` makes it +X/-Z. Change `facing` and `roll` to orient the diagonal in other planes.
|
|
195
|
+
|
|
196
|
+
### Lay wires and splitters
|
|
197
|
+
|
|
198
|
+
```python
|
|
199
|
+
bp.wire((1, 0, 0), (5, 0, 0), end=Dir.X)
|
|
200
|
+
bp.split((6, 0, 0), Dir.X, [Dir.X, Dir.Y])
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
`wire()` fills each cell between listed points with arrows; each segment must be straight along one axis. `split()` chooses a supported splitter orientation from the requested output directions.
|
|
204
|
+
|
|
205
|
+
### Add links and palettes
|
|
206
|
+
|
|
207
|
+
```python
|
|
208
|
+
bp.place(Block.LINKED_ARROW, (0, 0, 2), facing=Dir.X)
|
|
209
|
+
bp.place(Block.LINKED_ARROW, (8, 0, 2), facing=Dir.X)
|
|
210
|
+
bp.link((0, 0, 2), (8, 0, 2))
|
|
211
|
+
|
|
212
|
+
palette_id = bp.add_palette([
|
|
213
|
+
(255, 80, 80, 255),
|
|
214
|
+
(80, 160, 255, 255),
|
|
215
|
+
])
|
|
216
|
+
bp.place(Block.PALETTE_BULB, (9, 0, 2), palette=palette_id)
|
|
217
|
+
bp.save("linked_palette_demo.labp")
|
|
218
|
+
```
|
|
219
|
+
|
|
220
|
+
`bp.link(source, target)` validates supported link types and graph constraints. Palette bulbs and mixers can be linked to mixers according to the game's link rules.
|
|
221
|
+
|
|
222
|
+
### Save
|
|
223
|
+
|
|
224
|
+
```python
|
|
225
|
+
path = bp.save("my_circuit.labp")
|
|
226
|
+
print(path)
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
`save()` writes the native Base64-wrapped binary `.labp`. It does not launch the game and does not need the headless executable. If probes, scheduled actions or assertions are present, `save()` also writes a separate `.tests.json` sidecar; the game ignores that sidecar.
|
|
230
|
+
|
|
231
|
+
## Run a circuit without opening the game
|
|
232
|
+
|
|
233
|
+
After building the runner, run a saved blueprint directly:
|
|
234
|
+
|
|
235
|
+
```powershell
|
|
236
|
+
.\lasim.exe .\output\source_to_bulb.labp 100
|
|
237
|
+
```
|
|
238
|
+
|
|
239
|
+
The final number is the number of simulation ticks. This loads the `.labp`, constructs the real simulation `World`, and calls `World::Tick()` repeatedly. It does not render a window.
|
|
240
|
+
|
|
241
|
+
To inspect signal changes, add named probes in the Python script before saving:
|
|
242
|
+
|
|
243
|
+
```python
|
|
244
|
+
bp.probe("source", (0, 0, 0))
|
|
245
|
+
bp.probe("lamp", (6, 0, 0))
|
|
246
|
+
bp.save("output/source_to_bulb.labp")
|
|
247
|
+
```
|
|
248
|
+
|
|
249
|
+
Then run the headless command. It prints a trace line when a probed state changes. `probe()` is just trace output; it does not create an assertion or change the `.labp` circuit.
|
|
250
|
+
|
|
251
|
+
You can also call `bp.run(ticks=100, runner=r".\lasim.exe")` from Python after the runner has been built. The `runner` argument is useful when you built the executable outside the installed package. It returns a `SimulationResult` with `.trace`, `.stdout`, and `.stderr`.
|
|
252
|
+
|
|
253
|
+
## Runtime tests (optional)
|
|
254
|
+
|
|
255
|
+
Runtime tests are optional and are separate from creating/placing a blueprint. See `examples/runtime_test.py` and the test API section in the previous headless README if you want assertions and scheduled inputs.
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"""Create a simple source-to-bulb blueprint.
|
|
2
|
+
|
|
3
|
+
Usage:
|
|
4
|
+
python examples/create_circuit.py [output.labp]
|
|
5
|
+
"""
|
|
6
|
+
from pathlib import Path
|
|
7
|
+
import sys
|
|
8
|
+
|
|
9
|
+
from lac import Blueprint, Block, Dir
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def build_circuit():
|
|
13
|
+
bp = Blueprint()
|
|
14
|
+
|
|
15
|
+
# A source powers the adjacent arrow. The arrows carry the signal to the bulb.
|
|
16
|
+
bp.place(Block.SOURCE, (0, 0, 0))
|
|
17
|
+
bp.wire((1, 0, 0), (5, 0, 0), end=Dir.X)
|
|
18
|
+
bp.place(
|
|
19
|
+
Block.BULB,
|
|
20
|
+
(6, 0, 0),
|
|
21
|
+
fill={
|
|
22
|
+
"off": (55, 65, 80, 255),
|
|
23
|
+
"on": (255, 220, 70, 255),
|
|
24
|
+
},
|
|
25
|
+
)
|
|
26
|
+
|
|
27
|
+
return bp
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
if __name__ == "__main__":
|
|
31
|
+
output = Path(sys.argv[1]) if len(sys.argv) > 1 else Path("source_to_bulb.labp")
|
|
32
|
+
saved = build_circuit().save(output)
|
|
33
|
+
print(f"Created {saved}")
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"""Demonstrate runtime stimuli and assertions in the headless simulator."""
|
|
2
|
+
from pathlib import Path
|
|
3
|
+
import sys
|
|
4
|
+
|
|
5
|
+
from lac import Blueprint, Block, Dir
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
def build():
|
|
9
|
+
bp = Blueprint()
|
|
10
|
+
button = (0, 0, 0)
|
|
11
|
+
lamp = (1, 0, 0)
|
|
12
|
+
|
|
13
|
+
bp.place(Block.KEY_BUTTON, button, facing=Dir.X, key=65)
|
|
14
|
+
bp.place(Block.BULB, lamp)
|
|
15
|
+
bp.press(button, at=3)
|
|
16
|
+
bp.probe("lamp", lamp)
|
|
17
|
+
|
|
18
|
+
check = bp.test("key button produces a one-tick pulse")
|
|
19
|
+
check.off(lamp, at=1)
|
|
20
|
+
check.on(lamp, at=3)
|
|
21
|
+
check.off(lamp, at=4)
|
|
22
|
+
check.rising_edges(lamp, count=1, from_tick=1, through=8)
|
|
23
|
+
check.falling_edges(lamp, count=1, from_tick=1, through=8)
|
|
24
|
+
return bp
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
if __name__ == "__main__":
|
|
28
|
+
result = build().run(ticks=8)
|
|
29
|
+
for test in result.tests:
|
|
30
|
+
print(("PASS" if test["passed"] else "FAIL"), test["name"], test["message"])
|
|
31
|
+
print("probe trace:")
|
|
32
|
+
for line in result.trace:
|
|
33
|
+
print(line)
|
|
34
|
+
result.assert_passed()
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=68", "wheel"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "logic-arrows-lac"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "Python blueprint builder and headless simulation interface for Logic Arrows 3D"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.9"
|
|
11
|
+
keywords = ["logic-arrows-3d", "blueprint", "circuit", "simulation"]
|
|
12
|
+
classifiers = [
|
|
13
|
+
"Development Status :: 3 - Alpha",
|
|
14
|
+
"Intended Audience :: Developers",
|
|
15
|
+
"Operating System :: OS Independent",
|
|
16
|
+
"Programming Language :: Python :: 3",
|
|
17
|
+
"Programming Language :: Python :: 3 :: Only",
|
|
18
|
+
"Topic :: Software Development :: Libraries :: Python Modules",
|
|
19
|
+
]
|
|
20
|
+
|
|
21
|
+
[tool.setuptools]
|
|
22
|
+
package-dir = {"" = "src"}
|
|
23
|
+
include-package-data = true
|
|
24
|
+
|
|
25
|
+
[tool.setuptools.packages.find]
|
|
26
|
+
where = ["src"]
|
|
27
|
+
|
|
28
|
+
[tool.setuptools.package-data]
|
|
29
|
+
lac = [
|
|
30
|
+
"headless/*.cpp",
|
|
31
|
+
"headless/*.bat",
|
|
32
|
+
"headless/*.sh",
|
|
33
|
+
"headless/stub/*.h",
|
|
34
|
+
]
|