-
Notifications
You must be signed in to change notification settings - Fork 0
Patterns
Next Section: Scripting
Previous Section: Stackup
A discussion on how patterns are created.
This library uses string interpretation to generate patterns. Even complex patterns can be represented easily with just a few characters. This is generally much quicker than manually writing loops to spawn walls in the correct locations with varying thickness values.
Before going over how the pattern syntax works we need to establish a baseline for how patterns should be represented and constructed. There are various ways in which this can be done. The method shown here is sufficient for most situations.
Almost all patterns can be broken down into the same constituent parts. Take this tunnel for example:
It can be broken down into three rings which are highlighted in different colors below:
What is important is that each ring contains walls that have the same thickness. This simplifies pattern creation as we can "stack" each of these rings on top of each other to create the pattern. Note that technically the very large wall on the far left side could be merged into a single wall. However, this is not done as it would introduce unneccessary complexity. By keeping all walls in rings of equal thickness, we can consistently predict how long we need to wait to space each of the rings out appropriately. (There are ways to create rings with differing wall thicknesses but that will not be discussed.)
Next, each ring can be broken down into walls or gaps. Normally, this is done with a "starting side" or pivot and a loop that "circles" the shape while spawning walls, but this can be rather tedious to manage. Patternizer provides a more efficient solution: P-Strings.
Utilizing string interpretation, P-Strings can represent even complex patterns with just a few characters. To understand p-strings, lets take the example ring below of a barrage:
Note: In all ring examples, the pivot side is highlighted red and the direction of spawning is indicated by the arrow.
An obvious (albeit naive) approach is to have one character represent a wall and another represent a gap and create them in order, clockwise around the shape:
_.....
Note: The rest of this page uses a period to represent the precense of a wall and an underscore for the absence of a wall.
However, this is not very elegant as we would have to manually specify every wall. Since many common rings have repeated character patterns, we can use the looping syntax:
_|.
Any group placed before the pipe is spawned only once. Any group placed after the pipe is looped indefinitely until the shape is filled. This p-string, when spawned, looks identical to the one above except that it has the advantage that it generalizes to any side count.
Another common ring is the alt-barrage which can be represented as:
|._
In this example, there are no characters before the pipe which means that the entire pattern is repeating.
Note: The pipe is optional. If ommitted, the group is considered non-looping.
The combination of a non-looping and looping group is referred to as a division. In the previous examples, there has only been one division. However, having only one division is still fairly limiting, so p-strings can have multiple divisions where groups can act independently.
Below is a barrage where the gap is on the opposite side of the pivot:
Note: There are two arrows to illustrate the divisions.
It would be impossible to produce a generalized solution with a single division, but with two divisions it is possible:
|./_|. OR |.+_|.
Each division divides the shape up as evenly as possible for each group to occupy. Divisions are separated by plus signs or slashes. (In this example, it does not matter whether a plus or slash is used but there is a difference between the two that will be discussed later.)
Since the above p-string has two divisions, the shape is divided into two halves: One which goes from 0-2 and the other from 3-5. The first group (|.) is interpreted starting at the pivot. This group fills the entire first division with walls. The next group (_|.) spawns a gap at side 3 and fills sides 4 and 5 with walls.
Often, it is not possible to divide a shape evenly for divisons to occupy, so they have to be rounded. This rounding behavior can be controlled by choosing to use a plus or slash to separate divisions. In the below examples, a pentagon is divided into two divisions. Whether the first or second division takes the remaining side is decided by the plus or slash.
A slash rounds down, making the first division the smaller of the two.
|./_|.
A plus rounds up, making the first division the larger of the two.
|.+_|.
In short, a / will always shrink the division to its left and grow the division to its right if neccessary. A plus does the opposite.
A tilde can be placed in front of a p-string to mirror it. This causes the p-string to circle the shape in the opposite direction. The below p-string creates a gap facing upwards:
|.-.
To face the opening downwards, we could rewrite the p-string or simply mirror what we already have:
Note: The arrows have reversed their direction.
~|.-.
When using Stackup there is a global mirror state which applies to all patterns. It is randomly initialized whenever a pattern is called. This prevents the need to create separate left-handed and right-handed versions of patterns.
- P-Strings only communicate the presence or absence of a wall.
- The pivot and thickness of a ring are always given from an external source.
- If a division is too small to accomodate all possible characters in a group, the leftover characters are ignored.
- If a division is too large to accomodate all possible characters in a group, the remaining space is ignored.
- Only alphanumeric characters, periods, and underscores (
A-Z a-z 0-9 . _) can be used to spawn walls. The tilde, pipe, plus, slash, and minus (~ | + / -) characters are reserved.Note: The minus sign is equivalent to the slash but its use is discouraged since it can conflict with the Stackup comment syntax.
A completed structure of walls that serves as an obstacle to the player.
The first smaller component of a pattern. Consists walls of equal thickness and/or gaps.
An anchor side from which rings are generated. Stackup uses two: an absolute pivot and relative pivot.
A group of characters in a p-string. Can be non-looping or looping, which are separated by a pipe.
The combination of a non-looping and/or looping section in a p-string. Separated by plus or slash characters.
The information presented in this wiki is not guaranteed to be accurate. The information presented may be a few versions old.