Skip to content
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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 47 additions & 3 deletions evfl/entry_point.py
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):
Copy link
Member

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)

__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:
Copy link
Member

Choose a reason for hiding this comment

The 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 = {}
Copy link
Member

Choose a reason for hiding this comment

The 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()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Expand All @@ -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()
Copy link
Member

Choose a reason for hiding this comment

The 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
Expand Down
5 changes: 5 additions & 0 deletions evfl/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,8 @@ class BuildResultType(enum.IntEnum):
kInvalidOperation = 1
kResFlowchartNotFound = 2
kEntryPointNotFound = 3

class VariableType(enum.IntEnum):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is actually the same enum as ContainerDataType (aka ore::ResMetaData::DataType)

kInteger = 2
kFloat = 4

2 changes: 1 addition & 1 deletion evfl/repr_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def traverse(entry_event: Event, join_stack: typing.List[Event]) -> None:
handle_next(nid, data.nxt.v, join_stack, queue)

for i, entry in enumerate(flow.flowchart.entry_points):
builder.add_node(-1000-i, 'entry', {'name': entry.name})
builder.add_node(-1000-i, 'entry', {'name': entry.name, 'variables': entry.items})
if entry.main_event.v:
builder.add_edge(-1000-i, event_idx_map[entry.main_event.v])
traverse(entry.main_event.v, [])
Expand Down