-
Notifications
You must be signed in to change notification settings - Fork 3
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
Message Bus v1 #61
Message Bus v1 #61
Conversation
You're learning a lot, hah. Some quick articles for you: |
I feel like a good portion of the re-writes are in how combat is done. Changing from a handful of functions to a class is putting my logic skills to the test. Aside from that, converting all of the items to classes is more time-consuming than difficult. |
I need a system for registering and unregistering components so enemies only have their callback functions called when they are in combat.
@miketwo Could you give an example of how this code works? def subscribe(self, event_type: Message, callback, uid):
if event_type not in self.subscribers:
self.subscribers[event_type] = dict()
self.subscribers[event_type][uid] = callback
if self.debug:
ansiprint(f"<basic>MESSAGEBUS</basic>: <blue>{event_type}</blue> | Subscribed <bold>{callback.__qualname__}</bold>") The main thing I'm confused about is how the dictionary is structured. I kinda need to know that if I'm going to have an |
Yeah. It's a dictionary of dictionaries. The Message is the first key, the UID is the second. So it'll look something like:
The unique combination of a message and uid gets you a specific callback. Subscribing with the same message and uid overwrites the callback. An unsubscribe would need to know both those values. I'll push a commit with a test that demonstrates it. |
…tate during combat instead of them being removed from the enemies list.
Why won't grandalf install. The tests fail when I run them because of it but even if I use |
Right now I'm struggling with how to manipulate the |
|
Not sure I know what you mean... Cause there's already code around potion drops and gen.cards_rewards, right? So is it erroring out? Or you need something else to happen here? |
I'll start rewriting the tests. Cause it's such a big change that I'm sure most of them will break (for not valid reasons). |
The problem I have is that I need to decide whether or not to give the player rewards based on what the last alive enemy did. If the last enemy escaped then I wouldn't give the player rewards. If the last enemy died then I would give the rewards. I'm not sure how to know if the last enemy died or escaped or what the last enemy is in the first place. |
Have enemies fire messages on death/escape, catch the message in Combat and check conditions for last enemy/rewards? |
Sounds like a solution! |
I just started using linux(in vm) and I have already phased out the need for docker desktop. I love the terminal. Edit: I need docker desktop lol |
WSL2 is pretty cool overall. |
Add more message bus tests
Currently getting brainrot from Rust while trying to convert hex to rgb. It's fun tho. |
All good. I can't really code anything until the mega-PR-rewrite is done (cause it'll have conflicts). Do you want to do it in smaller chunks? |
Like smaller commits? I could do that. |
Yeah more like keeping the branch-commit-merge cycle tight. Cause if there's a branch that changes a whole bunch of files, any other branches made while that's open run the risk of conflicts. |
Ah, ok. I'm just struggling with finding out how to make the enemies communicate with the combat class when they die/escape. |
Forgot to add that I fixed combat not initializing. |
Re-enabled the tests. Why is |
That was not intentional. I meant to make it a tuple but didn't realize that using parentheses made a generator. I had to fix that when making the death message system but I didn't remember that I made the same mistake with |
I don't know why |
@miketwo Could using a |
Edit: No. I can just make the relics and such that activate only when cards are used return early if the card parameter is |
Neovim is the best editor I've used. |
Working on adding potions rn |
@miketwo Should I try and remove global variables whenever necessary? I'm trying to get rid of |
Yes. Global constants are ok, but anything mutable should have a smaller scope. Otherwise it couples together very distant parts of the code. It can be annoying to pass context around, but it shows where things are connected. The alternative is untraceable bugs that happen when something mutates your global when it's not supposed to. |
`Player.attack()`'s dmg variable is now updated after the event BEFORE_ATTACK is triggered.
Never doing a big pr like this again. It feels like development is going very slow right now. |
Definitely keeping this in mind once this whole brainrot session is over with. Is there anything I can do right now to improve it? |
Mikado Method works sometimes. Which is like figure out all the things you were trying to do simulateneously here (rewrite combat system, remove globals, change Game into a class, ....) and break them all apart. Revert and work your way down the pre-reqs. You know a lot more now about the problems you're going to run into, so you can just solve those pre-reqs first. Don't try to boil the ocean, just start with a pot of water. So long as you've got the branch, you can always refer back to it or copy code over. But do it in much smaller chunks. For example: A PR that only removes 1 global var, not all of them. Or a PR that only uses the message bus once, for like START_OF_COMBAT or something. Little improvements that stack. |
No more. |
It turns out that restructuring the entire game is a little hard.