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.
Files changed (72) hide show
  1. tfbscript/__init__.py +21 -0
  2. tfbscript/__main__.py +52 -0
  3. tfbscript/ansi.py +203 -0
  4. tfbscript/arena.py +119 -0
  5. tfbscript/binary.py +84 -0
  6. tfbscript/debug.py +14 -0
  7. tfbscript/editor/__init__.py +3 -0
  8. tfbscript/editor/app.py +141 -0
  9. tfbscript/editor/fonts/ms-sans-serif/MS Sans Serif.ttf +0 -0
  10. tfbscript/editor/fonts/ms-sans-serif/license.txt +4 -0
  11. tfbscript/editor/fonts/ms-sans-serif/readme.txt +26 -0
  12. tfbscript/editor/fonts/ms-sans-serif-bold/MS Sans Serif Bold.ttf +0 -0
  13. tfbscript/editor/fonts/ms-sans-serif-bold/license.txt +4 -0
  14. tfbscript/editor/fonts/ms-sans-serif-bold/readme.txt +26 -0
  15. tfbscript/editor/fonts.py +98 -0
  16. tfbscript/editor/search.py +200 -0
  17. tfbscript/editor/style.py +141 -0
  18. tfbscript/editor/widgets.py +321 -0
  19. tfbscript/opcodes/__init__.py +104 -0
  20. tfbscript/opcodes/base.py +362 -0
  21. tfbscript/opcodes/block.py +34 -0
  22. tfbscript/opcodes/enums.py +219 -0
  23. tfbscript/opcodes/op_behavior_implementation.py +39 -0
  24. tfbscript/opcodes/op_change_membership.py +62 -0
  25. tfbscript/opcodes/op_check_fov.py +73 -0
  26. tfbscript/opcodes/op_check_membership.py +41 -0
  27. tfbscript/opcodes/op_check_message.py +79 -0
  28. tfbscript/opcodes/op_check_reference.py +61 -0
  29. tfbscript/opcodes/op_check_value.py +66 -0
  30. tfbscript/opcodes/op_comment.py +43 -0
  31. tfbscript/opcodes/op_control.py +80 -0
  32. tfbscript/opcodes/op_create_variable.py +42 -0
  33. tfbscript/opcodes/op_cut_scene.py +44 -0
  34. tfbscript/opcodes/op_dec_value.py +43 -0
  35. tfbscript/opcodes/op_displace.py +111 -0
  36. tfbscript/opcodes/op_find_subset.py +49 -0
  37. tfbscript/opcodes/op_find_variable.py +28 -0
  38. tfbscript/opcodes/op_for_each.py +65 -0
  39. tfbscript/opcodes/op_if_else.py +105 -0
  40. tfbscript/opcodes/op_inc_value.py +43 -0
  41. tfbscript/opcodes/op_loop_value.py +28 -0
  42. tfbscript/opcodes/op_move_from.py +47 -0
  43. tfbscript/opcodes/op_move_to.py +99 -0
  44. tfbscript/opcodes/op_play_animation.py +46 -0
  45. tfbscript/opcodes/op_play_sound.py +42 -0
  46. tfbscript/opcodes/op_prescript.py +26 -0
  47. tfbscript/opcodes/op_print.py +53 -0
  48. tfbscript/opcodes/op_remove.py +43 -0
  49. tfbscript/opcodes/op_reset.py +42 -0
  50. tfbscript/opcodes/op_run_as_player.py +26 -0
  51. tfbscript/opcodes/op_send_message.py +53 -0
  52. tfbscript/opcodes/op_set_behavior.py +41 -0
  53. tfbscript/opcodes/op_set_reference.py +52 -0
  54. tfbscript/opcodes/op_set_value.py +52 -0
  55. tfbscript/opcodes/op_shutdown.py +26 -0
  56. tfbscript/opcodes/op_slide_value.py +81 -0
  57. tfbscript/opcodes/op_spawn_actor.py +96 -0
  58. tfbscript/opcodes/op_startup.py +26 -0
  59. tfbscript/opcodes/op_stop_sound.py +26 -0
  60. tfbscript/opcodes/op_teleport_to.py +47 -0
  61. tfbscript/opcodes/op_turn_to.py +33 -0
  62. tfbscript/opcodes/op_use_camera.py +68 -0
  63. tfbscript/payload.py +40 -0
  64. tfbscript/reference.py +926 -0
  65. tfbscript/rhs.py +326 -0
  66. tfbscript/script.py +160 -0
  67. tfbscript/string_table.py +101 -0
  68. tfbscript-0.1.0.dist-info/METADATA +116 -0
  69. tfbscript-0.1.0.dist-info/RECORD +72 -0
  70. tfbscript-0.1.0.dist-info/WHEEL +4 -0
  71. tfbscript-0.1.0.dist-info/entry_points.txt +2 -0
  72. 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)