Skip to content
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

Merged
merged 8 commits into from
Jul 18, 2014
Merged

Added formatParse to FlxText: t.text="show $green text$ between dollar s... #1229

merged 8 commits into from
Jul 18, 2014

Conversation

larsiusprime
Copy link
Member

...igns"; t.formatParse([greenFormat],["$"]);

(Trying this again)

…r signs"; t.formatParse([greenFormat],["$"]);
addFormat(formatsToApply[i], range_starts[i], range_ends[i]);
}

//Clean up arrays created for this function
Copy link
Member

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
Copy link
Member

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?

Copy link
Member

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.

Copy link
Member Author

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

Copy link
Member Author

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?

Copy link
Member

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.

@larsiusprime
Copy link
Member Author

Updated. That does clean things up a bit.

@larsiusprime
Copy link
Member Author

I think this is ready now. Let me know.

@Gama11
Copy link
Member

Gama11 commented Jul 18, 2014

Thanks for your patience and this amazing addition! 👍

Gama11 added a commit that referenced this pull request Jul 18, 2014
Added formatParse to FlxText: t.text="show $green text$ between dollar s...
@Gama11 Gama11 merged commit ca4c4dc into HaxeFlixel:dev Jul 18, 2014
Gama11 added a commit to HaxeFlixel/flixel-demos that referenced this pull request Jul 18, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants