Skip to content

Commit

Permalink
Misc codestyle/comment cleaning.
Browse files Browse the repository at this point in the history
  • Loading branch information
Eiyeron committed Apr 17, 2018
1 parent 491576e commit 35c7001
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 37 deletions.
23 changes: 12 additions & 11 deletions textbox/TextPool.hx
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,6 @@ import flixel.util.FlxDestroyUtil;

class TextPool implements IFlxPool<Text>
{
public var length(get, never):Int;

private var _pool:Array<Text> = [];

/**
* Objects aren't actually removed from the array in order to improve performance.
* _count keeps track of the valid, accessible pool objects.
*/
private var _count:Int = 0;

public function new()
{
Expand All @@ -38,7 +29,7 @@ class TextPool implements IFlxPool<Text>
// if the object's spot in the pool was overwritten, or if it's at or past _count (in the inaccessible zone)
if (i == -1 || i >= _count)
{
// Make the character invisible and not updated instead of destroying the shit out of it.
// Make the character invisible and not updated instead of destroying it.
obj.kill();
_pool[_count++] = obj;
}
Expand All @@ -49,7 +40,7 @@ class TextPool implements IFlxPool<Text>
{
if (obj != null)
{
// Make the character invisible and not updated instead of destroying the shit out of it.
// Make the character invisible and not updated instead of destroying it.
obj.kill();
_pool[_count++] = obj;
}
Expand All @@ -75,6 +66,16 @@ class TextPool implements IFlxPool<Text>
{
return _count;
}

public var length(get, never):Int;

private var _pool:Array<Text> = [];

/**
* Objects aren't actually removed from the array in order to improve performance.
* _count keeps track of the valid, accessible pool objects.
*/
private var _count:Int = 0;
}

interface IFlxPooled extends IFlxDestroyable
Expand Down
3 changes: 2 additions & 1 deletion textbox/Textbox.hx
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ class Textbox extends FlxSpriteGroup {
}
else if(status != PAUSED && status != DONE)
{
// Nothing to do here
timerBeforeNewCharacter += elapsed;
while(timerBeforeNewCharacter > timePerCharacter)
{
Expand Down Expand Up @@ -526,7 +525,9 @@ class Textbox extends FlxSpriteGroup {
public override function set_alpha(Alpha:Float):Float
{
for(line in lines)
{
line.characters.forEach(function(s){s.set_alpha(Alpha);});
}
return super.set_alpha(Alpha);
}

Expand Down
51 changes: 26 additions & 25 deletions textbox/TextboxLine.hx
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,24 @@ package textbox;
import flixel.group.FlxGroup;
import flixel.text.FlxText;

class TextBoxLine {
public var characters:FlxTypedGroup<Text>;
public var text_width(default, null):Float;
var inner_text:FlxText;

class TextBoxLine
{
public function new()
{
characters = new FlxTypedGroup<Text>();
text_width = 0;
inner_text = new FlxText();
inner_text.text = "";
textWidth = 0;
innerText = new FlxText();
innerText.text = "";
}

// Creates a tempoary FlxText to calculate the future length of the current string with a suffix.
public function projectWidth(string_to_append:String):Float
{
var test_string:FlxText = new FlxText();
test_string.font = inner_text.font;
test_string.size = inner_text.size;
test_string.text = inner_text.text + string_to_append;
return test_string.textField.width;
var testString:FlxText = new FlxText();
testString.font = innerText.font;
testString.size = innerText.size;
testString.text = innerText.text + string_to_append;
return testString.textField.width;
}

// Accepts a new character and updates its logic values like width.
Expand All @@ -32,43 +29,47 @@ class TextBoxLine {
// Regerenate the FlxText.
if(characters.length == 0)
{
inner_text.text = "";
inner_text.font = character.font;
inner_text.size = character.size;
innerText.text = "";
innerText.font = character.font;
innerText.size = character.size;
}
characters.add(character);
inner_text.text += character.text;
innerText.text += character.text;
#if js
// Legnth calculation wouldn't work properly if I haven't done this.
if(character.text == " ")
// TODO : pass this magic cookie as a setting
text_width += character.width+2;
textWidth += character.width+2;
else
text_width = inner_text.textField.textWidth;
textWidth = innerText.textField.textWidth;
#else
text_width = inner_text.textField.textWidth;
textWidth = innerText.textField.textWidth;
#end
}

// Releases its characters to pass along or put them back into pool.
public function dispose():FlxTypedGroup<Text>
{
text_width = 0;
textWidth = 0;
var c = characters;
characters = new FlxTypedGroup<Text>();
inner_text.text = "";
innerText.text = "";
return c;
}

// Takes ownership of the characters and recalculates its metrics.
public function take(characters:FlxTypedGroup<Text>):Void
{
this.characters = characters;
inner_text.text = "";
innerText.text = "";
for(character in characters)
{
inner_text.text += character.text;
innerText.text += character.text;
}
text_width = inner_text.width;
textWidth = innerText.width;
}

public var characters:FlxTypedGroup<Text>;
public var textWidth(default, null):Float;
private var innerText:FlxText;
}

0 comments on commit 35c7001

Please sign in to comment.