Some paths to assets fixed with Boost::FS
This commit is contained in:
parent
a0c06ebe6a
commit
f449eda43f
@ -66,10 +66,19 @@ public:
|
|||||||
spriteType = sType;
|
spriteType = sType;
|
||||||
if(sType == spriteAnimation)
|
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()){
|
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()){
|
} else if (fin.is_open()){
|
||||||
std::ifstream jsonText(json);
|
std::ifstream jsonText(json);
|
||||||
std::ostringstream tmp;
|
std::ostringstream tmp;
|
||||||
|
@ -49,26 +49,26 @@ public:
|
|||||||
//const std::filesystem::path jsonPath = std::filesystem::u8path(mapPath);
|
//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");
|
const std::filesystem::path jsonPath = std::filesystem::u8path("/Users/ayoungblood/Projects/KaijuSaveEarth/assets/maps/kaiju-city-map.json");
|
||||||
map = t.parse(jsonPath);
|
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)
|
if(map->getStatus() == tson::ParseStatus::OK)
|
||||||
{
|
{
|
||||||
printf("Map File Loaded!! \n");
|
// printf("Map File Loaded!! \n");
|
||||||
tson::Tileset *tileset = map->getTileset(tsName);
|
tson::Tileset *tileset = map->getTileset(tsName);
|
||||||
std::cout << "tsName: " << tsName << std::endl;
|
//std::cout << "tsName: " << tsName << std::endl;
|
||||||
std::string fullPath = tileset->getImage();
|
std::string fullPath = tileset->getImage();
|
||||||
std::cout << "fullPath: " << fullPath << std::endl;
|
//std::cout << "fullPath: " << fullPath << std::endl;
|
||||||
//size_t charPos = fullPath.find("assets");
|
//size_t charPos = fullPath.find("assets");
|
||||||
//fullPath.erase(0,charPos);
|
//fullPath.erase(0,charPos);
|
||||||
std::string prependPath = std::string("assets/maps/");
|
std::string prependPath = std::string("assets/maps/");
|
||||||
std::string localPath = prependPath + fullPath;
|
std::string localPath = prependPath + fullPath;
|
||||||
std::string wholePath = "/Users/ayoungblood/Projects/KaijuSaveEarth/" + localPath;
|
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
|
tson::Layer *tileLayer = map->getLayer(tileLayerName); //This is a Layer
|
||||||
std::string texName = tileLayer->getName();
|
std::string texName = tileLayer->getName();
|
||||||
Game::assets->AddTexture(texName, wholePath.c_str());
|
Game::assets->AddTexture(texName, wholePath.c_str());
|
||||||
setTex(texName);
|
setTex(texName);
|
||||||
globalScale = gScale;
|
globalScale = gScale;
|
||||||
printf("Added texture for tilemap.\n");
|
//printf("Added texture for tilemap.\n");
|
||||||
tson::Layer *collisionLayer = map->getLayer(collisionLayerName);
|
tson::Layer *collisionLayer = map->getLayer(collisionLayerName);
|
||||||
|
|
||||||
tilesWide = map->getSize().x;
|
tilesWide = map->getSize().x;
|
||||||
@ -95,7 +95,7 @@ public:
|
|||||||
tileSet[element] = srcRect;
|
tileSet[element] = srcRect;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
printf("Tile Set Setup Completed.\n");
|
//printf("Tile Set Setup Completed.\n");
|
||||||
if(tileLayer->getType() == tson::LayerType::TileLayer)
|
if(tileLayer->getType() == tson::LayerType::TileLayer)
|
||||||
{
|
{
|
||||||
destRects.resize(tilesWide*tilesHigh);
|
destRects.resize(tilesWide*tilesHigh);
|
||||||
@ -117,31 +117,7 @@ public:
|
|||||||
destRect.w = destRect.h = tileWidth * gScale;
|
destRect.w = destRect.h = tileWidth * gScale;
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("Tilemap setup completed\n");
|
//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");
|
|
||||||
//std::cout << "destRects.size " << destRects.size() << std::endl;
|
//std::cout << "destRects.size " << destRects.size() << std::endl;
|
||||||
} else {
|
} else {
|
||||||
// printf("Failed to load Tileson map\n");
|
// printf("Failed to load Tileson map\n");
|
||||||
|
@ -77,6 +77,8 @@ bool Game::gravityOnPlayer = true;
|
|||||||
bool Game::playerIsGrounded = false;
|
bool Game::playerIsGrounded = false;
|
||||||
bool Game::playerIsJumping = false;
|
bool Game::playerIsJumping = false;
|
||||||
|
|
||||||
|
std::string Game::projPath = "";
|
||||||
|
|
||||||
int gScale = 0;
|
int gScale = 0;
|
||||||
int last_time;
|
int last_time;
|
||||||
int current_time;
|
int current_time;
|
||||||
@ -97,9 +99,9 @@ std::string Game::BoolToString(bool b) {
|
|||||||
return myString;
|
return myString;
|
||||||
}
|
}
|
||||||
|
|
||||||
Game::Game() {
|
Game::Game(std::string projectPath) {
|
||||||
// TODO Auto-generated constructor stub
|
// TODO Auto-generated constructor stub
|
||||||
|
Game::projPath = projectPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
Game::~Game() {
|
Game::~Game() {
|
||||||
@ -142,7 +144,9 @@ 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());
|
SDL_LogError(SDL_LOG_CATEGORY_ERROR, "Couldn't initialize SDL audio mixer!, Error: %s", SDL_GetError());
|
||||||
}
|
}
|
||||||
|
|
||||||
assets->AddTexture("player", "assets/textures/actors/kaijuturtle.png");
|
std::string kaijuTex = Game::projPath + "assets/textures/actors/kaijuturtle.png";
|
||||||
|
|
||||||
|
assets->AddTexture("player", kaijuTex.c_str());
|
||||||
assets->AddTexture("font", "assets/textures/ui/ui-font-lorez5.png");
|
assets->AddTexture("font", "assets/textures/ui/ui-font-lorez5.png");
|
||||||
assets->AddTexture("textBox", "assets/textures/ui/ui-element-bubble.png");
|
assets->AddTexture("textBox", "assets/textures/ui/ui-element-bubble.png");
|
||||||
assets->AddTexture("collider","assets/textures/ColTex.png");
|
assets->AddTexture("collider","assets/textures/ColTex.png");
|
||||||
@ -192,7 +196,7 @@ void Game::init(const char *title, int width, int height, bool fullscreen, int g
|
|||||||
playerPosition = Vector2D().Zero();
|
playerPosition = Vector2D().Zero();
|
||||||
pVel = Vector2D().Zero();
|
pVel = Vector2D().Zero();
|
||||||
|
|
||||||
printf("Init Completed\n");
|
// printf("Init Completed\n");
|
||||||
} else {
|
} else {
|
||||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't Initialize SDL: %s", SDL_GetError());
|
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't Initialize SDL: %s", SDL_GetError());
|
||||||
isRunning = false;
|
isRunning = false;
|
||||||
|
@ -25,7 +25,7 @@ class AssetManager;
|
|||||||
|
|
||||||
class Game {
|
class Game {
|
||||||
public:
|
public:
|
||||||
Game();
|
Game(std::string projectPath);
|
||||||
virtual ~Game();
|
virtual ~Game();
|
||||||
void init(const char* title, int width, int height, bool fullscreen, int globalScale);
|
void init(const char* title, int width, int height, bool fullscreen, int globalScale);
|
||||||
void handleEvents();
|
void handleEvents();
|
||||||
@ -42,7 +42,7 @@ public:
|
|||||||
// static std::vector<ColliderComponent*> colliders;
|
// static std::vector<ColliderComponent*> colliders;
|
||||||
// static tmxparser::TmxMap map;
|
// static tmxparser::TmxMap map;
|
||||||
// gameScene;
|
// gameScene;
|
||||||
|
static std::string projPath;
|
||||||
static bool debugMenu;
|
static bool debugMenu;
|
||||||
static bool isRunning;
|
static bool isRunning;
|
||||||
static bool debugCollisionBoxes;
|
static bool debugCollisionBoxes;
|
||||||
|
@ -11,7 +11,6 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
//#include <mach-o/dyld.h>
|
|
||||||
#include <boost/filesystem.hpp>
|
#include <boost/filesystem.hpp>
|
||||||
|
|
||||||
Game *game = nullptr;
|
Game *game = nullptr;
|
||||||
@ -27,41 +26,46 @@ int main(int argc, const char * argv[])
|
|||||||
|
|
||||||
boost::filesystem::path p{argv[0]};
|
boost::filesystem::path p{argv[0]};
|
||||||
p = absolute(p).parent_path();
|
p = absolute(p).parent_path();
|
||||||
std::cout << "boost path: " << p << std::endl;
|
// std::cout << "boost path: " << p << std::endl;
|
||||||
|
|
||||||
// =============================
|
// =============================
|
||||||
// Load cJSON config.json file
|
// Load cJSON config.json file
|
||||||
// =============================
|
// =============================
|
||||||
// Starting with Error Checking
|
// Starting with Error Checking
|
||||||
//std::string configPath = "src/config/config.json";
|
std::string configPath = "src/config/config.json";
|
||||||
std::string configPath = "/Users/ayoungblood/Projects/KaijuSaveEarth/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
|
// /Users/ayoungblood/Projects/KaijuSaveEarth
|
||||||
// std::string fullPath = p.c_str() + "/" + configPath;
|
// 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 << "Attempting to load: " << configPath << std::endl;
|
||||||
// std::cout << "Current working Dir: " << std::filesystem::current_path() << std::endl;
|
// std::cout << "Current working Dir: " << std::filesystem::current_path() << std::endl;
|
||||||
if(!fin.is_open()){
|
if(!fin.is_open()){
|
||||||
std::cerr<<"ERROR: config.json not found or opened"<<std::endl;
|
std::cerr<<"ERROR: config.json not found or opened"<<std::endl;
|
||||||
} else {
|
} else {
|
||||||
printf("config.json loaded successfully.\n");
|
printf("config.json loaded successfully.\n");
|
||||||
}
|
|
||||||
/*std::ifstream jsonText("src/config/config.json");
|
std::ifstream jsonText(configurationPath);
|
||||||
std::ostringstream tmp;
|
std::ostringstream tmp;
|
||||||
tmp << jsonText.rdbuf();
|
tmp << jsonText.rdbuf();
|
||||||
std::string json = tmp.str();
|
std::string json = tmp.str();
|
||||||
cJSON * myJSON = cJSON_Parse(json.c_str());
|
cJSON * myJSON = cJSON_Parse(json.c_str());
|
||||||
cJSON * windowName = cJSON_GetObjectItemCaseSensitive(myJSON, "WindowName");
|
cJSON * windowName = cJSON_GetObjectItemCaseSensitive(myJSON, "WindowName");
|
||||||
cJSON * windowSize = cJSON_GetObjectItem(myJSON, "WindowSize");*/
|
cJSON * windowSize = cJSON_GetObjectItem(myJSON, "WindowSize");
|
||||||
// int windowWidth = cJSON_GetObjectItem(windowSize, "w")->valueint;
|
int windowWidth = cJSON_GetObjectItem(windowSize, "w")->valueint;
|
||||||
// int windowHeight = cJSON_GetObjectItem(windowSize, "h")->valueint;
|
int windowHeight = cJSON_GetObjectItem(windowSize, "h")->valueint;
|
||||||
// int windowFS = cJSON_GetObjectItem(myJSON, "WindowFullScreen")->valueint;
|
int windowFS = cJSON_GetObjectItem(myJSON, "WindowFullScreen")->valueint;
|
||||||
// int globalScale = cJSON_GetObjectItem(myJSON, "GlobalScale")->valueint;
|
int globalScale = cJSON_GetObjectItem(myJSON, "GlobalScale")->valueint;
|
||||||
int windowWidth = 64;
|
/* int windowWidth = 64;
|
||||||
int windowHeight = 64;
|
int windowHeight = 64;
|
||||||
int windowFS = 0;
|
int windowFS = 0;
|
||||||
int globalScale = 10;
|
int globalScale = 10;*/
|
||||||
bool isWindowFS;
|
bool isWindowFS;
|
||||||
std::string windowName = "KaijuSaveEarth";
|
//std::string windowName = "KaijuSaveEarth";
|
||||||
if (windowFS==0)
|
if (windowFS==0)
|
||||||
{
|
{
|
||||||
isWindowFS = false;
|
isWindowFS = false;
|
||||||
@ -71,11 +75,11 @@ int main(int argc, const char * argv[])
|
|||||||
}
|
}
|
||||||
windowWidth = windowWidth*globalScale;
|
windowWidth = windowWidth*globalScale;
|
||||||
windowHeight = windowHeight*globalScale;
|
windowHeight = windowHeight*globalScale;
|
||||||
game = new Game();
|
game = new Game(bps);
|
||||||
// game->init(windowName->valuestring, windowWidth, windowHeight, isWindowFS, globalScale);
|
game->init(windowName->valuestring, windowWidth, windowHeight, isWindowFS, globalScale);
|
||||||
game->init(windowName.c_str(), windowWidth, windowHeight, isWindowFS, globalScale);
|
// game->init(windowName.c_str(), windowWidth, windowHeight, isWindowFS, globalScale);
|
||||||
// cJSON memory management
|
// cJSON memory management
|
||||||
// cJSON_Delete(myJSON);
|
cJSON_Delete(myJSON);
|
||||||
|
|
||||||
while (game->running())
|
while (game->running())
|
||||||
{
|
{
|
||||||
@ -94,7 +98,7 @@ int main(int argc, const char * argv[])
|
|||||||
|
|
||||||
}
|
}
|
||||||
game->clean();
|
game->clean();
|
||||||
// }
|
}
|
||||||
|
|
||||||
if(fin.fail()){
|
if(fin.fail()){
|
||||||
std::cout<<"config.json load failed"<<std::endl;
|
std::cout<<"config.json load failed"<<std::endl;
|
||||||
|
Loading…
Reference in New Issue
Block a user