2020-10-25 20:51:06 +00:00
|
|
|
package;
|
|
|
|
|
2020-10-26 09:16:05 +00:00
|
|
|
import flixel.FlxG;
|
2020-10-25 20:51:06 +00:00
|
|
|
import flixel.FlxSprite;
|
|
|
|
import flixel.graphics.frames.FlxAtlasFrames;
|
|
|
|
import flixel.group.FlxSpriteGroup;
|
2020-10-26 09:16:05 +00:00
|
|
|
import flixel.math.FlxMath;
|
|
|
|
import flixel.util.FlxTimer;
|
2020-10-25 20:51:06 +00:00
|
|
|
|
|
|
|
using StringTools;
|
|
|
|
|
2020-10-25 21:38:48 +00:00
|
|
|
/**
|
|
|
|
* Loosley based on FlxTypeText lolol
|
|
|
|
*/
|
2020-10-25 20:51:06 +00:00
|
|
|
class Alphabet extends FlxSpriteGroup
|
|
|
|
{
|
2020-10-25 21:38:48 +00:00
|
|
|
public var delay:Float = 0.05;
|
|
|
|
public var paused:Bool = false;
|
|
|
|
|
2020-11-01 19:16:22 +00:00
|
|
|
// for menu shit
|
|
|
|
public var targetY:Float = 0;
|
|
|
|
public var isMenuItem:Bool = false;
|
|
|
|
|
2020-10-30 23:47:19 +00:00
|
|
|
public var text:String = "";
|
|
|
|
|
2020-10-25 21:38:48 +00:00
|
|
|
var _finalText:String = "";
|
|
|
|
var _curText:String = "";
|
|
|
|
|
2020-10-26 09:16:05 +00:00
|
|
|
public var widthOfWords:Float = FlxG.width;
|
|
|
|
|
|
|
|
var yMulti:Float = 1;
|
|
|
|
|
2020-10-25 20:51:06 +00:00
|
|
|
// custom shit
|
|
|
|
// amp, backslash, question mark, apostrophy, comma, angry faic, period
|
|
|
|
var lastSprite:AlphaCharacter;
|
2020-10-26 09:16:05 +00:00
|
|
|
var xPosResetted:Bool = false;
|
2020-10-30 23:47:19 +00:00
|
|
|
var lastWasSpace:Bool = false;
|
|
|
|
|
|
|
|
var splitWords:Array<String> = [];
|
2020-10-25 20:51:06 +00:00
|
|
|
|
2020-11-01 01:11:14 +00:00
|
|
|
var isBold:Bool = false;
|
|
|
|
|
2020-10-30 23:47:19 +00:00
|
|
|
public function new(x:Float, y:Float, text:String = "", ?bold:Bool = false, typed:Bool = false)
|
2020-10-25 20:51:06 +00:00
|
|
|
{
|
|
|
|
super(x, y);
|
|
|
|
|
2020-10-25 21:38:48 +00:00
|
|
|
_finalText = text;
|
2020-10-30 23:47:19 +00:00
|
|
|
this.text = text;
|
2020-11-01 01:11:14 +00:00
|
|
|
isBold = bold;
|
2020-10-30 23:47:19 +00:00
|
|
|
|
2020-11-01 01:11:14 +00:00
|
|
|
if (text != "")
|
2020-10-30 23:47:19 +00:00
|
|
|
{
|
2020-11-01 01:11:14 +00:00
|
|
|
if (typed)
|
|
|
|
{
|
|
|
|
startTypedText();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
addText();
|
|
|
|
}
|
2020-10-30 23:47:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function addText()
|
|
|
|
{
|
|
|
|
doSplitWords();
|
|
|
|
|
2020-11-01 01:11:14 +00:00
|
|
|
var xPos:Float = 0;
|
2020-10-30 23:47:19 +00:00
|
|
|
for (character in splitWords)
|
|
|
|
{
|
|
|
|
// if (character.fastCodeAt() == " ")
|
|
|
|
// {
|
|
|
|
// }
|
|
|
|
|
2020-12-27 08:13:51 +00:00
|
|
|
if (character == " " || character == "-")
|
2020-10-30 23:47:19 +00:00
|
|
|
{
|
|
|
|
lastWasSpace = true;
|
|
|
|
}
|
|
|
|
|
2020-11-02 20:31:28 +00:00
|
|
|
if (AlphaCharacter.alphabet.indexOf(character.toLowerCase()) != -1)
|
2020-12-27 08:13:51 +00:00
|
|
|
// if (AlphaCharacter.alphabet.contains(character.toLowerCase()))
|
2020-10-30 23:47:19 +00:00
|
|
|
{
|
|
|
|
if (lastSprite != null)
|
|
|
|
{
|
2020-11-01 01:11:14 +00:00
|
|
|
xPos = lastSprite.x + lastSprite.width;
|
2020-10-30 23:47:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (lastWasSpace)
|
|
|
|
{
|
|
|
|
xPos += 40;
|
|
|
|
lastWasSpace = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// var letter:AlphaCharacter = new AlphaCharacter(30 * loopNum, 0);
|
|
|
|
var letter:AlphaCharacter = new AlphaCharacter(xPos, 0);
|
2020-11-01 01:11:14 +00:00
|
|
|
|
|
|
|
if (isBold)
|
|
|
|
letter.createBold(character);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
letter.createLetter(character);
|
|
|
|
}
|
|
|
|
|
2020-10-30 23:47:19 +00:00
|
|
|
add(letter);
|
|
|
|
|
|
|
|
lastSprite = letter;
|
|
|
|
}
|
|
|
|
|
|
|
|
// loopNum += 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function doSplitWords():Void
|
|
|
|
{
|
|
|
|
splitWords = _finalText.split("");
|
|
|
|
}
|
|
|
|
|
2020-11-01 01:11:14 +00:00
|
|
|
public var personTalking:String = 'gf';
|
|
|
|
|
2020-10-30 23:47:19 +00:00
|
|
|
public function startTypedText():Void
|
|
|
|
{
|
|
|
|
_finalText = text;
|
|
|
|
doSplitWords();
|
2020-10-25 21:38:48 +00:00
|
|
|
|
2020-10-30 23:47:19 +00:00
|
|
|
// trace(arrayShit);
|
2020-10-25 20:51:06 +00:00
|
|
|
|
|
|
|
var loopNum:Int = 0;
|
|
|
|
|
2020-11-01 01:11:14 +00:00
|
|
|
var xPos:Float = 0;
|
|
|
|
var curRow:Int = 0;
|
|
|
|
|
2020-10-26 09:16:05 +00:00
|
|
|
new FlxTimer().start(0.05, function(tmr:FlxTimer)
|
2020-10-25 20:51:06 +00:00
|
|
|
{
|
2020-10-26 09:16:05 +00:00
|
|
|
// trace(_finalText.fastCodeAt(loopNum) + " " + _finalText.charAt(loopNum));
|
|
|
|
if (_finalText.fastCodeAt(loopNum) == "\n".code)
|
2020-10-25 20:51:06 +00:00
|
|
|
{
|
2020-10-26 09:16:05 +00:00
|
|
|
yMulti += 1;
|
|
|
|
xPosResetted = true;
|
2020-11-01 01:11:14 +00:00
|
|
|
xPos = 0;
|
|
|
|
curRow += 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (splitWords[loopNum] == " ")
|
|
|
|
{
|
|
|
|
lastWasSpace = true;
|
2020-10-25 20:51:06 +00:00
|
|
|
}
|
|
|
|
|
2020-11-02 20:31:28 +00:00
|
|
|
#if (haxe >= "4.0.0")
|
2020-11-01 01:11:14 +00:00
|
|
|
var isNumber:Bool = AlphaCharacter.numbers.contains(splitWords[loopNum]);
|
|
|
|
var isSymbol:Bool = AlphaCharacter.symbols.contains(splitWords[loopNum]);
|
2020-11-02 20:31:28 +00:00
|
|
|
#else
|
|
|
|
var isNumber:Bool = AlphaCharacter.numbers.indexOf(splitWords[loopNum]) != -1;
|
|
|
|
var isSymbol:Bool = AlphaCharacter.symbols.indexOf(splitWords[loopNum]) != -1;
|
|
|
|
#end
|
|
|
|
|
|
|
|
if (AlphaCharacter.alphabet.indexOf(splitWords[loopNum].toLowerCase()) != -1 || isNumber || isSymbol)
|
2020-12-27 08:13:51 +00:00
|
|
|
// if (AlphaCharacter.alphabet.contains(splitWords[loopNum].toLowerCase()) || isNumber || isSymbol)
|
2020-11-02 23:37:55 +00:00
|
|
|
|
2020-10-25 20:51:06 +00:00
|
|
|
{
|
2020-10-26 09:16:05 +00:00
|
|
|
if (lastSprite != null && !xPosResetted)
|
2020-10-25 20:51:06 +00:00
|
|
|
{
|
2020-11-01 01:11:14 +00:00
|
|
|
lastSprite.updateHitbox();
|
|
|
|
xPos += lastSprite.width + 3;
|
|
|
|
// if (isBold)
|
|
|
|
// xPos -= 80;
|
2020-10-25 20:51:06 +00:00
|
|
|
}
|
2020-10-26 09:16:05 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
xPosResetted = false;
|
|
|
|
}
|
|
|
|
|
2020-11-01 01:11:14 +00:00
|
|
|
if (lastWasSpace)
|
|
|
|
{
|
|
|
|
xPos += 20;
|
|
|
|
lastWasSpace = false;
|
|
|
|
}
|
2020-10-26 09:16:05 +00:00
|
|
|
// trace(_finalText.fastCodeAt(loopNum) + " " + _finalText.charAt(loopNum));
|
2020-10-25 20:51:06 +00:00
|
|
|
|
|
|
|
// var letter:AlphaCharacter = new AlphaCharacter(30 * loopNum, 0);
|
2020-10-26 09:16:05 +00:00
|
|
|
var letter:AlphaCharacter = new AlphaCharacter(xPos, 55 * yMulti);
|
2020-11-01 01:11:14 +00:00
|
|
|
letter.row = curRow;
|
|
|
|
if (isBold)
|
|
|
|
{
|
|
|
|
letter.createBold(splitWords[loopNum]);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (isNumber)
|
|
|
|
{
|
|
|
|
letter.createNumber(splitWords[loopNum]);
|
|
|
|
}
|
|
|
|
else if (isSymbol)
|
|
|
|
{
|
|
|
|
letter.createSymbol(splitWords[loopNum]);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
letter.createLetter(splitWords[loopNum]);
|
|
|
|
}
|
|
|
|
|
|
|
|
letter.x += 90;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (FlxG.random.bool(40))
|
|
|
|
{
|
|
|
|
var daSound:String = "GF_";
|
2021-02-08 21:34:48 +00:00
|
|
|
FlxG.sound.play(Paths.soundRandom(daSound, 1, 4));
|
2020-11-01 01:11:14 +00:00
|
|
|
}
|
|
|
|
|
2020-10-25 20:51:06 +00:00
|
|
|
add(letter);
|
|
|
|
|
|
|
|
lastSprite = letter;
|
|
|
|
}
|
|
|
|
|
|
|
|
loopNum += 1;
|
2020-10-26 09:16:05 +00:00
|
|
|
|
2020-11-01 01:11:14 +00:00
|
|
|
tmr.time = FlxG.random.float(0.04, 0.09);
|
2020-10-30 23:47:19 +00:00
|
|
|
}, splitWords.length);
|
2020-10-25 20:51:06 +00:00
|
|
|
}
|
2020-10-25 21:38:48 +00:00
|
|
|
|
|
|
|
override function update(elapsed:Float)
|
|
|
|
{
|
2020-11-01 19:16:22 +00:00
|
|
|
if (isMenuItem)
|
|
|
|
{
|
|
|
|
var scaledY = FlxMath.remapToRange(targetY, 0, 1, 0, 1.3);
|
|
|
|
|
|
|
|
y = FlxMath.lerp(y, (scaledY * 120) + (FlxG.height * 0.48), 0.16);
|
|
|
|
x = FlxMath.lerp(x, (targetY * 20) + 90, 0.16);
|
|
|
|
}
|
|
|
|
|
2020-10-25 21:38:48 +00:00
|
|
|
super.update(elapsed);
|
|
|
|
}
|
2020-10-25 20:51:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
class AlphaCharacter extends FlxSprite
|
|
|
|
{
|
|
|
|
public static var alphabet:String = "abcdefghijklmnopqrstuvwxyz";
|
|
|
|
|
2020-11-01 01:11:14 +00:00
|
|
|
public static var numbers:String = "1234567890";
|
|
|
|
|
|
|
|
public static var symbols:String = "|~#$%()*+-:;<=>@[]^_.,'!?";
|
|
|
|
|
|
|
|
public var row:Int = 0;
|
2020-10-25 20:51:06 +00:00
|
|
|
|
|
|
|
public function new(x:Float, y:Float)
|
|
|
|
{
|
|
|
|
super(x, y);
|
2021-02-08 21:34:48 +00:00
|
|
|
var tex = Paths.getSparrowAtlas('alphabet');
|
2020-10-25 20:51:06 +00:00
|
|
|
frames = tex;
|
|
|
|
|
|
|
|
antialiasing = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function createBold(letter:String)
|
|
|
|
{
|
|
|
|
animation.addByPrefix(letter, letter.toUpperCase() + " bold", 24);
|
|
|
|
animation.play(letter);
|
|
|
|
updateHitbox();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function createLetter(letter:String):Void
|
|
|
|
{
|
|
|
|
var letterCase:String = "lowercase";
|
|
|
|
if (letter.toLowerCase() != letter)
|
|
|
|
{
|
|
|
|
letterCase = 'capital';
|
|
|
|
}
|
|
|
|
|
|
|
|
animation.addByPrefix(letter, letter + " " + letterCase, 24);
|
|
|
|
animation.play(letter);
|
2020-11-01 01:11:14 +00:00
|
|
|
updateHitbox();
|
|
|
|
|
|
|
|
FlxG.log.add('the row' + row);
|
|
|
|
|
|
|
|
y = (110 - height);
|
|
|
|
y += row * 60;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function createNumber(letter:String):Void
|
|
|
|
{
|
|
|
|
animation.addByPrefix(letter, letter, 24);
|
|
|
|
animation.play(letter);
|
|
|
|
|
|
|
|
updateHitbox();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function createSymbol(letter:String)
|
|
|
|
{
|
|
|
|
switch (letter)
|
|
|
|
{
|
|
|
|
case '.':
|
|
|
|
animation.addByPrefix(letter, 'period', 24);
|
|
|
|
animation.play(letter);
|
|
|
|
y += 50;
|
|
|
|
case "'":
|
|
|
|
animation.addByPrefix(letter, 'apostraphie', 24);
|
|
|
|
animation.play(letter);
|
|
|
|
y -= 0;
|
|
|
|
case "?":
|
|
|
|
animation.addByPrefix(letter, 'question mark', 24);
|
|
|
|
animation.play(letter);
|
|
|
|
case "!":
|
|
|
|
animation.addByPrefix(letter, 'exclamation point', 24);
|
|
|
|
animation.play(letter);
|
|
|
|
}
|
|
|
|
|
|
|
|
updateHitbox();
|
2020-10-25 20:51:06 +00:00
|
|
|
}
|
|
|
|
}
|