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

create rich actions #51

Merged
merged 1 commit into from
Jun 8, 2024
Merged
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
24 changes: 24 additions & 0 deletions src/richchk/model/richchk/trig/actions/center_view_action.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import dataclasses
from abc import ABC

from ...mrgn.rich_location import RichLocation
from ..rich_trigger_action import RichTriggerAction, _RichTriggerActionDefaultsBase
from ..trigger_action_id import TriggerActionId


@dataclasses.dataclass(frozen=True)
class _CenterViewActionBase(RichTriggerAction, ABC):
_location: RichLocation

@classmethod
def action_id(cls) -> TriggerActionId:
return TriggerActionId.CENTER_VIEW

@property
def location(self) -> RichLocation:
return self._location


@dataclasses.dataclass(frozen=True)
class CenterViewAction(_RichTriggerActionDefaultsBase, _CenterViewActionBase):
pass
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import dataclasses
from abc import ABC

from ...str.rich_string import RichString
from ..rich_trigger_action import RichTriggerAction, _RichTriggerActionDefaultsBase
from ..trigger_action_id import TriggerActionId


@dataclasses.dataclass(frozen=True)
class _DisplayTextMessageActionBase(RichTriggerAction, ABC):
_text: RichString

@classmethod
def action_id(cls) -> TriggerActionId:
return TriggerActionId.DISPLAY_TEXT_MESSAGE

@property
def message(self) -> RichString:
return self._text


@dataclasses.dataclass(frozen=True)
class DisplayTextMessageAction(
_RichTriggerActionDefaultsBase, _DisplayTextMessageActionBase
):
pass
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import dataclasses
from abc import ABC

from ...str.rich_string import RichString
from ..rich_trigger_action import RichTriggerAction, _RichTriggerActionDefaultsBase
from ..trigger_action_id import TriggerActionId


@dataclasses.dataclass(frozen=True)
class _SetMissionObjectivesActionBase(RichTriggerAction, ABC):
_text: RichString

@classmethod
def action_id(cls) -> TriggerActionId:
return TriggerActionId.SET_MISSION_OBJECTIVES

@property
def message(self) -> RichString:
return self._text


@dataclasses.dataclass(frozen=True)
class SetMissionObjectivesAction(
_RichTriggerActionDefaultsBase, _SetMissionObjectivesActionBase
):
pass
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
"""Decode Center View trigger action."""

from ......model.chk.trig.decoded_trigger_action import DecodedTriggerAction
from ......model.richchk.mrgn.rich_location import RichLocation
from ......model.richchk.richchk_decode_context import RichChkDecodeContext
from ......model.richchk.richchk_encode_context import RichChkEncodeContext
from ......model.richchk.trig.actions.center_view_action import CenterViewAction
from ......util import logger
from ..rich_trigger_action_transcoder import RichTriggerActionTranscoder
from ..rich_trigger_action_transcoder_factory import (
_RichTriggerActionRegistrableTranscoder,
)


class RichTriggerCenterViewActionTranscoder(
RichTriggerActionTranscoder[CenterViewAction, DecodedTriggerAction],
_RichTriggerActionRegistrableTranscoder,
trigger_action_id=CenterViewAction.action_id(),
):
def __init__(self) -> None:
self.log = logger.get_logger(RichTriggerCenterViewActionTranscoder.__name__)

def _decode(
self,
decoded_action: DecodedTriggerAction,
rich_chk_decode_context: RichChkDecodeContext,
) -> CenterViewAction:
assert decoded_action.action_id == CenterViewAction.action_id().id
assert rich_chk_decode_context.rich_mrgn_lookup is not None
maybe_location = rich_chk_decode_context.rich_mrgn_lookup.get_location_by_id(
decoded_action.location_id
)
assert isinstance(maybe_location, RichLocation)
return CenterViewAction(
_location=maybe_location,
)

