Time to get rid of the GameEvent objects and move to dictionaries?

Discuss API design here.
User avatar
Ayuto
Project Leader
Posts: 1619
Joined: Sat Jul 07, 2012 8:17 am
Location: Germany

Postby Ayuto » Sat Oct 31, 2015 8:23 am

The plan is to implement __getitem__ and __setitem__. If we still keep the get_<type>/set_<type> methods it's absolutely backwards compatible, because it's just an addition.
Mahi
Senior Member
Posts: 213
Joined: Wed Aug 29, 2012 8:39 pm
Location: Finland

Postby Mahi » Sat Oct 31, 2015 9:16 am

Ayuto wrote:The plan is to implement __getitem__ and __setitem__. If we still keep the get_<type>/set_<type> methods it's absolutely backwards compatible, because it's just an addition.
Sounds really good, perfect not to say. Hopefully you'll also add some kind of to_dict() method or a way of iterating over the event variables!

__iter__ would probably be enough, since you could just do:

Syntax: Select all

d = {var: event[var] for var in event}
User avatar
Ayuto
Project Leader
Posts: 1619
Joined: Sat Jul 07, 2012 8:17 am
Location: Germany

Postby Ayuto » Sat Oct 31, 2015 9:31 am

We can also expose the KeyValues object. Then you would do

Syntax: Select all

event.variables.as_dict()
User avatar
Ayuto
Project Leader
Posts: 1619
Joined: Sat Jul 07, 2012 8:17 am
Location: Germany

Postby Ayuto » Sat Oct 31, 2015 9:31 pm

I have created a new branch for the __getitem__ implementation. https://github.com/Source-Python-Dev-Team/Source.Python/commit/06658ab791b3db65cd83356798d5ac5f86f7fb21

I think the event system is the same on all branches. Some weeks ago I checked the offset of the KeyValues object and it was the same on all games we support. That's why I just reconstructed the structure of CGameEvent and didn't use an offset. Not sure if we want to change that. I honestly don't think we need to.
Mahi
Senior Member
Posts: 213
Joined: Wed Aug 29, 2012 8:39 pm
Location: Finland

Postby Mahi » Sat Oct 31, 2015 9:48 pm

Ayuto wrote:I have created a new branch for the __getitem__ implementation. https://github.com/Source-Python-Dev-Team/Source.Python/commit/06658ab791b3db65cd83356798d5ac5f86f7fb21

I think the event system is the same on all branches. Some weeks ago I checked the offset of the KeyValues object and it was the same on all games we support. That's why I just reconstructed the structure of CGameEvent and didn't use an offset. Not sure if we want to change that. I honestly don't think we need to.
Awesome, this looks fantastic! The system just became infinitely times better with the KeyValues addition, for me at least.
User avatar
satoon101
Project Leader
Posts: 2384
Joined: Sat Jul 07, 2012 1:59 am

Postby satoon101 » Sat Oct 31, 2015 11:24 pm

I went ahead an removed the first event_test branch. I won't be home for a few days, so please feel free to test this out and let us know if you find any issues or if it works perfectly fine. Once we get confirmation, it looks good enough for me to merge into master.
Image
Mahi
Senior Member
Posts: 213
Joined: Wed Aug 29, 2012 8:39 pm
Location: Finland

Postby Mahi » Mon Nov 02, 2015 12:06 pm

satoon101 wrote:I went ahead an removed the first event_test branch. I won't be home for a few days, so please feel free to test this out and let us know if you find any issues or if it works perfectly fine. Once we get confirmation, it looks good enough for me to merge into master.
I've spent 5+ hours with the new system and found absolutely no issues with it. Boolean values seem to always come in as 1 and 0, but that hasn't bothered me (you can still do all operations normally, only identity testing fails) and they can easily be converted using bool() if someone really wants a bool. But other than that, seems to work just fine!
User avatar
satoon101
Project Leader
Posts: 2384
Joined: Sat Jul 07, 2012 1:59 am

Postby satoon101 » Tue Nov 03, 2015 12:09 am

Awesome! I will merge this when I get home tomorrow morning/afternoon if someone else doesn't before then. Thanks again for the suggestion and testing.
Image

Return to “API Design”

Who is online

Users browsing this forum: No registered users and 1 guest