tfbscript 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- tfbscript/__init__.py +21 -0
- tfbscript/__main__.py +52 -0
- tfbscript/ansi.py +203 -0
- tfbscript/arena.py +119 -0
- tfbscript/binary.py +84 -0
- tfbscript/debug.py +14 -0
- tfbscript/editor/__init__.py +3 -0
- tfbscript/editor/app.py +141 -0
- tfbscript/editor/fonts/ms-sans-serif/MS Sans Serif.ttf +0 -0
- tfbscript/editor/fonts/ms-sans-serif/license.txt +4 -0
- tfbscript/editor/fonts/ms-sans-serif/readme.txt +26 -0
- tfbscript/editor/fonts/ms-sans-serif-bold/MS Sans Serif Bold.ttf +0 -0
- tfbscript/editor/fonts/ms-sans-serif-bold/license.txt +4 -0
- tfbscript/editor/fonts/ms-sans-serif-bold/readme.txt +26 -0
- tfbscript/editor/fonts.py +98 -0
- tfbscript/editor/search.py +200 -0
- tfbscript/editor/style.py +141 -0
- tfbscript/editor/widgets.py +321 -0
- tfbscript/opcodes/__init__.py +104 -0
- tfbscript/opcodes/base.py +362 -0
- tfbscript/opcodes/block.py +34 -0
- tfbscript/opcodes/enums.py +219 -0
- tfbscript/opcodes/op_behavior_implementation.py +39 -0
- tfbscript/opcodes/op_change_membership.py +62 -0
- tfbscript/opcodes/op_check_fov.py +73 -0
- tfbscript/opcodes/op_check_membership.py +41 -0
- tfbscript/opcodes/op_check_message.py +79 -0
- tfbscript/opcodes/op_check_reference.py +61 -0
- tfbscript/opcodes/op_check_value.py +66 -0
- tfbscript/opcodes/op_comment.py +43 -0
- tfbscript/opcodes/op_control.py +80 -0
- tfbscript/opcodes/op_create_variable.py +42 -0
- tfbscript/opcodes/op_cut_scene.py +44 -0
- tfbscript/opcodes/op_dec_value.py +43 -0
- tfbscript/opcodes/op_displace.py +111 -0
- tfbscript/opcodes/op_find_subset.py +49 -0
- tfbscript/opcodes/op_find_variable.py +28 -0
- tfbscript/opcodes/op_for_each.py +65 -0
- tfbscript/opcodes/op_if_else.py +105 -0
- tfbscript/opcodes/op_inc_value.py +43 -0
- tfbscript/opcodes/op_loop_value.py +28 -0
- tfbscript/opcodes/op_move_from.py +47 -0
- tfbscript/opcodes/op_move_to.py +99 -0
- tfbscript/opcodes/op_play_animation.py +46 -0
- tfbscript/opcodes/op_play_sound.py +42 -0
- tfbscript/opcodes/op_prescript.py +26 -0
- tfbscript/opcodes/op_print.py +53 -0
- tfbscript/opcodes/op_remove.py +43 -0
- tfbscript/opcodes/op_reset.py +42 -0
- tfbscript/opcodes/op_run_as_player.py +26 -0
- tfbscript/opcodes/op_send_message.py +53 -0
- tfbscript/opcodes/op_set_behavior.py +41 -0
- tfbscript/opcodes/op_set_reference.py +52 -0
- tfbscript/opcodes/op_set_value.py +52 -0
- tfbscript/opcodes/op_shutdown.py +26 -0
- tfbscript/opcodes/op_slide_value.py +81 -0
- tfbscript/opcodes/op_spawn_actor.py +96 -0
- tfbscript/opcodes/op_startup.py +26 -0
- tfbscript/opcodes/op_stop_sound.py +26 -0
- tfbscript/opcodes/op_teleport_to.py +47 -0
- tfbscript/opcodes/op_turn_to.py +33 -0
- tfbscript/opcodes/op_use_camera.py +68 -0
- tfbscript/payload.py +40 -0
- tfbscript/reference.py +926 -0
- tfbscript/rhs.py +326 -0
- tfbscript/script.py +160 -0
- tfbscript/string_table.py +101 -0
- tfbscript-0.1.0.dist-info/METADATA +116 -0
- tfbscript-0.1.0.dist-info/RECORD +72 -0
- tfbscript-0.1.0.dist-info/WHEEL +4 -0
- tfbscript-0.1.0.dist-info/entry_points.txt +2 -0
- tfbscript-0.1.0.dist-info/licenses/LICENSE +201 -0
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
from dataclasses import dataclass, field
|
|
2
|
+
from typing import BinaryIO, override
|
|
3
|
+
|
|
4
|
+
from tfbscript.ansi import func_call
|
|
5
|
+
from tfbscript.binary import write_u8
|
|
6
|
+
from tfbscript.opcodes.base import Opcode, opcode
|
|
7
|
+
from tfbscript.opcodes.enums import AnimationMapping
|
|
8
|
+
from tfbscript.payload import PayloadReader
|
|
9
|
+
from tfbscript.rhs import Rhs
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
@opcode(
|
|
13
|
+
"turn to",
|
|
14
|
+
"Turns to either an actor reference or an angle while playing an animation.",
|
|
15
|
+
)
|
|
16
|
+
@dataclass
|
|
17
|
+
class OpTurnTo(Opcode):
|
|
18
|
+
rhs: Rhs = field(default_factory=Rhs) # angle or actor reference
|
|
19
|
+
animation: AnimationMapping = field(default=AnimationMapping.ambient)
|
|
20
|
+
|
|
21
|
+
@classmethod
|
|
22
|
+
@override
|
|
23
|
+
def parse_payload(cls, reader: PayloadReader) -> "OpTurnTo":
|
|
24
|
+
return cls(rhs=reader.readRHS(), animation=AnimationMapping(reader.read_u8()))
|
|
25
|
+
|
|
26
|
+
@override
|
|
27
|
+
def source_line(self, inline: bool = False) -> str:
|
|
28
|
+
return func_call("turnTo", str(self.rhs), f"animation: {self.animation}")
|
|
29
|
+
|
|
30
|
+
@override
|
|
31
|
+
def write_payload(self, f: BinaryIO) -> None:
|
|
32
|
+
self.rhs.write(f)
|
|
33
|
+
write_u8(f, self.animation)
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
from dataclasses import dataclass, field
|
|
2
|
+
from typing import BinaryIO, override
|
|
3
|
+
|
|
4
|
+
from tfbscript.ansi import func_call
|
|
5
|
+
from tfbscript.binary import write_f32, write_u8
|
|
6
|
+
from tfbscript.opcodes.base import Opcode, opcode
|
|
7
|
+
from tfbscript.opcodes.enums import CamTransitionInMode, CamTransitionOutMode
|
|
8
|
+
from tfbscript.payload import PayloadReader
|
|
9
|
+
from tfbscript.reference import Reference
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
@opcode("use camera")
|
|
13
|
+
@dataclass
|
|
14
|
+
class OpUseCamera(Opcode):
|
|
15
|
+
camera_ref: Reference = field(default_factory=Reference)
|
|
16
|
+
|
|
17
|
+
trans_in_mode: CamTransitionInMode = field(default=CamTransitionInMode.fade_in)
|
|
18
|
+
trans_in_duration: float = field(default=0.0)
|
|
19
|
+
|
|
20
|
+
trans_out_mode: CamTransitionOutMode = field(
|
|
21
|
+
default=CamTransitionOutMode.no_transition
|
|
22
|
+
)
|
|
23
|
+
trans_out_duration: float | None = field(default=None)
|
|
24
|
+
|
|
25
|
+
@classmethod
|
|
26
|
+
@override
|
|
27
|
+
def parse_payload(cls, reader: PayloadReader) -> "OpUseCamera":
|
|
28
|
+
camera_ref = reader.readRef()
|
|
29
|
+
|
|
30
|
+
trans_in_mode = CamTransitionInMode(reader.read_u8())
|
|
31
|
+
trans_in_duration = reader.read_f32()
|
|
32
|
+
|
|
33
|
+
trans_out_mode = CamTransitionOutMode(reader.read_u8())
|
|
34
|
+
|
|
35
|
+
trans_out_duration = None
|
|
36
|
+
if trans_out_mode != CamTransitionOutMode.no_transition:
|
|
37
|
+
trans_out_duration = reader.read_f32()
|
|
38
|
+
|
|
39
|
+
return cls(
|
|
40
|
+
camera_ref=camera_ref,
|
|
41
|
+
trans_in_mode=trans_in_mode,
|
|
42
|
+
trans_in_duration=trans_in_duration,
|
|
43
|
+
trans_out_mode=trans_out_mode,
|
|
44
|
+
trans_out_duration=trans_out_duration,
|
|
45
|
+
)
|
|
46
|
+
|
|
47
|
+
@override
|
|
48
|
+
def write_payload(self, f: BinaryIO) -> None:
|
|
49
|
+
self.camera_ref.write(f)
|
|
50
|
+
write_u8(f, self.trans_in_mode)
|
|
51
|
+
write_f32(f, self.trans_in_duration)
|
|
52
|
+
|
|
53
|
+
write_u8(f, self.trans_out_mode)
|
|
54
|
+
if self.trans_out_mode != CamTransitionOutMode.no_transition:
|
|
55
|
+
assert self.trans_out_duration is not None # Should never assert
|
|
56
|
+
write_f32(f, self.trans_out_duration)
|
|
57
|
+
|
|
58
|
+
@override
|
|
59
|
+
def source_line(self, inline: bool = False) -> str:
|
|
60
|
+
return func_call(
|
|
61
|
+
"useCamera",
|
|
62
|
+
str(self.camera_ref),
|
|
63
|
+
f"trans_in: {self.trans_in_mode} for {self.trans_in_duration}sec",
|
|
64
|
+
f"trans_out: {self.trans_out_mode} for {self.trans_out_duration}sec"
|
|
65
|
+
if self.trans_out_mode != CamTransitionOutMode.no_transition
|
|
66
|
+
else f"trans_out: {self.trans_out_mode}",
|
|
67
|
+
)
|
|
68
|
+
|
tfbscript/payload.py
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"""Reader for opcode payloads, with access to the script's reference tables."""
|
|
2
|
+
|
|
3
|
+
from typing import TYPE_CHECKING
|
|
4
|
+
|
|
5
|
+
from tfbscript.binary import BinaryReader
|
|
6
|
+
from tfbscript.reference import Reference
|
|
7
|
+
from tfbscript.rhs import Rhs
|
|
8
|
+
from tfbscript.string_table import StringTable
|
|
9
|
+
|
|
10
|
+
if TYPE_CHECKING:
|
|
11
|
+
from tfbscript.opcodes.base import ParserContext
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class PayloadReader(BinaryReader):
|
|
15
|
+
"""A BinaryReader over one opcode payload.
|
|
16
|
+
|
|
17
|
+
Also carries the script's global/local reference tables so payload parsers
|
|
18
|
+
can read References and RHS operands without threading the tables through.
|
|
19
|
+
"""
|
|
20
|
+
|
|
21
|
+
def __init__(
|
|
22
|
+
self,
|
|
23
|
+
data: bytes,
|
|
24
|
+
global_refs: StringTable,
|
|
25
|
+
local_refs: StringTable,
|
|
26
|
+
little_endian: bool = True,
|
|
27
|
+
context: "ParserContext | None" = None,
|
|
28
|
+
):
|
|
29
|
+
super().__init__(data, little_endian)
|
|
30
|
+
self.global_refs = global_refs
|
|
31
|
+
self.local_refs = local_refs
|
|
32
|
+
self.context = context
|
|
33
|
+
|
|
34
|
+
def readRef(self) -> Reference:
|
|
35
|
+
"""Read a 4-byte TFB-Script variable reference."""
|
|
36
|
+
return Reference.read(self, self.global_refs, self.local_refs, self.context)
|
|
37
|
+
|
|
38
|
+
def readRHS(self) -> Rhs:
|
|
39
|
+
"""Read a 5-11 byte TFB-Script RHS operand."""
|
|
40
|
+
return Rhs.read(self, self.global_refs, self.local_refs, self.context)
|