A downloadable asset pack

Download NowName your own price

Originally created for our bi-quarter project at ACM Studio at UCLA. A framework for designing custom parser logic.

To use the parser:

Define somewhere in your Unity project a series of node class, which implement the INode interface.

Within the nodes (recommanded) or outside, define a factory class for that node, and implement the base class NodeFactory<Nodetype> (where Nodetype is the type of node this factory class should produce). Implement MyTags(), method to get an array of string tags used to identify Twine blocks, and MakeNode(), which should contain all the initialization work for an empty node. Tags returned from MyTags() will be used to identify blocks in the input Twine file, ones that contain all of them (extra tags are allowed and will be recorded in the return data structure, more details later).

Then let the factory class implement NodeFactoryBase.Production, this interface tells the parser to use this factory class. It's primarily designed to enable selective activation of the factory classes for the convenience of debugging.

Inside the factory (recommanded) or outside, define a series of line parser classes implementing the base class LineParser<Nodetype>. In each of these line parsers, there are 2 crucial functions: GetMyMatch() and TakeAction(). GetMyMatch() should return a .Net regular expression that matches all and nothing but lines corresponding to this line parser; TakeAction() is callback for processing a line when a line is matched: get a reference to the node currently under construction, and add/change information within it.

The setup of this package is intended to allow user to associate each block in the twine file with a INode object, and define all the logic of a type of node inside a single file (runtime logic, creation, ...). 

The top-level entry to this utility is TwineParser class. To use it, create a new TwineParser instance and call ParseTwine(text asset), where text asset is the text asset contianing your Twine script (the html output file).

Return from ParseTwine() is a NodeCollection class, which has 2 fields: allNodes, tagNodes: allNodes is a dictionary mapping block names to the converted node objects and tagNodes is a dictionary mapping block tag to a list of all nodes having that tag. 

The last piece of this package is INode interface, which is just a standard state machine interface containing Initialize(), Update(), and NextNode(). There's no code pre-inserted to any of those so feel free to use this interface however you see fit.

Dependency (included in the asset package):

HTML Agility Pack, a .Net package for parsing HTML files.

Unity Version:

Created on 2019.4.18f1 LTS, but it should work with any recent version since most of it is .Net code.

StatusReleased
CategoryAssets
Rating
Rated 5.0 out of 5 stars
(1 total ratings)
AuthorJohnnyWan
GenreVisual Novel
Tagscodebase, Unity

Download

Download NowName your own price

Click download now to get access to the following files:

NodeSystem.unitypackage 83 kB

Leave a comment

Log in with itch.io to leave a comment.