AnssiR66 / AlanStdLib

The Standard Library for ALAN Interactive Fiction Language
Other
6 stars 2 forks source link

New 'wearer' Attribute along with 'worn' #134

Closed tajmone closed 2 years ago

tajmone commented 2 years ago

@AnssiR66, while working on the code to handle wearable items in the new Foundation Library at ALAN-i18n, we've implemented a simplified version of the StdLib wearing mechanics (i.e. using the worn attribute instead of the old ENTITY, but not the clothing class or layered body strata, just the wearable attribute for any type of wearable items).

But in doing so, we came up with an extra attribute: wearer — a reference attribute which points either to wearing actor or the the nobody dummy actor.

Initially, we wanted to use just wearer, without worn, since if the wearer of an item is nobody you already know that its' not worn. But, as it turned out, aggregators' filters only work with boolean attributes, so we had to keep both.

The advantage of adding the extra wearer attribute is that at any time you can print the name of the wearing actor via Say wearer of this, without having to iterate through all actors to determine who's wearing it.

This adds a bit of code overhead, i.e. the need to set wearer of this to nobody every time an items is moved around (just as we're doing with worn), to ensure there are no wearable items around which are still set as is worn. Nonetheless, I think it's a nice addition which is worth the price, because being able to so easily access the wearer in messages can be very handy (and the extra code is just an additional line wherever the worn attribute is already being manipulated).

You can follow the discussion that led to this new approach, here:

alan-if/alan-i18n#18

Let me know what you think about the possibility of also adopting wearer in the StdLib. Its implementation won't take too much work, and I personally think it's worth it, and since the new wearing mechanics haven't yet been released (except in the early-access preview release of last Christmas) we're still in time to throw that into the bag of new clothing features for v2.2.0.

AnssiR66 commented 2 years ago

All this is fine and I think it is a useful addition, so we can go ahead.

tajmone commented 2 years ago

WIP in Dedicated Branch

@AnssiR66, I've implemented the new wearer attribute in the dev-wearer-attribute branch, which you can access on GitHub via the previous link or checkout locally to carry out your own tests (better).

I've spent the whole morning on it, and have checked that all the clothing tests were not broken by the new changes; so far everything seems to work fine.

Here you can view the tests transcripts from the dev branch:

Since I've used this feature in the Foundation library (English, Spanish and Italian) already, it was pretty much a work of adding a feature which had already been tested elsewhere, so I'm quite confident that everything is working as expected.

Unlike the Foundation library, here I've also added to the ACTOR class initialization some safeguards that iterate over every worn item IN actors and correctly sets the item's wearer to that ACTOR — this spares authors from also having to set the wearer attribute when defining items which are worn at game start, i.e. taking care of the worn attribute is enough, and the library will handle the rest:

The coat IsA clothing in hero
  Is worn.
End the.

Of course, if the adventure programmatically shifts around worn items (e.g. in scene changes) then the author must remember to also set the wearer attribute, since the library also caters for it at initialization time, and there are no turn-based events that further deal with this (sounds reasonable to me).

Before Merging...

Before squashing dev-wearer-attribute into the main dev branch I still have to update the CHANGELOG and the markdown doc with the notes on the new clothing system, and possibly also the Clothing Tutorial.

I decided to work on this new feature now, so I can then start rewriting the Clothing chapter of the StdLib Manual at once — and not having to tweak again in the future.

I also thought this was a feature worth adding in v2.2.0, since we're already revamping the entire clothing system it made no sense to postpone it to the second next release. It's a neat addition and makes the code easier to read too.

Can You Check it?

Even though I'm pretty confident that the code should be fine, I'd still appreciate if you could go through the changes and double check that I didn't forget anything — you never know what I might have missed during the process!

Before the dedicate branch is squashed into the dev baseline you should benefit from the fact that every commit deals with a separate aspect (library sources, tests, documentation, etc.), whereas once we squash everything into a single commit it might not be so easy to track changes.

It will probably take a few days before I'm ready to squash, since I'll have to tweak various documents here and there.

AnssiR66 commented 2 years ago

I've been meaning to reply before but as I said May is very busy for me and I've never got as far as actually testing the code snippet yet. I promise I will give it a try today and let you know how it looks. Thanks for your patience!

AnssiR66 commented 2 years ago

I have now gone through the code of ega.alan, without actually playing the game yet. A nice, helpful and extensive example game, and I would have some comments mainly on spelling:

There is no compiled game file for this, right? I will play it later today and comment further.

tajmone commented 2 years ago

There is no compiled game file for this, right?

No, the repository is set to ignore compiled storyfiles to save on space. The assumption is that end users (which in this case are always project maintainers) will simply build the project locally.