mirror of
https://github.com/TombEngine/TombEngine.git
synced 2025-04-28 15:57:59 +03:00
Remove accidentally-committed multi-font WIP stuff. Update Timer DisplayString code. Add callstack printing stuff for CreateString.
This commit is contained in:
parent
88a6d7f229
commit
05740927b4
4 changed files with 14 additions and 27 deletions
|
@ -34,7 +34,7 @@ local Timer
|
||||||
|
|
||||||
local unpausedColor = TEN.Color(255, 255, 255)
|
local unpausedColor = TEN.Color(255, 255, 255)
|
||||||
local pausedColor = TEN.Color(255, 255, 0)
|
local pausedColor = TEN.Color(255, 255, 0)
|
||||||
local str = TEN.Strings.DisplayString("TIMER", 0, 0, unpausedColor, false, {TEN.Strings.DisplayStringOption.CENTER, TEN.Strings.DisplayStringOption.SHADOW} )
|
local str = TEN.Strings.DisplayString("TIMER", 0, 0, 1, unpausedColor, false, {TEN.Strings.DisplayStringOption.CENTER, TEN.Strings.DisplayStringOption.SHADOW} )
|
||||||
|
|
||||||
|
|
||||||
Timer = {
|
Timer = {
|
||||||
|
|
|
@ -208,7 +208,6 @@ namespace TEN::Renderer
|
||||||
Texture2D* Texture;
|
Texture2D* Texture;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct FontData { int size; std::wstring path; std::unique_ptr<SpriteFont> font; };
|
|
||||||
struct RendererSpriteSequence
|
struct RendererSpriteSequence
|
||||||
{
|
{
|
||||||
int Id;
|
int Id;
|
||||||
|
@ -380,7 +379,6 @@ struct FontData { int size; std::wstring path; std::unique_ptr<SpriteFont> font;
|
||||||
|
|
||||||
// Text
|
// Text
|
||||||
std::unique_ptr<SpriteFont> m_gameFont;
|
std::unique_ptr<SpriteFont> m_gameFont;
|
||||||
std::vector<FontData> m_gameFonts;
|
|
||||||
std::vector<RendererStringToDraw> m_strings;
|
std::vector<RendererStringToDraw> m_strings;
|
||||||
float BlinkColorValue = 0.0f;
|
float BlinkColorValue = 0.0f;
|
||||||
float BlinkTime = 0.0f;
|
float BlinkTime = 0.0f;
|
||||||
|
|
|
@ -3,7 +3,6 @@
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
#include <regex>
|
|
||||||
|
|
||||||
#include "Renderer/Renderer11.h"
|
#include "Renderer/Renderer11.h"
|
||||||
#include "Renderer/Quad/RenderQuad.h"
|
#include "Renderer/Quad/RenderQuad.h"
|
||||||
|
@ -395,24 +394,6 @@ void Renderer11::InitializeCommonTextures()
|
||||||
{
|
{
|
||||||
// Initialize font.
|
// Initialize font.
|
||||||
auto fontPath = GetAssetPath(L"Textures/Font.spritefont");
|
auto fontPath = GetAssetPath(L"Textures/Font.spritefont");
|
||||||
auto fontDir = GetAssetPath(L"Textures");
|
|
||||||
//get all paths in directory matching a pattern
|
|
||||||
|
|
||||||
std::regex pattern("Font(\\d{1,3})\\.spritefont");
|
|
||||||
for (const auto& file : std::filesystem::directory_iterator(fontDir))
|
|
||||||
{
|
|
||||||
std::smatch result;
|
|
||||||
std::string fileName = file.path().filename().string();
|
|
||||||
auto bResult = std::regex_search(fileName, result, pattern);
|
|
||||||
//ensure the paths have a number in the name
|
|
||||||
// result[0] is the whole match including the leading backslash
|
|
||||||
// result[1] is the digits/font size
|
|
||||||
|
|
||||||
if (!result.empty())
|
|
||||||
{
|
|
||||||
m_gameFonts.push_back({ std::stoi(result[1].str()), file.path().wstring(), std::make_unique<SpriteFont>(m_device.Get(), file.path().wstring().c_str()) });
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!std::filesystem::is_regular_file(fontPath))
|
if (!std::filesystem::is_regular_file(fontPath))
|
||||||
throw std::runtime_error("Font not found; path " + TEN::Utils::ToString(fontPath) + " is missing.");
|
throw std::runtime_error("Font not found; path " + TEN::Utils::ToString(fontPath) + " is missing.");
|
||||||
|
|
|
@ -56,11 +56,19 @@ If true, the string argument will be the key of a translated string specified in
|
||||||
__Default: empty__
|
__Default: empty__
|
||||||
@treturn DisplayString A new DisplayString object.
|
@treturn DisplayString A new DisplayString object.
|
||||||
*/
|
*/
|
||||||
static std::unique_ptr<DisplayString> CreateString(const std::string& key, int x, int y, TypeOrNil<float> scale, TypeOrNil<ScriptColor> color, TypeOrNil<bool> maybeTranslated, TypeOrNil<sol::table> flags)
|
static std::unique_ptr<DisplayString> CreateString(const std::string& key, int x, int y, TypeOrNil<float> scale, TypeOrNil<ScriptColor> color, TypeOrNil<bool> maybeTranslated, TypeOrNil<sol::table> flags, sol::this_state state)
|
||||||
{
|
{
|
||||||
auto ptr = std::make_unique<DisplayString>();
|
auto ptr = std::make_unique<DisplayString>();
|
||||||
auto id = ptr->GetID();
|
auto id = ptr->GetID();
|
||||||
|
|
||||||
|
auto getCallStack = [state]
|
||||||
|
{
|
||||||
|
luaL_traceback(state, state, NULL, 0);
|
||||||
|
std::string traceback{ lua_tostring(state, -1) };
|
||||||
|
lua_pop(state, 1);
|
||||||
|
return traceback;
|
||||||
|
};
|
||||||
|
|
||||||
FlagArray f{};
|
FlagArray f{};
|
||||||
if (std::holds_alternative<sol::table>(flags))
|
if (std::holds_alternative<sol::table>(flags))
|
||||||
{
|
{
|
||||||
|
@ -73,22 +81,22 @@ static std::unique_ptr<DisplayString> CreateString(const std::string& key, int x
|
||||||
}
|
}
|
||||||
else if (!std::holds_alternative<sol::nil_t>(flags))
|
else if (!std::holds_alternative<sol::nil_t>(flags))
|
||||||
{
|
{
|
||||||
ScriptAssertF(false, "Wrong argument type for {}.new \"flags\" argument; must be a table or nil.", ScriptReserved_DisplayString);
|
ScriptAssertF(false, "Wrong argument type for {}.new \"flags\" argument; must be a table or nil.\n{}", ScriptReserved_DisplayString, getCallStack());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!IsValidOptionalArg(maybeTranslated))
|
if (!IsValidOptionalArg(maybeTranslated))
|
||||||
{
|
{
|
||||||
ScriptAssertF(false, "Wrong argument type for {}.new \"translated\" argument; must be a bool or nil.", ScriptReserved_DisplayString);
|
ScriptAssertF(false, "Wrong argument type for {}.new \"translated\" argument; must be a bool or nil.\n{}", ScriptReserved_DisplayString, getCallStack());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!IsValidOptionalArg(color))
|
if (!IsValidOptionalArg(color))
|
||||||
{
|
{
|
||||||
ScriptAssertF(false, "Wrong argument type for {}.new \"color\" argument; must be a {} or nil.", ScriptReserved_DisplayString, ScriptReserved_Color);
|
ScriptAssertF(false, "Wrong argument type for {}.new \"color\" argument; must be a {} or nil.\n{}", ScriptReserved_DisplayString, ScriptReserved_Color, getCallStack());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!IsValidOptionalArg(scale))
|
if (!IsValidOptionalArg(scale))
|
||||||
{
|
{
|
||||||
ScriptAssertF(false, "Wrong argument type for {}.new \"scale\" argument; must be a float or nil.", ScriptReserved_DisplayString);
|
ScriptAssertF(false, "Wrong argument type for {}.new \"scale\" argument; must be a float or nil.\n{}", ScriptReserved_DisplayString, getCallStack());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue