I am currently developing an interactive story using OpenFL and I am currently going through the process of optimising my engine for a C++ output, since that is what my focus will be on. The master branch over on Github has a functional Flash target working, but this uses anchor links to identify hyperlinks in the links to different passages, and the Haxe code to parse using HScript.
I know that hyperlinks do not work in the C++ target, so I took a look at using the “getCharIndexAtPoint()” function to determine the location of a link in the htmlText field. I do not know what HTML text supports what in C++, but if none of the tags are supported at all, then I may as well write my own parser.
This is my current code for an attempt to parse my links using traditional link formatting in interactive stories:
private function parseLink(s:String):String
{
_parsedLinks.splice(0, _parsedLinks.length);
var pos:Int = 0;
var content = s;
while (pos < content.length)
{
if (!(content.indexOf("[") > -1 && content.indexOf("]") > -1)) break;
pos = content.indexOf("[");
var subs = content.substring(pos + 1, content.indexOf("]"));
if (subs.indexOf("|") > -1)
{
var link = subs.split("|");
var parsedLink:ParsedLink = new ParsedLink();
parsedLink.code = link[1];
parsedLink.startIndex = s.indexOf(link[0]);
parsedLink.endIndex = s.indexOf(link[0].charAt(link[0].length));
trace("Link text: " + link[0] + "\n" + "Link code: " + link[1]);
_parsedLinks.push(parsedLink);
content = content.substr(parsedLink.endIndex + 1);
trace("Content: " + content);
s = StringTools.replace(s, parsedLink.code, "");
}
}
s = StringTools.replace(s, "[", "");
s = StringTools.replace(s, "]", "");
s = StringTools.replace(s, "|", "");
return s;
}
private function onLinkClicked(e:MouseEvent):Void
{
var idx:Int = e.currentTarget.getCharIndexAtPoint(e.localX, e.localY);
for (i in 0..._parsedLinks.length)
{
if (idx >= _parsedLinks[i].startIndex && idx < _parsedLinks[i].endIndex)
{
runCode(_parsedLinks[i].code);
break;
}
}
}
At least, that's the general idea. Unfortunately, the given code results in this output. Any thoughts on how to solve this?