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 a "CharacterFilter" class #32

Closed
wsowens opened this issue Feb 25, 2019 · 3 comments
Closed

Add a "CharacterFilter" class #32

wsowens opened this issue Feb 25, 2019 · 3 comments
Assignees
Labels
enhancement New feature or request

Comments

@wsowens
Copy link
Member

wsowens commented Feb 25, 2019

Right now, the Exit class has a lot of specialized code to deal with allowing certain CharacterClasses in, and keeping certain CharacterClasses out.

In the interest of abstraction, we should abstract this code out into a new class, CharacterFilter. We could then painlessly reuse this functionality for items and entities later. This would solve Issue #27 as well.

@wsowens wsowens added the enhancement New feature or request label Feb 25, 2019
@wsowens wsowens self-assigned this Feb 25, 2019
@wsowens
Copy link
Member Author

wsowens commented Feb 27, 2019

I've implemented this feature on the branch class-filter.
Here's a test:

from character import *

class Magical(Character):
    pass

class Brute(Character):
    pass

class Wizard(Magical):
    pass

class Witch(Magical):
    pass

steve = Character()
steve.set_name("steve")
gandalf = Wizard()
gandalf.set_name("gandalf")
bill = Wizard()
bill.set_name("bill")
sabrina = Witch()
sabrina.set_name("sabrina")
rich_piana = Brute()
rich_piana.set_name("rich piana")

filters = {
    "salty_spitoon" : CharFilter(True, [Brute]),
    "no_brutes_allowed" : CharFilter(False, [Brute]),
    "magic_users_club" : CharFilter(True, [Magical]),
    "we're fine with wizards, we just hate bill" : CharFilter(False, [bill])
}

for name, filter in filters.items():
    print("Testing: %s" % name)
    for thing in [steve, gandalf, bill, sabrina, rich_piana, Character, Magical, Wizard, Witch, Brute]:
        print(str(thing).strip(), filter.allows(thing), sep="\t")

Results:

Testing: salty_spitoon
steve	False
gandalf	False
bill	False
sabrina	False
rich piana	True
Default Character	False
Magical	False
Wizard	False
Witch	False
Brute	True
Testing: no_brutes_allowed
steve	True
gandalf	True
bill	True
sabrina	True
rich piana	False
Default Character	True
Magical	True
Wizard	True
Witch	True
Brute	False
Testing: magic_users_club
steve	False
gandalf	True
bill	True
sabrina	True
rich piana	False
Default Character	False
Magical	True
Wizard	True
Witch	True
Brute	False
Testing: we're fine with wizards, we just hate bill
steve	True
gandalf	True
bill	False
sabrina	True
rich piana	True
Default Character	True
Magical	True
Wizard	True
Witch	True
Brute	True

@wsowens
Copy link
Member Author

wsowens commented Feb 27, 2019

Now we must rewrite this part of the Exit class, and add this to the item class. After with do the latter, #27 will be effectively solved.

@wsowens
Copy link
Member Author

wsowens commented Mar 1, 2019

The location.Exit class now supports the CharFilter, I'm considering this issue closed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant