Added error checking for config.json
This commit is contained in:
@ -12,10 +12,11 @@
|
||||
#include "string.h"
|
||||
#include <iostream>
|
||||
#include <stdio.h>
|
||||
#include <vector>
|
||||
|
||||
extern Manager manager;
|
||||
|
||||
UIText::UIText(const char* text, std::string texId, int x, int y, int letterW, int letterH, int lScale)
|
||||
UIText::UIText(std::string text, std::string texId, int x, int y, int letterW, int letterH, int lScale)
|
||||
{
|
||||
inputText = text;
|
||||
textureID = texId;
|
||||
@ -30,7 +31,7 @@ UIText::~UIText()
|
||||
{
|
||||
}
|
||||
|
||||
void UIText::ParseString(const char* inputText, int x, int y, int scale)
|
||||
void UIText::ParseString(std::string inputText, int x, int y, int scale, std::string tag)
|
||||
{
|
||||
//Parse input text into an array of char
|
||||
int posX = x;
|
||||
@ -38,30 +39,47 @@ void UIText::ParseString(const char* inputText, int x, int y, int scale)
|
||||
int i = 0;
|
||||
// printf(inputText);
|
||||
char current = inputText[i];
|
||||
// const char* newLineChar{10};
|
||||
|
||||
// std::vector<char> writableStr(inputText.begin(), inputText.end());
|
||||
// writableStr.push_back('\0');
|
||||
|
||||
do
|
||||
{
|
||||
// for (int i = 0; i < writableStr.size(); i++)
|
||||
// {
|
||||
// if (writableStr.at(i) == '\n')
|
||||
// {
|
||||
// printf("found new line");
|
||||
// }
|
||||
// }
|
||||
++i;
|
||||
if (strcmp(¤t,"\n"))
|
||||
if (strcmp(¤t,"\n")!=0)
|
||||
{
|
||||
posX += letterWidth;
|
||||
}
|
||||
else
|
||||
{
|
||||
// printf("new line detected");
|
||||
// printf("new line detected/n");
|
||||
posX = x;
|
||||
posY += letterHeight;
|
||||
}
|
||||
UIText::AddLetter(posX, posY, current);
|
||||
UIText::AddLetter(posX, posY, current, tag);
|
||||
current = inputText[i];
|
||||
} while ((strcmp(¤t,"\0"))!=0);
|
||||
}
|
||||
|
||||
|
||||
void UIText::AddLetter(int xpos, int ypos, char crnt)
|
||||
void UIText::AddLetter(int xpos, int ypos, char crnt, std::string tag)
|
||||
{
|
||||
auto& letter(manager.addEntity());
|
||||
letter.addComponent<TransformComponent>(xpos*scale, ypos*scale, letterWidth, letterHeight, 1);
|
||||
// printf("Scale: %d\n",scale);
|
||||
letter.addComponent<SpriteComponent>("font", SpriteComponent::spriteText, crnt, letterWidth, letterHeight, scale);
|
||||
letter.setTag(tag);
|
||||
letter.addGroup(Game::groupUI_Layer1);
|
||||
}
|
||||
|
||||
// void UIText::RemoveLetter()
|
||||
// {
|
||||
// }
|
||||
|
Reference in New Issue
Block a user