diff options
Diffstat (limited to 'src/example')
| -rw-r--r-- | src/example/FontExample.cpp | 6 | ||||
| -rw-r--r-- | src/example/loadfont.cpp | 31 | 
2 files changed, 22 insertions, 15 deletions
diff --git a/src/example/FontExample.cpp b/src/example/FontExample.cpp index 3f5af48..7b2dadb 100644 --- a/src/example/FontExample.cpp +++ b/src/example/FontExample.cpp @@ -11,6 +11,7 @@  #include <crepe/manager/EventManager.h>  #include <crepe/manager/Mediator.h>  #include <crepe/manager/ResourceManager.h> +#include <crepe/api/Config.h>  #include <exception>  #include <iostream>  #include <memory> @@ -36,14 +37,15 @@ class TestScene : public Scene {  public:  	void load_scene() override {  		GameObject text_object = this->new_object("test", "test", vec2{0, 0}, 0, 1); -		text_object.add_component<Text>(vec2(100, 100), vec2(0, 0), "test test", "Noto Sans", -										Text::Data{}); +		text_object.add_component<Text>(vec2(100, 100), vec2(0, 0), "OpenSymbol", Text::Data{});  		text_object.add_component<BehaviorScript>().set_script<TestScript>();  		text_object.add_component<Camera>(ivec2{300, 300}, vec2{100, 100}, Camera::Data{});  	}  	std::string get_name() const override { return "hey"; }  };  int main() { +	// Config& config = Config::get_instance(); +	// config.log.level = Log::Level::TRACE;  	LoopManager engine;  	engine.add_scene<TestScene>();  	engine.start(); diff --git a/src/example/loadfont.cpp b/src/example/loadfont.cpp index ce287b4..36d00dd 100644 --- a/src/example/loadfont.cpp +++ b/src/example/loadfont.cpp @@ -2,10 +2,12 @@  #include <crepe/api/Text.h>  #include <crepe/facade/Font.h>  #include <crepe/facade/SDLContext.h> +#include <crepe/api/Asset.h>  #include <crepe/manager/Mediator.h>  #include <crepe/manager/ResourceManager.h>  #include <exception>  #include <iostream> +#include <optional>  #include <memory>  using namespace crepe;  int main() { @@ -18,21 +20,24 @@ int main() {  	try {  		// Correct way to create a unique pointer for Text  		std::unique_ptr<Text> label = std::make_unique<Text>( -			1, vec2(100, 100), vec2(0, 0), "test test", "OpenSymbol", Text::Data{}); -		std::cout << "Path: " << label->font.get_path() << std::endl; +			1, vec2(100, 100), vec2(0, 0), "OpenSymbol", Text::Data{},"test text", Asset("")); +		// std::cout << "Path: " << label->font.get_path() << std::endl;  		std::unique_ptr<Text> label2 -			= std::make_unique<Text>(1, vec2(100, 100), vec2(0, 0), "test test", -									 "fsaafdafsdafsdafsdasfdds", Text::Data{}); -		std::cout << "Path: " << label2->font.get_path() << std::endl; -		ResourceManager & resource_mgr = mediator.resource_manager; -		const Font & res = resource_manager.get<Font>(label->font); -		TTF_Font * test_font = res.get_font(); -		if (test_font == NULL) { -			std::cout << "error with font" << std::endl; -		} else { -			std::cout << "correct font retrieved" << std::endl; -		} +			= std::make_unique<Text>(1, vec2(100, 100), vec2(0, 0),"fsaafdafsdafsdafsdasfdds", Text::Data{}); +		Asset asset = Asset("test test"); +		label->font = asset; +		std::cout << label->font.value().get_path() << std::endl; +		// label2->font = std::make_optional(asset); +		// std::cout << "Path: " << label2->font.get_path() << std::endl; +		// ResourceManager & resource_mgr = mediator.resource_manager; +		// const Font & res = resource_manager.get<Font>(label->font); +		// TTF_Font * test_font = res.get_font(); +		// if (test_font == NULL) { +		// 	std::cout << "error with font" << std::endl; +		// } else { +		// 	std::cout << "correct font retrieved" << std::endl; +		// }  	} catch (const std::exception & e) {  		std::cout << "Standard exception thrown: " << e.what() << std::endl;  	}  |