-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add variables for int and float types #5
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,51 @@ | ||
from evfl.common import StringHolder | ||
import evfl.event | ||
from evfl.util import * | ||
from evfl.dic import DicReader | ||
from evfl.enums import VariableType | ||
import os | ||
|
||
|
||
class Variable(BinaryObject): | ||
__slots__ = ["num", "type", "value"] | ||
|
||
def __init__(self) -> None: | ||
super().__init__() | ||
self.type: VariableType | ||
|
||
def _do_read(self, stream: ReadStream) -> None: | ||
offset = stream.tell() | ||
stream.seek(8, os.SEEK_CUR) | ||
self.num = stream.read_u16() | ||
self.type = stream.read_u16() | ||
assert self.type == VariableType.kInteger or self.type == VariableType.kFloat | ||
stream.seek(offset) | ||
if self.type == VariableType.kInteger: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. needs handling of int arrays and float arrays |
||
self.value = stream.read_s32() | ||
elif self.type == VariableType.kFloat: | ||
self.value = stream.read_f32() | ||
stream.seek(12, os.SEEK_CUR) | ||
|
||
def _do_write(self, stream: WriteStream) -> None: | ||
if self.type == VariableType.kInteger: | ||
stream.write(s32(self.value)) | ||
if self.type == VariableType.kFloat: | ||
stream.write(f32(self.value)) | ||
stream.write(u32(0)) | ||
stream.write(u16(self.num)) | ||
stream.write(u16(self.type)) | ||
stream.write(u32(0)) | ||
|
||
|
||
class EntryPoint(BinaryObject): | ||
__slots__ = ['name', 'main_event', '_sub_flow_event_indices', '_sub_flow_event_indices_offset_writer'] | ||
__slots__ = ['name', 'main_event', '_sub_flow_event_indices', '_sub_flow_event_indices_offset_writer', 'items'] | ||
def __init__(self, name: str) -> None: | ||
super().__init__() | ||
self.name = name | ||
self.main_event: Index[evfl.event.Event] = Index() | ||
self._sub_flow_event_indices: typing.List[int] = [] | ||
self._sub_flow_event_indices_offset_writer: typing.Optional[PlaceholderWriter] = None | ||
self.items = {} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. variable_defs |
||
|
||
def _do_read(self, stream: ReadStream) -> None: | ||
sub_flow_event_indices_offset = stream.read_u64() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can we rename these variables to match the names in https://github.com/open-ead/EventFlow/blob/556793186c3065e7b25a51247d0560d7ff401b81/include/evfl/ResFlowchart.h#L71-L83 ? |
||
|
@@ -19,13 +55,21 @@ def _do_read(self, stream: ReadStream) -> None: | |
x1a = stream.read_u16() | ||
self.main_event._idx = stream.read_u16() | ||
x1e = stream.read_u16() | ||
assert x8 == 0 and x1a == 0 and x1e == 0 and ptr_x10 == 0 | ||
assert x1e == 0 | ||
|
||
if num_sub_flow_event_indices > 0: | ||
assert sub_flow_event_indices_offset != 0 | ||
with SeekContext(stream, sub_flow_event_indices_offset): | ||
self._sub_flow_event_indices = [stream.read_u16() for i in range(num_sub_flow_event_indices)] | ||
|
||
if x1a > 0: | ||
with SeekContext(stream, x8): | ||
dic = DicReader() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. variable_def_names |
||
dic.read(stream) | ||
with SeekContext(stream, ptr_x10): | ||
for item in dic.items: | ||
v = Variable() | ||
v._do_read(stream) | ||
self.items[item] = v.value | ||
def _do_write(self, stream: WriteStream) -> None: | ||
self._sub_flow_event_indices_offset_writer = stream.write_placeholder_ptr_if(bool(self._sub_flow_event_indices), register=True) | ||
stream.write(u64(0)) # x8 | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -71,3 +71,8 @@ class BuildResultType(enum.IntEnum): | |
kInvalidOperation = 1 | ||
kResFlowchartNotFound = 2 | ||
kEntryPointNotFound = 3 | ||
|
||
class VariableType(enum.IntEnum): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is actually the same enum as ContainerDataType (aka |
||
kInteger = 2 | ||
kFloat = 4 | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
VariableDef (to match the actual name in the EventFlow lib)