-
Notifications
You must be signed in to change notification settings - Fork 435
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added formatParse to FlxText: t.text="show $green text$ between dollar s... #1229
Conversation
…r signs"; t.formatParse([greenFormat],["$"]);
addFormat(formatsToApply[i], range_starts[i], range_ends[i]); | ||
} | ||
|
||
//Clean up arrays created for this function |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this is necessary, these are not going to be around after this function has finished anyway.
* @param markers corresponding marker strings, such as "@" or "$" (rarely used single-characters recommended) | ||
*/ | ||
|
||
public function formatParse(formats:Array<FlxTextFormat>, markers:Array<String>):Void |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What happens when formats.length != markers.length
or one of the two contains null entries?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The former issue could be avoided by abstracting the format and its marker into an object:
typedef FormatMarkerPair =
{
format:FlxTextFormat,
marker:String
}
That would mean an Array<FormatMarkerPair>
is used.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably a crash. Let me throw in some explicit errors if that's the case. formats.length should always == markers.length or else user intent is ambiguous.
If the case of one of the entries being null:
- If a marker is null, right now the corresponding format is probably ignored
- If a format is null, a crash will probably happen
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can put in some checks and errors, but just thought:
What if the formats.length and markers.length are 0, or both are null? Should it:
- Throw an error (what's the point of running this if it would do nothing?)
- Do nothing (not even call clearFormats()) ?
- Call clearFormats(), then return immediately?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah... I guess in flixel there are actually very few functions that guard against null errors, so it wouldn't make too much sense to prevent that here.
In the case of both arrays having length 0, nothing should happen I think.
Updated. That does clean things up a bit. |
I think this is ready now. Let me know. |
Thanks for your patience and this amazing addition! 👍 |
Added formatParse to FlxText: t.text="show $green text$ between dollar s...
...igns"; t.formatParse([greenFormat],["$"]);
(Trying this again)