Added error checking for config.json

This commit is contained in:
2021-03-08 20:51:58 -05:00
parent fe13bac080
commit de99b127b1
10 changed files with 161 additions and 52 deletions

View File

@ -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(&current,"\n"))
if (strcmp(&current,"\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(&current,"\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()
// {
// }