def _encode(
self,
rich_action: CenterViewAction,
rich_chk_encode_context: RichChkEncodeContext,
) -> DecodedTriggerAction:
assert rich_chk_encode_context.rich_mrgn_lookup is not None
maybe_location_id = rich_chk_encode_context.rich_mrgn_lookup.get_id_by_location(
rich_action.location
)
assert maybe_location_id is not None
return DecodedTriggerAction(
_location_id=maybe_location_id,
_text_string_id=0,
_wav_string_id=0,
_time=0,
_first_group=0,
_second_group=0,
_action_argument_type=0,
_action_id=rich_action.action_id().id,
_quantifier_or_switch_or_order=0,
_flags=0,
_padding=0,
_mask_flag=0,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
"""Decode Victory trigger action."""

from ......model.chk.trig.decoded_trigger_action import DecodedTriggerAction
from ......model.richchk.richchk_decode_context import RichChkDecodeContext
from ......model.richchk.richchk_encode_context import RichChkEncodeContext
from ......model.richchk.trig.actions.display_text_message_action import (
DisplayTextMessageAction,
)
from ......util import logger
from ..rich_trigger_action_transcoder import RichTriggerActionTranscoder
from ..rich_trigger_action_transcoder_factory import (
_RichTriggerActionRegistrableTranscoder,
)


class RichTriggerDisplayTextMessageActionTranscoder(
RichTriggerActionTranscoder[DisplayTextMessageAction, DecodedTriggerAction],
_RichTriggerActionRegistrableTranscoder,
trigger_action_id=DisplayTextMessageAction.action_id(),
):
def __init__(self) -> None:
self.log = logger.get_logger(
RichTriggerDisplayTextMessageActionTranscoder.__name__
)

def _decode(
self,
decoded_action: DecodedTriggerAction,
rich_chk_decode_context: RichChkDecodeContext,
) -> DisplayTextMessageAction:
assert decoded_action.action_id == DisplayTextMessageAction.action_id().id
return DisplayTextMessageAction(
_text=rich_chk_decode_context.rich_str_lookup.get_string_by_id(
decoded_action.text_string_id
)
)

def _encode(
self,
rich_action: DisplayTextMessageAction,
rich_chk_encode_context: RichChkEncodeContext,
) -> DecodedTriggerAction:
return DecodedTriggerAction(
_location_id=0,
_text_string_id=rich_chk_encode_context.rich_str_lookup.get_id_by_string(
rich_action.message
),
_wav_string_id=0,
_time=0,
_first_group=0,
_second_group=0,
_action_argument_type=0,
_action_id=rich_action.action_id().id,
_quantifier_or_switch_or_order=0,
_flags=0,
_padding=0,
_mask_flag=0,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
"""Decode Victory trigger action."""

from ......model.chk.trig.decoded_trigger_action import DecodedTriggerAction
from ......model.richchk.richchk_decode_context import RichChkDecodeContext
from ......model.richchk.richchk_encode_context import RichChkEncodeContext
from ......model.richchk.trig.actions.set_mission_objectives_action import (
SetMissionObjectivesAction,
)
from ......util import logger
from ..rich_trigger_action_transcoder import RichTriggerActionTranscoder
from ..rich_trigger_action_transcoder_factory import (
_RichTriggerActionRegistrableTranscoder,
)


class RichTriggerSetMissionObjectivesActionTranscoder(
RichTriggerActionTranscoder[SetMissionObjectivesAction, DecodedTriggerAction],
_RichTriggerActionRegistrableTranscoder,
trigger_action_id=SetMissionObjectivesAction.action_id(),
):
def __init__(self) -> None:
self.log = logger.get_logger(
RichTriggerSetMissionObjectivesActionTranscoder.__name__
)

def _decode(
self,
decoded_action: DecodedTriggerAction,
rich_chk_decode_context: RichChkDecodeContext,
) -> SetMissionObjectivesAction:
assert decoded_action.action_id == SetMissionObjectivesAction.action_id().id
return SetMissionObjectivesAction(
_text=rich_chk_decode_context.rich_str_lookup.get_string_by_id(
decoded_action.text_string_id
)
)

def _encode(
self,
rich_action: SetMissionObjectivesAction,
rich_chk_encode_context: RichChkEncodeContext,
) -> DecodedTriggerAction:
return DecodedTriggerAction(
_location_id=0,
_text_string_id=rich_chk_encode_context.rich_str_lookup.get_id_by_string(
rich_action.message
),
_wav_string_id=0,
_time=0,
_first_group=0,
_second_group=0,
_action_argument_type=0,
_action_id=rich_action.action_id().id,
_quantifier_or_switch_or_order=0,
_flags=0,
_padding=0,
_mask_flag=0,
)
Loading