tfbpseudo 0.1.1__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.
- tfbpseudo-0.1.1/.gitignore +78 -0
- tfbpseudo-0.1.1/LICENSE +201 -0
- tfbpseudo-0.1.1/PKG-INFO +43 -0
- tfbpseudo-0.1.1/README.md +25 -0
- tfbpseudo-0.1.1/pyproject.toml +38 -0
- tfbpseudo-0.1.1/src/tfbpseudo/__init__.py +29 -0
- tfbpseudo-0.1.1/src/tfbpseudo/arguments.py +271 -0
- tfbpseudo-0.1.1/src/tfbpseudo/compiler.py +722 -0
- tfbpseudo-0.1.1/src/tfbpseudo/decompiler.py +597 -0
- tfbpseudo-0.1.1/src/tfbpseudo/editor/__init__.py +3 -0
- tfbpseudo-0.1.1/src/tfbpseudo/editor/app.py +805 -0
- tfbpseudo-0.1.1/src/tfbpseudo/editor/basic.tai +16 -0
- tfbpseudo-0.1.1/src/tfbpseudo/editor/completer.py +242 -0
- tfbpseudo-0.1.1/src/tfbpseudo/editor/completions.py +945 -0
- tfbpseudo-0.1.1/src/tfbpseudo/editor/favicon.png +0 -0
- tfbpseudo-0.1.1/src/tfbpseudo/editor/highlighter.py +164 -0
- tfbpseudo-0.1.1/src/tfbpseudo/editor/panel.py +397 -0
- tfbpseudo-0.1.1/src/tfbpseudo/editor/preferences.py +180 -0
- tfbpseudo-0.1.1/src/tfbpseudo/editor/search.py +427 -0
- tfbpseudo-0.1.1/src/tfbpseudo/editor/settings.py +77 -0
- tfbpseudo-0.1.1/src/tfbpseudo/editor/theme.py +290 -0
- tfbpseudo-0.1.1/src/tfbpseudo/editor/widgets.py +1161 -0
- tfbpseudo-0.1.1/src/tfbpseudo/errors.py +20 -0
- tfbpseudo-0.1.1/src/tfbpseudo/lexer.py +62 -0
- tfbpseudo-0.1.1/src/tfbpseudo/methods.py +456 -0
- tfbpseudo-0.1.1/src/tfbpseudo/nodes.py +86 -0
- tfbpseudo-0.1.1/src/tfbpseudo/parser.py +366 -0
- tfbpseudo-0.1.1/src/tfbpseudo/references.py +254 -0
- tfbpseudo-0.1.1/src/tfbpseudo/rhs.py +486 -0
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
# Python
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.py[cod]
|
|
4
|
+
*.pyd
|
|
5
|
+
|
|
6
|
+
# Virtual environments
|
|
7
|
+
env/
|
|
8
|
+
.venv/
|
|
9
|
+
venv/
|
|
10
|
+
|
|
11
|
+
# Python build/package output
|
|
12
|
+
build/
|
|
13
|
+
dist/
|
|
14
|
+
*.egg-info/
|
|
15
|
+
|
|
16
|
+
# uv
|
|
17
|
+
# uv.lock is intentionally NOT ignored
|
|
18
|
+
|
|
19
|
+
# Test / tooling caches
|
|
20
|
+
.pytest_cache/
|
|
21
|
+
.mypy_cache/
|
|
22
|
+
.ruff_cache/
|
|
23
|
+
.coverage
|
|
24
|
+
htmlcov/
|
|
25
|
+
|
|
26
|
+
# IDE
|
|
27
|
+
.vscode/
|
|
28
|
+
.idea/
|
|
29
|
+
.claude/
|
|
30
|
+
|
|
31
|
+
# Environment / secrets
|
|
32
|
+
.env
|
|
33
|
+
.env.*
|
|
34
|
+
!.env.example
|
|
35
|
+
|
|
36
|
+
# OS
|
|
37
|
+
.DS_Store
|
|
38
|
+
Thumbs.db
|
|
39
|
+
|
|
40
|
+
*.stream
|
|
41
|
+
*.txd
|
|
42
|
+
*.rws
|
|
43
|
+
*.wav
|
|
44
|
+
*.bsp
|
|
45
|
+
*.dff
|
|
46
|
+
|
|
47
|
+
Levels/
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
# *.gig.* = Dont track this file
|
|
51
|
+
**/*.gig.*
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
native/printhook
|
|
57
|
+
native/mods
|
|
58
|
+
|
|
59
|
+
# Local scratch drivers / experiments
|
|
60
|
+
scratch/
|
|
61
|
+
|
|
62
|
+
# Compiler output from examples/
|
|
63
|
+
*.out.ai
|
|
64
|
+
|
|
65
|
+
# mod build output (cli mod build)
|
|
66
|
+
mods/*/build/
|
|
67
|
+
|
|
68
|
+
# machine-specific settings (cli config)
|
|
69
|
+
settings.toml
|
|
70
|
+
|
|
71
|
+
mods/
|
|
72
|
+
# tfbscript local data (game scripts, notes, decompiler output)
|
|
73
|
+
packages/tfbscript/example_scripts/
|
|
74
|
+
packages/tfbscript/my_scripts/
|
|
75
|
+
packages/tfbscript/archive/
|
|
76
|
+
packages/tfbscript/nopush.txt
|
|
77
|
+
_MYNOTES.*
|
|
78
|
+
*.decomp
|
tfbpseudo-0.1.1/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
tfbpseudo-0.1.1/PKG-INFO
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: tfbpseudo
|
|
3
|
+
Version: 0.1.1
|
|
4
|
+
Summary: Compiler and decompiler for TfbPseudo, a text version of Madagascar AI scripts
|
|
5
|
+
Project-URL: Repository, https://github.com/MaxStache/madagascar-game-asset-tools
|
|
6
|
+
Project-URL: Issues, https://github.com/MaxStache/madagascar-game-asset-tools/issues
|
|
7
|
+
Author: Max Stache
|
|
8
|
+
License-Expression: Apache-2.0
|
|
9
|
+
License-File: LICENSE
|
|
10
|
+
Classifier: Programming Language :: Python :: 3
|
|
11
|
+
Classifier: Topic :: Games/Entertainment
|
|
12
|
+
Classifier: Topic :: Software Development :: Libraries
|
|
13
|
+
Requires-Python: >=3.12
|
|
14
|
+
Requires-Dist: tfbscript>=0.1.0
|
|
15
|
+
Provides-Extra: editor
|
|
16
|
+
Requires-Dist: pyside6>=6.11.2; extra == 'editor'
|
|
17
|
+
Description-Content-Type: text/markdown
|
|
18
|
+
|
|
19
|
+
# tfbpseudo
|
|
20
|
+
|
|
21
|
+
Compiler and decompiler for **TfbPseudo**, a readable text form of the AI scripts (`.ai` files) in *Madagascar* (2005, PC).
|
|
22
|
+
|
|
23
|
+
Decompile a script to text, edit it, and compile it back to a byte-compatible `.ai` file. The binary format itself is handled by [`tfbscript`](https://pypi.org/project/tfbscript/).
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
pip install tfbpseudo # compiler + decompiler
|
|
27
|
+
pip install "tfbpseudo[editor]" # plus the Qt editor (tfbeditor)
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
```python
|
|
31
|
+
from tfbscript import ScriptFile
|
|
32
|
+
from tfbpseudo import compile_source, decompile_script
|
|
33
|
+
|
|
34
|
+
source = decompile_script(ScriptFile.from_path("DG_Coin_Collectable.ai"))
|
|
35
|
+
# ... edit source ...
|
|
36
|
+
script = compile_source(source)
|
|
37
|
+
with open("DG_Coin_Collectable.ai", "wb") as f:
|
|
38
|
+
script.write(f)
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
With the `editor` extra installed, `tfbeditor [FILE]` opens a TfbPseudo editor with syntax highlighting and completion.
|
|
42
|
+
|
|
43
|
+
Part of the [madagascar-game-asset-tools](https://github.com/MaxStache/madagascar-game-asset-tools) monorepo.
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# tfbpseudo
|
|
2
|
+
|
|
3
|
+
Compiler and decompiler for **TfbPseudo**, a readable text form of the AI scripts (`.ai` files) in *Madagascar* (2005, PC).
|
|
4
|
+
|
|
5
|
+
Decompile a script to text, edit it, and compile it back to a byte-compatible `.ai` file. The binary format itself is handled by [`tfbscript`](https://pypi.org/project/tfbscript/).
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pip install tfbpseudo # compiler + decompiler
|
|
9
|
+
pip install "tfbpseudo[editor]" # plus the Qt editor (tfbeditor)
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
```python
|
|
13
|
+
from tfbscript import ScriptFile
|
|
14
|
+
from tfbpseudo import compile_source, decompile_script
|
|
15
|
+
|
|
16
|
+
source = decompile_script(ScriptFile.from_path("DG_Coin_Collectable.ai"))
|
|
17
|
+
# ... edit source ...
|
|
18
|
+
script = compile_source(source)
|
|
19
|
+
with open("DG_Coin_Collectable.ai", "wb") as f:
|
|
20
|
+
script.write(f)
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
With the `editor` extra installed, `tfbeditor [FILE]` opens a TfbPseudo editor with syntax highlighting and completion.
|
|
24
|
+
|
|
25
|
+
Part of the [madagascar-game-asset-tools](https://github.com/MaxStache/madagascar-game-asset-tools) monorepo.
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "tfbpseudo"
|
|
3
|
+
description = "Compiler and decompiler for TfbPseudo, a text version of Madagascar AI scripts"
|
|
4
|
+
version = "0.1.1"
|
|
5
|
+
requires-python = ">=3.12"
|
|
6
|
+
readme = "README.md"
|
|
7
|
+
license = "Apache-2.0"
|
|
8
|
+
license-files = ["LICENSE"]
|
|
9
|
+
authors = [{ name = "Max Stache" }]
|
|
10
|
+
classifiers = [
|
|
11
|
+
"Programming Language :: Python :: 3",
|
|
12
|
+
"Topic :: Games/Entertainment",
|
|
13
|
+
"Topic :: Software Development :: Libraries",
|
|
14
|
+
]
|
|
15
|
+
|
|
16
|
+
dependencies = [
|
|
17
|
+
"tfbscript>=0.1.0",
|
|
18
|
+
]
|
|
19
|
+
|
|
20
|
+
[project.urls]
|
|
21
|
+
Repository = "https://github.com/MaxStache/madagascar-game-asset-tools"
|
|
22
|
+
Issues = "https://github.com/MaxStache/madagascar-game-asset-tools/issues"
|
|
23
|
+
|
|
24
|
+
[project.optional-dependencies]
|
|
25
|
+
# Only tfbpseudo.editor needs Qt; the compiler and decompiler do not.
|
|
26
|
+
editor = [
|
|
27
|
+
"pyside6>=6.11.2",
|
|
28
|
+
]
|
|
29
|
+
|
|
30
|
+
[project.gui-scripts]
|
|
31
|
+
tfbeditor = "tfbpseudo.editor:main"
|
|
32
|
+
|
|
33
|
+
[build-system]
|
|
34
|
+
requires = ["hatchling"]
|
|
35
|
+
build-backend = "hatchling.build"
|
|
36
|
+
|
|
37
|
+
[tool.uv.sources]
|
|
38
|
+
tfbscript = { workspace = true }
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
from .compiler import Compiler, compile_source
|
|
2
|
+
from .decompiler import Decompiler, decompile_script
|
|
3
|
+
from .errors import CompileError, DecompileError, ParseError
|
|
4
|
+
from .lexer import Token, tokenize
|
|
5
|
+
from .nodes import Behavior, Block, Flow, Prescript, Script, Statement, Variable
|
|
6
|
+
from .parser import Parser
|
|
7
|
+
|
|
8
|
+
# Imported for its side effect: it declares every opcode in both directions.
|
|
9
|
+
from . import methods # noqa: E402,F401 isort:skip
|
|
10
|
+
|
|
11
|
+
__all__ = [
|
|
12
|
+
"Behavior",
|
|
13
|
+
"Block",
|
|
14
|
+
"CompileError",
|
|
15
|
+
"Compiler",
|
|
16
|
+
"DecompileError",
|
|
17
|
+
"Flow",
|
|
18
|
+
"Decompiler",
|
|
19
|
+
"ParseError",
|
|
20
|
+
"Parser",
|
|
21
|
+
"Prescript",
|
|
22
|
+
"Script",
|
|
23
|
+
"Statement",
|
|
24
|
+
"Token",
|
|
25
|
+
"Variable",
|
|
26
|
+
"compile_source",
|
|
27
|
+
"decompile_script",
|
|
28
|
+
"tokenize",
|
|
29
|
+
]
|
|
@@ -0,0 +1,271 @@
|
|
|
1
|
+
"""Opcode arguments, spelled the same way by the compiler and the decompiler.
|
|
2
|
+
|
|
3
|
+
Nearly every opcode is a fixed list of operands, so rather than writing the two
|
|
4
|
+
directions out by hand for each one -- where they could drift apart -- an
|
|
5
|
+
opcode declares its operands once in `methods.py` and both handlers are built
|
|
6
|
+
from that declaration. Each Argument here knows how to read one argument's
|
|
7
|
+
tokens into the opcode's fields and how to write those fields back out.
|
|
8
|
+
|
|
9
|
+
An argument may be `optional`, in which case it is the trailing ones that go
|
|
10
|
+
missing: `spawnActor` has a byte that is only in some files, `useCamera` has a
|
|
11
|
+
second duration only for a real transition. `present` decides whether to write
|
|
12
|
+
one back out, and everything after an absent argument is absent too.
|
|
13
|
+
"""
|
|
14
|
+
|
|
15
|
+
from collections.abc import Callable
|
|
16
|
+
from dataclasses import dataclass
|
|
17
|
+
from enum import IntEnum
|
|
18
|
+
from typing import TYPE_CHECKING, Any
|
|
19
|
+
|
|
20
|
+
from tfbpseudo.errors import CompileError, DecompileError
|
|
21
|
+
from tfbpseudo.lexer import Token, synth_token
|
|
22
|
+
from tfbpseudo.rhs import REL_OP_BY_TOKEN, float_text
|
|
23
|
+
from tfbscript.opcodes.base import Opcode
|
|
24
|
+
from tfbscript.opcodes.enums import RelOp
|
|
25
|
+
|
|
26
|
+
if TYPE_CHECKING:
|
|
27
|
+
from tfbpseudo.compiler import Compiler
|
|
28
|
+
from tfbpseudo.decompiler import Decompiler
|
|
29
|
+
|
|
30
|
+
@dataclass(frozen=True)
|
|
31
|
+
class Argument:
|
|
32
|
+
"""One argument of an opcode."""
|
|
33
|
+
|
|
34
|
+
name: str # the opcode field it sets, and what errors call it
|
|
35
|
+
optional: bool = False
|
|
36
|
+
default: Any = None # what the field is when the argument is left out
|
|
37
|
+
# For the opcodes whose payload shape is recorded in a private field
|
|
38
|
+
# rather than shown by the argument's own value.
|
|
39
|
+
present_if: Callable[[Opcode], bool] | None = None
|
|
40
|
+
|
|
41
|
+
def read(
|
|
42
|
+
self, tokens: list[Token], compiler: "Compiler"
|
|
43
|
+
) -> dict[str, object]: # pragma: no cover - overridden
|
|
44
|
+
raise NotImplementedError
|
|
45
|
+
|
|
46
|
+
def write(
|
|
47
|
+
self, opcode: Opcode, decompiler: "Decompiler"
|
|
48
|
+
) -> list[Token]: # pragma: no cover - overridden
|
|
49
|
+
raise NotImplementedError
|
|
50
|
+
|
|
51
|
+
def absent(self) -> dict[str, object]:
|
|
52
|
+
"""The fields to set when this argument is not written."""
|
|
53
|
+
return {self.name: self.default}
|
|
54
|
+
|
|
55
|
+
def present(self, opcode: Opcode) -> bool:
|
|
56
|
+
"""Whether to write this argument back out."""
|
|
57
|
+
if self.present_if is not None:
|
|
58
|
+
return self.present_if(opcode)
|
|
59
|
+
|
|
60
|
+
return getattr(opcode, self.name) != self.default
|
|
61
|
+
|
|
62
|
+
def error(self, tokens: list[Token], msg: str) -> CompileError:
|
|
63
|
+
anchor = tokens[0] if tokens else Token("EOF", "", 0, 0)
|
|
64
|
+
return CompileError(f"{self.name}: {msg}", anchor.line, anchor.col)
|
|
65
|
+
|
|
66
|
+
def one_token(self, tokens: list[Token], kind: str, what: str) -> Token:
|
|
67
|
+
if len(tokens) != 1 or tokens[0].kind != kind:
|
|
68
|
+
raise self.error(tokens, f"expected {what}")
|
|
69
|
+
|
|
70
|
+
return tokens[0]
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
@dataclass(frozen=True)
|
|
74
|
+
class Ref(Argument):
|
|
75
|
+
"""A reference: `Zoo Loop`, `@myself.health`, `players#first`.
|
|
76
|
+
|
|
77
|
+
`expects` is the kind of variable the opcode wants named here -- "sound"
|
|
78
|
+
for `playSound`, "set" for the membership ops -- where that is the same in
|
|
79
|
+
every script. It is what the editor completes, not a rule: a reference can
|
|
80
|
+
reach the right kind through a field of something else, so nothing here
|
|
81
|
+
refuses one that does not say so up front.
|
|
82
|
+
"""
|
|
83
|
+
|
|
84
|
+
expects: str | None = None
|
|
85
|
+
|
|
86
|
+
def read(self, tokens: list[Token], compiler: "Compiler") -> dict[str, object]:
|
|
87
|
+
return {self.name: compiler.get_ref_by_tokens(tokens)}
|
|
88
|
+
|
|
89
|
+
def write(self, opcode: Opcode, decompiler: "Decompiler") -> list[Token]:
|
|
90
|
+
return decompiler.ref_tokens(getattr(opcode, self.name))
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
@dataclass(frozen=True)
|
|
94
|
+
class Value(Argument):
|
|
95
|
+
"""A right-hand side: an immediate, a reference, or an expression."""
|
|
96
|
+
|
|
97
|
+
def read(self, tokens: list[Token], compiler: "Compiler") -> dict[str, object]:
|
|
98
|
+
return {self.name: compiler.get_rhs_by_tokens(tokens)}
|
|
99
|
+
|
|
100
|
+
def write(self, opcode: Opcode, decompiler: "Decompiler") -> list[Token]:
|
|
101
|
+
return decompiler.rhs_tokens(getattr(opcode, self.name))
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
@dataclass(frozen=True)
|
|
105
|
+
class Condition(Argument):
|
|
106
|
+
"""`lhs <op> rhs` in one argument, setting three fields at once."""
|
|
107
|
+
|
|
108
|
+
rel_op_name: str = "rel_op"
|
|
109
|
+
rhs_name: str = "rhs"
|
|
110
|
+
|
|
111
|
+
def read(self, tokens: list[Token], compiler: "Compiler") -> dict[str, object]:
|
|
112
|
+
lhs, rel_op, rhs = compiler.get_condition_by_tokens(tokens)
|
|
113
|
+
return {self.name: lhs, self.rel_op_name: rel_op, self.rhs_name: rhs}
|
|
114
|
+
|
|
115
|
+
def absent(self) -> dict[str, object]:
|
|
116
|
+
# All three fields keep whatever the opcode's dataclass defaults are.
|
|
117
|
+
return {}
|
|
118
|
+
|
|
119
|
+
def write(self, opcode: Opcode, decompiler: "Decompiler") -> list[Token]:
|
|
120
|
+
return decompiler.condition_tokens(
|
|
121
|
+
getattr(opcode, self.name),
|
|
122
|
+
getattr(opcode, self.rel_op_name),
|
|
123
|
+
getattr(opcode, self.rhs_name),
|
|
124
|
+
)
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
@dataclass(frozen=True)
|
|
128
|
+
class Comparison(Argument):
|
|
129
|
+
"""A bare relational operator, for the ops that carry one on its own."""
|
|
130
|
+
|
|
131
|
+
def read(self, tokens: list[Token], compiler: "Compiler") -> dict[str, object]:
|
|
132
|
+
if len(tokens) != 1 or tokens[0].value not in REL_OP_BY_TOKEN:
|
|
133
|
+
raise self.error(tokens, f"expected one of {' '.join(REL_OP_BY_TOKEN)}")
|
|
134
|
+
|
|
135
|
+
return {self.name: REL_OP_BY_TOKEN[tokens[0].value]}
|
|
136
|
+
|
|
137
|
+
def write(self, opcode: Opcode, decompiler: "Decompiler") -> list[Token]:
|
|
138
|
+
rel_op: RelOp = getattr(opcode, self.name)
|
|
139
|
+
return [synth_token("OP", rel_op.symbol())]
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
@dataclass(frozen=True)
|
|
143
|
+
class Choice(Argument):
|
|
144
|
+
"""One of an enum's members, written by name -- `slow_move`, `randomly` --
|
|
145
|
+
or by its raw number when a file has one the enum has no name for."""
|
|
146
|
+
|
|
147
|
+
enum: type[IntEnum] = RelOp
|
|
148
|
+
|
|
149
|
+
def read(self, tokens: list[Token], compiler: "Compiler") -> dict[str, object]:
|
|
150
|
+
if len(tokens) != 1 or tokens[0].kind not in ("NAME", "NUMBER", "STRING"):
|
|
151
|
+
raise self.error(tokens, f"expected one of {self.choices()}")
|
|
152
|
+
|
|
153
|
+
token = tokens[0]
|
|
154
|
+
|
|
155
|
+
if token.kind == "NUMBER":
|
|
156
|
+
try:
|
|
157
|
+
return {self.name: self.enum(int(token.value, 0))}
|
|
158
|
+
except ValueError:
|
|
159
|
+
raise self.error(
|
|
160
|
+
tokens, f"{token.value} is not a {self.enum.__name__} value"
|
|
161
|
+
) from None
|
|
162
|
+
|
|
163
|
+
folded = token.value.casefold()
|
|
164
|
+
for member in self.enum:
|
|
165
|
+
if member.name.casefold() == folded:
|
|
166
|
+
return {self.name: member}
|
|
167
|
+
|
|
168
|
+
raise self.error(
|
|
169
|
+
tokens, f"{token.value!r} is not one of {self.choices()}"
|
|
170
|
+
)
|
|
171
|
+
|
|
172
|
+
def write(self, opcode: Opcode, decompiler: "Decompiler") -> list[Token]:
|
|
173
|
+
value = getattr(opcode, self.name)
|
|
174
|
+
|
|
175
|
+
if not isinstance(value, self.enum):
|
|
176
|
+
return [synth_token("NUMBER", str(int(value)))]
|
|
177
|
+
|
|
178
|
+
return [synth_token("NAME", value.name)]
|
|
179
|
+
|
|
180
|
+
def choices(self) -> str:
|
|
181
|
+
names = [member.name for member in self.enum]
|
|
182
|
+
if len(names) > 6:
|
|
183
|
+
return ", ".join(names[:6]) + f", ... ({len(names)} in all)"
|
|
184
|
+
return ", ".join(names)
|
|
185
|
+
|
|
186
|
+
|
|
187
|
+
@dataclass(frozen=True)
|
|
188
|
+
class Text(Argument):
|
|
189
|
+
"""A quoted string the opcode stores verbatim."""
|
|
190
|
+
|
|
191
|
+
def read(self, tokens: list[Token], compiler: "Compiler") -> dict[str, object]:
|
|
192
|
+
return {self.name: self.one_token(tokens, "STRING", "a quoted string").value}
|
|
193
|
+
|
|
194
|
+
def write(self, opcode: Opcode, decompiler: "Decompiler") -> list[Token]:
|
|
195
|
+
return [synth_token("STRING", getattr(opcode, self.name))]
|
|
196
|
+
|
|
197
|
+
|
|
198
|
+
@dataclass(frozen=True)
|
|
199
|
+
class Number(Argument):
|
|
200
|
+
"""A plain number the opcode stores as-is, not a right-hand side."""
|
|
201
|
+
|
|
202
|
+
is_float: bool = False
|
|
203
|
+
|
|
204
|
+
def read(self, tokens: list[Token], compiler: "Compiler") -> dict[str, object]:
|
|
205
|
+
negative = False
|
|
206
|
+
rest = tokens
|
|
207
|
+
|
|
208
|
+
if tokens and tokens[0].kind == "OP" and tokens[0].value in ("+", "-"):
|
|
209
|
+
negative = tokens[0].value == "-"
|
|
210
|
+
rest = tokens[1:]
|
|
211
|
+
|
|
212
|
+
token = self.one_token(rest, "NUMBER", "a number")
|
|
213
|
+
text = token.value
|
|
214
|
+
|
|
215
|
+
if self.is_float:
|
|
216
|
+
value = float(text)
|
|
217
|
+
else:
|
|
218
|
+
if "." in text:
|
|
219
|
+
raise self.error(tokens, f"expected a whole number, got {text}")
|
|
220
|
+
value = int(text, 0)
|
|
221
|
+
|
|
222
|
+
return {self.name: -value if negative else value}
|
|
223
|
+
|
|
224
|
+
def write(self, opcode: Opcode, decompiler: "Decompiler") -> list[Token]:
|
|
225
|
+
value = getattr(opcode, self.name)
|
|
226
|
+
text = float_text(float(value)) if self.is_float else str(int(value))
|
|
227
|
+
|
|
228
|
+
return [synth_token("NUMBER", text)]
|
|
229
|
+
|
|
230
|
+
|
|
231
|
+
def read_arguments(
|
|
232
|
+
arguments: list[list[Token]],
|
|
233
|
+
spec: list[Argument],
|
|
234
|
+
opcode: Opcode,
|
|
235
|
+
compiler: "Compiler",
|
|
236
|
+
) -> None:
|
|
237
|
+
"""Read each argument into `opcode`'s fields, filling in the ones that were
|
|
238
|
+
left out with their defaults."""
|
|
239
|
+
for index, argument in enumerate(spec):
|
|
240
|
+
if index < len(arguments):
|
|
241
|
+
fields = argument.read(arguments[index], compiler)
|
|
242
|
+
else:
|
|
243
|
+
fields = argument.absent()
|
|
244
|
+
|
|
245
|
+
for name, value in fields.items():
|
|
246
|
+
setattr(opcode, name, value)
|
|
247
|
+
|
|
248
|
+
|
|
249
|
+
def write_arguments(
|
|
250
|
+
spec: list[Argument], opcode: Opcode, decompiler: "Decompiler"
|
|
251
|
+
) -> list[list[Token]]:
|
|
252
|
+
"""Write `opcode`'s fields back out, stopping at the first optional
|
|
253
|
+
argument that is not there -- nothing after it can be written either."""
|
|
254
|
+
out: list[list[Token]] = []
|
|
255
|
+
|
|
256
|
+
for argument in spec:
|
|
257
|
+
if argument.optional and not argument.present(opcode):
|
|
258
|
+
break
|
|
259
|
+
|
|
260
|
+
out.append(argument.write(opcode, decompiler))
|
|
261
|
+
|
|
262
|
+
for argument in spec[len(out) :]:
|
|
263
|
+
if not argument.optional:
|
|
264
|
+
raise DecompileError(
|
|
265
|
+
f"`{argument.name}` is not optional but comes after an argument "
|
|
266
|
+
+ "that is missing, so this opcode cannot be written out"
|
|
267
|
+
)
|
|
268
|
+
|
|
269
|
+
return out
|
|
270
|
+
|
|
271
|
+
|