All asset paths corrected to use Boost::FS

This commit is contained in:
Alan Youngblood 2023-08-12 14:44:08 -04:00
parent a0c06ebe6a
commit 1cbc8cbbc0
7 changed files with 67 additions and 69 deletions

BIN
.DS_Store vendored

Binary file not shown.

3
.gitignore vendored
View File

@ -110,3 +110,6 @@ CMakeCache.txt
# macOS finder files
.DS_Store
# VS Code project stuff
.vscode*

View File

@ -66,10 +66,19 @@ public:
spriteType = sType;
if(sType == spriteAnimation)
{
std::ifstream fin(json);
/*boost::filesystem::path p{argv[0]};
p = absolute(p).parent_path();
std::string configPath = "src/config/config.json";
std::string bps = p.string();
size_t charPos = bps.find("build");
bps.erase(charPos,bps.length());
std::string configurationPath = bps + json;*/
std::cout << "Project Path: " << Game::projPath << std::endl;
std::string fullPath = Game::projPath + json;
std::ifstream fin(fullPath);
if(fin.fail()){
std::cerr<<"ERROR opening json file"<<std::endl;
std::cerr<<"ERROR opening json file: " << json << std::endl;
} else if (fin.is_open()){
std::ifstream jsonText(json);
std::ostringstream tmp;

View File

@ -49,26 +49,26 @@ public:
//const std::filesystem::path jsonPath = std::filesystem::u8path(mapPath);
const std::filesystem::path jsonPath = std::filesystem::u8path("/Users/ayoungblood/Projects/KaijuSaveEarth/assets/maps/kaiju-city-map.json");
map = t.parse(jsonPath);
std::cout << "Trying to load json tile map from: " << jsonPath << std::endl;
//std::cout << "Trying to load json tile map from: " << jsonPath << std::endl;
if(map->getStatus() == tson::ParseStatus::OK)
{
printf("Map File Loaded!! \n");
// printf("Map File Loaded!! \n");
tson::Tileset *tileset = map->getTileset(tsName);
std::cout << "tsName: " << tsName << std::endl;
//std::cout << "tsName: " << tsName << std::endl;
std::string fullPath = tileset->getImage();
std::cout << "fullPath: " << fullPath << std::endl;
//std::cout << "fullPath: " << fullPath << std::endl;
//size_t charPos = fullPath.find("assets");
//fullPath.erase(0,charPos);
std::string prependPath = std::string("assets/maps/");
std::string localPath = prependPath + fullPath;
std::string wholePath = "/Users/ayoungblood/Projects/KaijuSaveEarth/" + localPath;
std::cout << "fullPath: " << wholePath << std::endl;
//std::cout << "fullPath: " << wholePath << std::endl;
tson::Layer *tileLayer = map->getLayer(tileLayerName); //This is a Layer
std::string texName = tileLayer->getName();
Game::assets->AddTexture(texName, wholePath.c_str());
setTex(texName);
globalScale = gScale;
printf("Added texture for tilemap.\n");
//printf("Added texture for tilemap.\n");
tson::Layer *collisionLayer = map->getLayer(collisionLayerName);
tilesWide = map->getSize().x;
@ -95,7 +95,7 @@ public:
tileSet[element] = srcRect;
}
}
printf("Tile Set Setup Completed.\n");
//printf("Tile Set Setup Completed.\n");
if(tileLayer->getType() == tson::LayerType::TileLayer)
{
destRects.resize(tilesWide*tilesHigh);
@ -117,31 +117,7 @@ public:
destRect.w = destRect.h = tileWidth * gScale;
}
printf("Tilemap setup completed\n");
// tson::Layer *myLayer = map->getLayer("Tile Layer 1");
// for (int r = 0;r<map->getSize().y;r++){
// // Next cycle through each column or tile in that row:
// for (int c = 0;c<map->getSize().x;c++){
// int i = r*map->getSize().x+c;
// int elem = c+r*map->getSize().x;
// tson::Tile *myTile = myLayer->getTileData(c,r);
// int tid = myTile->getId()-1;
// //std::cout << myLayer->getTileData(1,1)->getId() << std::endl;
// // TextureManager::Draw(texture, tileSet[tid], destRects[elem], SDL_FLIP_NONE);
// //std::cout << "c,r: " << c << ", " << r << std::endl;
// if(!tid){
// //printf("got nullptr\n");
// // printf("found valid tid\n");
// } else {
// //std::cout << "tid: " << tid << std::endl;
// }
// //std::cout << " elem: " << elem << std::endl;
// //std::cout << "i" << i << std::endl;
// }
// }
// tson::Tile *testTile = myLayer->getTileData(0,4);
// int myTid = testTile->getId()-1;
printf("Completed tilemap init\n");
//printf("Tilemap setup completed\n");
//std::cout << "destRects.size " << destRects.size() << std::endl;
} else {
// printf("Failed to load Tileson map\n");

View File

@ -77,6 +77,8 @@ bool Game::gravityOnPlayer = true;
bool Game::playerIsGrounded = false;
bool Game::playerIsJumping = false;
std::string Game::projPath = "";
int gScale = 0;
int last_time;
int current_time;
@ -97,9 +99,9 @@ std::string Game::BoolToString(bool b) {
return myString;
}
Game::Game() {
Game::Game(std::string projectPath) {
// TODO Auto-generated constructor stub
Game::projPath = projectPath;
}
Game::~Game() {
@ -142,15 +144,19 @@ void Game::init(const char *title, int width, int height, bool fullscreen, int g
SDL_LogError(SDL_LOG_CATEGORY_ERROR, "Couldn't initialize SDL audio mixer!, Error: %s", SDL_GetError());
}
assets->AddTexture("player", "assets/textures/actors/kaijuturtle.png");
assets->AddTexture("font", "assets/textures/ui/ui-font-lorez5.png");
assets->AddTexture("textBox", "assets/textures/ui/ui-element-bubble.png");
assets->AddTexture("collider","assets/textures/ColTex.png");
std::string kaijuTex = Game::projPath + "assets/textures/actors/kaijuturtle.png";
std::string fontTex = Game::projPath + "assets/textures/ui/ui-font-lorez5.png";
std::string textBoxTex = Game::projPath + "assets/textures/ui/ui-element-bubble.png";
std::string musicFile = Game::projPath + "assets/audio/music/sillypuppy.ogg";
std::string sfxFile = Game::projPath + "assets/audio/sfx/bwoop.wav";
assets->AddMusicTrack("simonZ","assets/audio/music/sillypuppy.ogg");
assets->AddMusicTrack("simonZ","assets/audio/music/victory.ogg");
assets->AddTexture("player", kaijuTex.c_str());
assets->AddTexture("font", fontTex.c_str());
assets->AddTexture("textBox", textBoxTex.c_str());
assets->AddSoundClip("bwoop","assets/audio/sfx/bwoop.wav");
assets->AddMusicTrack("simonZ",musicFile.c_str());
assets->AddSoundClip("bwoop",sfxFile.c_str());
std::string myText = "U to Start";
@ -192,7 +198,7 @@ void Game::init(const char *title, int width, int height, bool fullscreen, int g
playerPosition = Vector2D().Zero();
pVel = Vector2D().Zero();
printf("Init Completed\n");
// printf("Init Completed\n");
} else {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't Initialize SDL: %s", SDL_GetError());
isRunning = false;
@ -241,7 +247,7 @@ void Game::update()
if (Mix_PlayingMusic() == 0 && gsm->currentState == GameStateManager::ST_COREGAME)
{
// std::cout << "Play Music Now" << std::endl;
// Mix_PlayMusic(assets->GetMusicTrack("simonZ"), -1);
Mix_PlayMusic(assets->GetMusicTrack("simonZ"), -1);
}
if (Mix_PlayingMusic() != 0 && gsm->currentState != GameStateManager::ST_COREGAME)
{

View File

@ -25,7 +25,7 @@ class AssetManager;
class Game {
public:
Game();
Game(std::string projectPath);
virtual ~Game();
void init(const char* title, int width, int height, bool fullscreen, int globalScale);
void handleEvents();
@ -42,7 +42,7 @@ public:
// static std::vector<ColliderComponent*> colliders;
// static tmxparser::TmxMap map;
// gameScene;
static std::string projPath;
static bool debugMenu;
static bool isRunning;
static bool debugCollisionBoxes;

View File

@ -11,7 +11,6 @@
#include <iostream>
#include <fstream>
#include <sstream>
//#include <mach-o/dyld.h>
#include <boost/filesystem.hpp>
Game *game = nullptr;
@ -27,41 +26,46 @@ int main(int argc, const char * argv[])
boost::filesystem::path p{argv[0]};
p = absolute(p).parent_path();
std::cout << "boost path: " << p << std::endl;
// std::cout << "boost path: " << p << std::endl;
// =============================
// Load cJSON config.json file
// =============================
// Starting with Error Checking
//std::string configPath = "src/config/config.json";
std::string configPath = "/Users/ayoungblood/Projects/KaijuSaveEarth/src/config/config.json";
std::string configPath = "src/config/config.json";
std::string bps = p.string();
size_t charPos = bps.find("build");
bps.erase(charPos,bps.length());
// std::cout << "Trimmed Boost Path: " << bps << std::endl;
std::string configurationPath = bps + configPath;
//std::string configPath = "/Users/ayoungblood/Projects/KaijuSaveEarth/src/config/config.json";
// /Users/ayoungblood/Projects/KaijuSaveEarth
// std::string fullPath = p.c_str() + "/" + configPath;
std::ifstream fin(configPath);
std::ifstream fin(configurationPath);
// std::cout << "Attempting to load: " << configPath << std::endl;
// std::cout << "Current working Dir: " << std::filesystem::current_path() << std::endl;
if(!fin.is_open()){
std::cerr<<"ERROR: config.json not found or opened"<<std::endl;
} else {
printf("config.json loaded successfully.\n");
}
/*std::ifstream jsonText("src/config/config.json");
std::ifstream jsonText(configurationPath);
std::ostringstream tmp;
tmp << jsonText.rdbuf();
std::string json = tmp.str();
cJSON * myJSON = cJSON_Parse(json.c_str());
cJSON * windowName = cJSON_GetObjectItemCaseSensitive(myJSON, "WindowName");
cJSON * windowSize = cJSON_GetObjectItem(myJSON, "WindowSize");*/
// int windowWidth = cJSON_GetObjectItem(windowSize, "w")->valueint;
// int windowHeight = cJSON_GetObjectItem(windowSize, "h")->valueint;
// int windowFS = cJSON_GetObjectItem(myJSON, "WindowFullScreen")->valueint;
// int globalScale = cJSON_GetObjectItem(myJSON, "GlobalScale")->valueint;
int windowWidth = 64;
cJSON * windowSize = cJSON_GetObjectItem(myJSON, "WindowSize");
int windowWidth = cJSON_GetObjectItem(windowSize, "w")->valueint;
int windowHeight = cJSON_GetObjectItem(windowSize, "h")->valueint;
int windowFS = cJSON_GetObjectItem(myJSON, "WindowFullScreen")->valueint;
int globalScale = cJSON_GetObjectItem(myJSON, "GlobalScale")->valueint;
/* int windowWidth = 64;
int windowHeight = 64;
int windowFS = 0;
int globalScale = 10;
int globalScale = 10;*/
bool isWindowFS;
std::string windowName = "KaijuSaveEarth";
//std::string windowName = "KaijuSaveEarth";
if (windowFS==0)
{
isWindowFS = false;
@ -71,11 +75,11 @@ int main(int argc, const char * argv[])
}
windowWidth = windowWidth*globalScale;
windowHeight = windowHeight*globalScale;
game = new Game();
// game->init(windowName->valuestring, windowWidth, windowHeight, isWindowFS, globalScale);
game->init(windowName.c_str(), windowWidth, windowHeight, isWindowFS, globalScale);
game = new Game(bps);
game->init(windowName->valuestring, windowWidth, windowHeight, isWindowFS, globalScale);
// game->init(windowName.c_str(), windowWidth, windowHeight, isWindowFS, globalScale);
// cJSON memory management
// cJSON_Delete(myJSON);
cJSON_Delete(myJSON);
while (game->running())
{
@ -94,7 +98,7 @@ int main(int argc, const char * argv[])
}
game->clean();
// }
}
if(fin.fail()){
std::cout<<"config.json load failed"<<std::endl;