Friday, July 20, 2018

Extensible Style

Originally Posted September 11th, 2017


Unlike clothing, it doesn't make much sense to randomly generate things like hairstyles, makeup styles, and jewelry. 

The most common examples of style options I've seen usually involve some code that allows the player to select from a few different options, and then set the game's variables based on that choice. The problem with this is that it often requires new code for each instance where the style might be affected, or simply reusing the same menu/location/process each time. (An example of this can be found in Girl Life, where a "mirror" location is reused to set makeup, and is presented as a link to the location from any bathroom.)

Depending on how it's done, this method can work quite well, and even save some time setting up (depending on the complexity). Girl Life's mirror, to follow the earlier example, works perfectly fine. A common limitation of this methodology, and what I'm trying to avoid in general, is the difficulty or extra time needed to add to it (for either function or variety). Rather than make a hard-coded set of styles for any of these categories, I think it's much more practical to make an extensible set of styles and jewelry. 

Object-Based Styles
One of the strengths of JavaScript, at least to my mind, is the ease with which it allows the use of objects. I've been coding all the "grooming stuff" in an extensible object-based manner. Individual hairstyles, for example, exist as part of a larger hairstyle object, and contains all the information needed to use them in the game. As a variable, they can be used anywhere, and adding a new style is as simple as declaring a new property; no extra coding required, and definitely no chasing down various portions of code that need to be updated to use the style.

The image above is a picture of the code that determines which hairstyles are available to the player. It iterates through all the different hairstyles, checking for a simple Boolean to see if the player knows that hairstyle. If so, the name is wrapped in apostrophes and added to a string that is used to print a drop-down macro call. This has the added advantage of making it very easy to utilize the style, as the player is essentially choosing the object index that they want when using the drop-down.

In the future, should new styles be needed (or wanted), adding them is a simple matter of working out their stats, putting them in the variable declaration passage (and backward compatibility), and adding them to the list of one or more shops/salons in Appletree. The clothing system supports ad-hoc addition of clothing items as well, but operates differently because most clothing is procedurally generated.

The Springtime Release v1.26

This summary is not available. Please click here to view the post.