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

Adding a context manager for Event #6412

Merged

Conversation

ThePotatoGuy
Copy link
Member

@ThePotatoGuy ThePotatoGuy commented Sep 29, 2020

dev QOL addition

Key Changes

  • adds a dummy class that does nothing but can be hurt in a variety of ways (MASDummyClass)
  • adds a context manager wrapper around Event that can be used to do things to/with an event object without having to None check - MAS_EVL

example:

normal_ev = mas_getEV("a_label")
get_value = None
with MAS_EVL("some_label") as ev:
    ev.unlocked = True
    ev.checkAffection(value)
    cmp_value = normal_ev == ev
    get_value = ev.shown_count
    # etc...

The above will not crash even if a bad label (or no event object found) occurs, unless you write code that would have crashed normally anyway (like calling ev.checkAffection with no arguments, etc...).

In a bad scenario, the behavior of different actions on the ev var vary:

  • all Event-based properties return default values
  • setting properties does nothing
  • function calls do nothing
  • the Event class is used as a fallback for everything else.

Two caveats:

  1. None checking ev doesnt work (well obviously).
  2. when calling a function on a bad ev, the object actually being called on is the MASDummyClass. if pre-determined default behavior is more desirable, then _default_values can be expanded.

Important things to remember

The normal way (None checking mas_getEV) allows us to include backup scenarios if something is off or data is missing. This with version of Event should only be used when we don't care about a bad case.

Testing

  • try stuff in console. In general, all things normally done with an Event object can be done with an instance of MAS_EVL regardless of the eventlabel's validity. If the eventlable is real, then the Event object will be modified. Otherwise nothing should happen. And as a reminder, anything that doesn't work with a real Event object will not work with the context manager version.

@ThePotatoGuy ThePotatoGuy added awaiting testing code needs to be tested awaiting code review someone needs to check for syntax/logic/indentation errors labels Sep 29, 2020
@ThePotatoGuy ThePotatoGuy added this to the 0.11.6 milestone Sep 29, 2020
@ThePotatoGuy ThePotatoGuy added this to awaiting review in core via automation Sep 29, 2020
core automation moved this from awaiting review to awaiting merge Oct 5, 2020
@ThePotatoGuy ThePotatoGuy removed awaiting code review someone needs to check for syntax/logic/indentation errors awaiting testing code needs to be tested labels Oct 5, 2020
@ThePotatoGuy ThePotatoGuy merged commit 524ad69 into Monika-After-Story:content Oct 5, 2020
core automation moved this from awaiting merge to done Oct 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
core
  
done
Development

Successfully merging this pull request may close these issues.

None yet

3 participants