This page talks about the DSAction: A generic type for classes that execute code when called by the DSActionQueue.actionQueue List.
This class is the core of how DeckStacker is designed: One thing happens at a time.
DSActionQueue will look at the index 0 DSAction in the actionQueue, and call its Execute() method.
The intention behind this is so the developer can queue up several actions at the time of an event, and then those actions can play out, one at a time.
The DSActionQueue.actionQueue List is a List<DSAction>, thus each class instance that is queued up is required to inherit from the DSAction class.
Let’s take a look at the DSAction class to understand more:
namespace DeckStacker { public abstract class DSAction { (_type is used for logging actions to console.) protected System.Type _type = null; (Prevents an action from being logged to console multiple times.) protected bool _actionLogged = false; (Override this abstract method to call code when this DSAction is at the front of the DSActionQueue's actionQueue.) public abstract void Execute(); (Resolving a DSAction removes it from the DSActionQueue.actionQueue, and allows the next DSAction to be executed on the next Update.) public void Resolve() { DSActionQueue.RemoveAction(this); if (DSDebugSettings.logActions) { Debug.Log(System.String.Format("Action: {0} resolved.", _type.ToString())); } } (A more friendly way of typing "_type.ToString()".) public string PrintType() { return _type.ToString(); } (When DSDebugSettings.logActions is enabled, this allows the DSAction to print logs to the console.) protected void LogAction(string actionMessage) { if (DSDebugSettings.logActions && !_actionLogged) { Debug.Log(actionMessage); _actionLogged = true; } } } }
Key takeaways:
One of the most critical takeaways: DSAction is not useable, on its own, and it really doesn’t do a whole lot.
The intention behind this is to be as flexible as possible, and allow developers to write their own DeckStacker Actions with ease.
DeckStacker comes equipped with a list of Core Actions to cover the basics of what a card game needs:
Be sure to visit each of the API docs pages for these actions to understand their intention.
When forming this list of DSActions, I went through all the different systems of DeckStacker and asked myself “Would this be useful if it was timed out in a queue of actions?”.
I think this list covers most of what is useful in DeckStacker, but I find that each time I start making a game with it, the game design I am working with at the time always seems to find new scenarios that I hadn’t thought of. Don’t expect this list of DSActions to cover everything you need for a game.
In the very likely event that you’ll need to make your own DSActions (I refer to these as “Custom Actions”), a template script has been added to DeckStacker to cover the boilerplate code.
namespace DeckStacker { public class DSTemplateAction : DSAction { (CONSTRUCTOR FIELDS) (enter fields here) (Standard Constructor: Add parameters if needed.) public DSTemplateAction() { _type = this.GetType(); } (This code will execute when this DSAction is at the 0 index of the DSActionQueue.actionQueue list, and an RunUpdate call has been made.) public override void Execute() { LogAction(System.String.Format("Action: {0}", _type.ToString())); (Action code here) Resolve(); } } }
This template action is 90% of the way to coding a simple Custom Action.
Here are some key takeaways:
With that understanding, let’s discuss guidelines for making your own Custom Actions.
Here are some basic guidelines you will want to employ when making Custom Actions:
It's critically important to understand Custom Action writing, so read through this page carefully, and open the provided DSAction scripts for examples. It is inevitable that you'll need to write your own DSActions, unless your usecase for DeckStacker is extremely limited.
Now go forth and make fun card games!