diff options
Diffstat (limited to 'src/crepe/api')
-rw-r--r-- | src/crepe/api/AssetManager.cpp (renamed from src/crepe/api/resource_manager.cpp) | 0 | ||||
-rw-r--r-- | src/crepe/api/AssetManager.h (renamed from src/crepe/api/resource_manager.h) | 0 | ||||
-rw-r--r-- | src/crepe/api/CMakeLists.txt | 2 | ||||
-rw-r--r-- | src/crepe/api/Texture.cpp | 39 | ||||
-rw-r--r-- | src/crepe/api/Texture.h | 31 | ||||
-rw-r--r-- | src/crepe/api/baseResource.h | 11 | ||||
-rw-r--r-- | src/crepe/api/game.cpp | 30 | ||||
-rw-r--r-- | src/crepe/api/game.h | 17 | ||||
-rw-r--r-- | src/crepe/api/map_asset.cpp | 12 | ||||
-rw-r--r-- | src/crepe/api/map_asset.h | 14 | ||||
-rw-r--r-- | src/crepe/api/spritesheet.cpp | 38 | ||||
-rw-r--r-- | src/crepe/api/spritesheet.h | 34 |
12 files changed, 72 insertions, 156 deletions
diff --git a/src/crepe/api/resource_manager.cpp b/src/crepe/api/AssetManager.cpp index 0ecdae5..0ecdae5 100644 --- a/src/crepe/api/resource_manager.cpp +++ b/src/crepe/api/AssetManager.cpp diff --git a/src/crepe/api/resource_manager.h b/src/crepe/api/AssetManager.h index a646d95..a646d95 100644 --- a/src/crepe/api/resource_manager.h +++ b/src/crepe/api/AssetManager.h diff --git a/src/crepe/api/CMakeLists.txt b/src/crepe/api/CMakeLists.txt index cecc2f1..9a02580 100644 --- a/src/crepe/api/CMakeLists.txt +++ b/src/crepe/api/CMakeLists.txt @@ -1,9 +1,11 @@ target_sources(crepe PUBLIC # AudioSource.cpp BehaviorScript.cpp + Script.cpp ) target_sources(crepe PUBLIC FILE_SET HEADERS FILES # AudioSource.h BehaviorScript.h + Script.h ) diff --git a/src/crepe/api/Texture.cpp b/src/crepe/api/Texture.cpp new file mode 100644 index 0000000..b4e3aa8 --- /dev/null +++ b/src/crepe/api/Texture.cpp @@ -0,0 +1,39 @@ + + +#include "util/log.h" + +#include "Texture.h" +#include "SdlContext.h" +#include <SDL2/SDL_render.h> + +using namespace crepe; + +Texture::Texture(std::unique_ptr<api::Resource> res) { + dbg_trace(); + this->load(std::move(res)); +} + +Texture::Texture(const char * src) { + dbg_trace(); + this->load(std::make_unique<api::Resource>(src)); +} + +Texture::~Texture(){ + dbg_trace(); + if(this->m_texture){ + SDL_DestroyTexture(m_texture); + } +} +void Texture::load(std::unique_ptr<api::Resource> res) { + dbg_trace(); + SdlContext& ctx = SdlContext::get_instance(); + m_texture = ctx.setTextureFromPath(res->canonical(), srcrect, 1, 1); +} + +SDL_Texture* Texture::get_texture() const{ + return m_texture; +} + +SDL_Rect& Texture::get_rect() { + return srcrect; +} diff --git a/src/crepe/api/Texture.h b/src/crepe/api/Texture.h new file mode 100644 index 0000000..db2f1f9 --- /dev/null +++ b/src/crepe/api/Texture.h @@ -0,0 +1,31 @@ +#pragma once + +#include "SDL_rect.h" +#include "api/baseResource.h" +#include "api/Resource.h" +#include <SDL2/SDL_render.h> +#include <memory> + +namespace crepe { + + + +class Texture : public api::BaseResource{ + +public: + Texture(const char * src); + Texture(std::unique_ptr<api::Resource> res); + ~Texture(); + + SDL_Texture* get_texture() const; + SDL_Rect& get_rect() ; +private: + void load(std::unique_ptr<api::Resource> res); + +private: + SDL_Texture* m_texture; + SDL_Rect srcrect; +}; + +} // namespace crepe + diff --git a/src/crepe/api/baseResource.h b/src/crepe/api/baseResource.h deleted file mode 100644 index 2513f4d..0000000 --- a/src/crepe/api/baseResource.h +++ /dev/null @@ -1,11 +0,0 @@ -#pragma once - -namespace crepe::api { - -class BaseResource { -public: - virtual ~BaseResource() = default; -}; - -} - diff --git a/src/crepe/api/game.cpp b/src/crepe/api/game.cpp deleted file mode 100644 index 01920a9..0000000 --- a/src/crepe/api/game.cpp +++ /dev/null @@ -1,30 +0,0 @@ - - - -#include "game.h" -#include "core/renderSystem.h" -#include "facade/SdlContext.h" - - -Engine::Engine(int windowHeight, int window_with){ - crepe::SdlContext& ctx = crepe::SdlContext::get_instance(); -} - - - -void Engine::loop() { - - bool running = true; - crepe::SdlContext& ctx = crepe::SdlContext::get_instance(); - RenderSystem rendering; - - while (running) { - ctx.handleEvents(running); - - ctx.clearScreen(); - - rendering.render(); - - ctx.presentScreen(); - } -} diff --git a/src/crepe/api/game.h b/src/crepe/api/game.h deleted file mode 100644 index 64027fa..0000000 --- a/src/crepe/api/game.h +++ /dev/null @@ -1,17 +0,0 @@ -#pragma once - - - -class Engine{ - -public: - Engine(int windowWith, int windowHeight); - ~Engine() = default; - - void loop(); - - -private: - int window_height; - int window_width; -}; diff --git a/src/crepe/api/map_asset.cpp b/src/crepe/api/map_asset.cpp deleted file mode 100644 index bbabe2b..0000000 --- a/src/crepe/api/map_asset.cpp +++ /dev/null @@ -1,12 +0,0 @@ - - - - -#include "map_asset.h" - -Map::Map(const std::string& content){ - this->m_content = content; -} - -Map::~Map(){ -} diff --git a/src/crepe/api/map_asset.h b/src/crepe/api/map_asset.h deleted file mode 100644 index a4f3df7..0000000 --- a/src/crepe/api/map_asset.h +++ /dev/null @@ -1,14 +0,0 @@ -#pragma once - -#include "Resource.h" -#include <string> - - -using namespace crepe::api; - -class Map : public Resource { - -public: - Map(const std::string& ); - ~Map(); -}; diff --git a/src/crepe/api/spritesheet.cpp b/src/crepe/api/spritesheet.cpp deleted file mode 100644 index 7f5da38..0000000 --- a/src/crepe/api/spritesheet.cpp +++ /dev/null @@ -1,38 +0,0 @@ - - -#include "spritesheet.h" -#include "SDL_rect.h" -#include "SDL_render.h" -#include "api/Resource.h" -#include "facade/SdlContext.h" -#include <memory> - - -using namespace crepe::api; - -Spritesheet::Spritesheet(const char* src, const int row, const int col){ - this->load(std::make_unique<api::Resource>(src), row, col); -} - -Spritesheet::Spritesheet(std::unique_ptr<api::Resource> res, const int row, const int col){ - this->load(std::move(res), row, col); -} - -Spritesheet::~Spritesheet(){ - - if (this->m_spritesheet) { - SDL_DestroyTexture(this->m_spritesheet); - } -} - -void Spritesheet::select_sprite(const int x, const int y){ - m_clip.x = x * m_clip.w; - m_clip.y = y * m_clip.h; -} - -void Spritesheet::load(std::unique_ptr<api::Resource> res, const int row, const int col){ - auto& ctx = SdlContext::get_instance(); - - this->m_spritesheet = ctx.setTextureFromPath(res->canonical(), this->m_clip, row, col); -} - diff --git a/src/crepe/api/spritesheet.h b/src/crepe/api/spritesheet.h deleted file mode 100644 index 503dcef..0000000 --- a/src/crepe/api/spritesheet.h +++ /dev/null @@ -1,34 +0,0 @@ -#pragma once - - - - -#include "Resource.h" -#include "SDL_rect.h" -#include "SDL_render.h" -#include <memory> - - -namespace crepe::api { - -class Spritesheet{ - -public: - Spritesheet(const char * src, const int row , const int col); - Spritesheet(std::unique_ptr<api::Resource> res, const int row, const int col); - ~Spritesheet(); - - void select_sprite(const int x, const int y); - void draw_selected_sprite(const int x, const int y); -private: - void load(std::unique_ptr<api::Resource> res, const int row, const int col);; - SDL_Texture* get_texture() const; - -private: - - SDL_Texture* m_spritesheet; - SDL_Rect m_clip; -}; - -} - |