-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #51 from sethmachine/displaytext-mo-centerview-act…
…ions create rich actions
- Loading branch information
Showing
6 changed files
with
253 additions
and
0 deletions.
There are no files selected for viewing
24 changes: 24 additions & 0 deletions
24
src/richchk/model/richchk/trig/actions/center_view_action.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
26 changes: 26 additions & 0 deletions
26
src/richchk/model/richchk/trig/actions/display_text_message_action.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
26 changes: 26 additions & 0 deletions
26
src/richchk/model/richchk/trig/actions/set_mission_objectives_action.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
61 changes: 61 additions & 0 deletions
61
...hk/transcoder/richchk/transcoders/trig/actions/rich_trig_center_view_action_transcoder.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
) |
58 changes: 58 additions & 0 deletions
58
...oder/richchk/transcoders/trig/actions/rich_trig_display_text_message_action_transcoder.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
) |
58 changes: 58 additions & 0 deletions
58
...er/richchk/transcoders/trig/actions/rich_trig_set_mission_objectives_action_transcoder.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
) |