Hooked the two scenes together
What the hell am I doing?
This commit is contained in:
@@ -1,3 +1,24 @@
|
||||
/* Copyright: (c) Kayne Ruse 2013
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
*
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
*
|
||||
* 3. This notice may not be removed or altered from any source
|
||||
* distribution.
|
||||
*/
|
||||
#include "map_loader.hpp"
|
||||
|
||||
#include "utility.hpp"
|
||||
@@ -6,98 +27,9 @@
|
||||
#include <stdexcept>
|
||||
|
||||
void loadGameMap(std::string mapPathName, RegionPager* const, TileSheetManager* const) {
|
||||
/* //open the index file
|
||||
std::ifstream indexFile(mapPathName + "\\index");
|
||||
if (!indexFile.is_open()) {
|
||||
throw(std::runtime_error(std::string("Failed to open game map: ") + mapPathName));
|
||||
}
|
||||
|
||||
//read each part of the metadata header
|
||||
std::string buffer, knownName;
|
||||
int sheetCount = -1, rangeEnd = -1, regionWidth = -1, regionHeight = -1;
|
||||
|
||||
getline(indexFile, knownName);
|
||||
|
||||
if (knownName != truncatePath(mapPathName)) {
|
||||
//probably not needed, I'll losen this down the road
|
||||
throw(std::runtime_error("Internal and external map names do not match"));
|
||||
}
|
||||
|
||||
getline(indexFile, buffer, ',');
|
||||
sheetCount = to_integer_custom(buffer);
|
||||
|
||||
getline(indexFile, buffer, ',');
|
||||
rangeEnd = to_integer_custom(buffer);
|
||||
|
||||
getline(indexFile, buffer, ',');
|
||||
regionWidth = to_integer_custom(buffer);
|
||||
|
||||
getline(indexFile, buffer);
|
||||
regionHeight = to_integer_custom(buffer);
|
||||
|
||||
//setup the pager
|
||||
pager->GetRegions()->clear();
|
||||
pager->SetWidth(regionWidth);
|
||||
pager->SetHeight(regionHeight);
|
||||
pager->SetOnNew([](Region* const ptr) {
|
||||
//TODO
|
||||
});
|
||||
pager->SetOnDelete([](Region* const ptr) {
|
||||
//TODO
|
||||
});
|
||||
|
||||
//load all of the tile sheets
|
||||
sheetList->clear();
|
||||
for (int i = 0; i < sheetCount; i++) {
|
||||
sheetList->push_back(TileSheet());
|
||||
|
||||
//get the name, width & height
|
||||
std::string sheetName;
|
||||
getline(indexFile, sheetName, ',');
|
||||
getline(indexFile, buffer, ',');
|
||||
int w = to_integer_custom(buffer);
|
||||
getline(indexFile, buffer, ',');
|
||||
int h = to_integer_custom(buffer);
|
||||
|
||||
//load
|
||||
sheetList->back().LoadSurface(std::string("rsc\\graphics\\tilesets\\") + sheetName, w, h);
|
||||
|
||||
//set the range
|
||||
getline(indexFile, buffer, ',');
|
||||
sheetList->back().SetBegin(to_integer_custom(buffer));
|
||||
getline(indexFile, buffer);
|
||||
sheetList->back().SetEnd(to_integer_custom(buffer));
|
||||
}
|
||||
TileSheet::SetRangeEnd(rangeEnd);
|
||||
|
||||
//clean up
|
||||
indexFile.close();
|
||||
*/
|
||||
//
|
||||
}
|
||||
|
||||
void saveGameMap(std::string mapPathName, RegionPager* const, TileSheetManager* const) {
|
||||
/* //open the index file
|
||||
std::ofstream indexFile(mapPathName + "\\index");
|
||||
if (!indexFile.is_open()) {
|
||||
throw(std::runtime_error(std::string("Failed to open game map: ") + mapPathName));
|
||||
}
|
||||
|
||||
//write each part of the metadata header
|
||||
indexFile << truncatePath(mapPathName) << std::endl;
|
||||
indexFile << sheetList->size() << ", ";
|
||||
indexFile << TileSheet::GetRangeEnd() << ", ";
|
||||
indexFile << pager->GetWidth() << ", ";
|
||||
indexFile << pager->GetHeight() << std::endl;
|
||||
|
||||
//write each tile sheet's data
|
||||
for (auto& it : *sheetList) {
|
||||
indexFile << it.GetName() << ", ";
|
||||
indexFile << it.GetImage()->GetClipW() << ", ";
|
||||
indexFile << it.GetImage()->GetClipH() << ", ";
|
||||
indexFile << it.GetBegin() << ", ";
|
||||
indexFile << it.GetEnd() << std::endl;
|
||||
}
|
||||
|
||||
indexFile.close();
|
||||
*/
|
||||
//
|
||||
}
|
||||
@@ -1,3 +1,24 @@
|
||||
/* Copyright: (c) Kayne Ruse 2013
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
*
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
*
|
||||
* 3. This notice may not be removed or altered from any source
|
||||
* distribution.
|
||||
*/
|
||||
#ifndef MAPLOADER_HPP_
|
||||
#define MAPLOADER_HPP_
|
||||
|
||||
|
||||
@@ -109,14 +109,15 @@ void EditorApplication::LoadScene(SceneList sceneIndex) {
|
||||
switch(sceneIndex) {
|
||||
//add scene creation calls here
|
||||
case SceneList::FIRST:
|
||||
// case SceneList::TESTIFICATESCENE:
|
||||
// activeScene = new TestificateScene();
|
||||
// break;
|
||||
|
||||
case SceneList::EDITORSCENE:
|
||||
activeScene = new EditorScene();
|
||||
break;
|
||||
|
||||
case SceneList::TESTIFICATESCENE:
|
||||
activeScene = new TestificateScene();
|
||||
break;
|
||||
|
||||
|
||||
default:
|
||||
throw(std::logic_error("Failed to recognize the scene index"));
|
||||
}
|
||||
|
||||
+30
-15
@@ -34,22 +34,26 @@ using namespace std;
|
||||
//-------------------------
|
||||
|
||||
EditorScene::EditorScene() {
|
||||
//create the debugging "window"
|
||||
debugInfo.CreateSurface(256, 256);
|
||||
|
||||
//setup the utility objects
|
||||
font.LoadSurface("rsc\\graphics\\fonts\\pk_white_8.bmp");
|
||||
|
||||
buttonImage.LoadSurface("rsc\\graphics\\interface\\button_menu.bmp");
|
||||
buttonImage.SetClipH(buttonImage.GetClipH()/3);
|
||||
|
||||
//setup the menu bar
|
||||
menuBar.SetFont(&font);
|
||||
menuBar.SetImage(&buttonImage);
|
||||
|
||||
menuBar.SetEntries({
|
||||
{"File", "New", "Open", "Save", "Save As...", "Close", "Exit"},
|
||||
{"Edit", "Set Tile", "Load Sheet", "Delete Sheet", "Metadata", "Run Script"},
|
||||
{"Debugging", "Debug On", "Debug Off", "Toggle Debug"}
|
||||
{"File", "-New", "-Open", "-Save", "-Save As...", "-Close", "Exit"},
|
||||
{"Edit", "-Set Tile", "-Load Sheet", "-Delete Sheet", "-Metadata", "-Run Script"},
|
||||
{"Debugging", "Debug On", "Debug Off", "Toggle Debug", "Testificate"}
|
||||
});
|
||||
|
||||
//setup the pager
|
||||
pager.SetOnNew([](Region* const ptr){
|
||||
printf("New Region: %d, %d\n", ptr->GetX(), ptr->GetY());
|
||||
});
|
||||
@@ -62,18 +66,7 @@ EditorScene::EditorScene() {
|
||||
pager.SetWidth(32*4);
|
||||
pager.SetHeight(32*4);
|
||||
|
||||
sheetMgr.LoadSheet("rsc\\graphics\\tilesets\\grass.bmp", 32, 32);
|
||||
sheetMgr.LoadSheet("rsc\\graphics\\tilesets\\longgrass.bmp", 16, 16);
|
||||
|
||||
// loadGameMap("rsc\\maps\\mappy", &pager, &sheetList);
|
||||
// saveGameMap("rsc\\maps\\foo", &pager, &sheetList);
|
||||
|
||||
// cout << "Region Width: " << pager.GetWidth() << endl;
|
||||
// cout << "Region Height: " << pager.GetHeight() << endl;
|
||||
|
||||
// for (auto& it : sheetList) {
|
||||
// cout << it.GetName() << ": " << it.GetBegin() << ", " << it.GetEnd() << endl;
|
||||
// }
|
||||
sheetMgr.LoadSheet("rsc\\graphics\\tilesets\\terrain.bmp", 32, 32);
|
||||
}
|
||||
|
||||
EditorScene::~EditorScene() {
|
||||
@@ -135,6 +128,24 @@ void EditorScene::DrawToDebugInfo(std::string str, int line) {
|
||||
void EditorScene::MouseMotion(SDL_MouseMotionEvent const& motion) {
|
||||
menuBar.MouseMotion(motion);
|
||||
|
||||
if (motion.state & SDL_BUTTON_LMASK && motion.y >= buttonImage.GetClipH()) {
|
||||
Region* regionPtr = pager.GetRegion(
|
||||
snapToBase(pager.GetWidth(), motion.x + camera.x),
|
||||
snapToBase(pager.GetHeight(), motion.y + camera.y)
|
||||
);
|
||||
|
||||
TileSheet* sheetPtr = sheetMgr.GetSheetByIndex(tileCounter);
|
||||
|
||||
regionPtr->NewTileA({
|
||||
snapToBase(sheetPtr->GetTileW(), motion.x + camera.x), //x
|
||||
snapToBase(sheetPtr->GetTileH(), motion.y + camera.y), //y
|
||||
0, //depth
|
||||
sheetPtr->GetTileW(), //width
|
||||
sheetPtr->GetTileH(), //height
|
||||
tileCounter++ //value
|
||||
});
|
||||
}
|
||||
|
||||
if (motion.state & SDL_BUTTON_RMASK) {
|
||||
camera.x -= motion.xrel;
|
||||
camera.y -= motion.yrel;
|
||||
@@ -238,6 +249,10 @@ void EditorScene::MouseButtonUp(SDL_MouseButtonEvent const& button) {
|
||||
case 2:
|
||||
debugOpen = !debugOpen;
|
||||
break;
|
||||
|
||||
case 3:
|
||||
SetNextScene(SceneList::TESTIFICATESCENE);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -67,11 +67,11 @@ void TestificateScene::FrameEnd() {
|
||||
|
||||
void TestificateScene::Render(SDL_Surface* const screen) {
|
||||
//dump all tile graphics to the screen
|
||||
// for (int i = 0; i < sheetMgr.GetRangeEnd(); i++) {
|
||||
// sheetMgr.DrawTo(screen, i * 32 % screen->w, i * 32 / screen->w * 32, i);
|
||||
// }
|
||||
for (int i = 0; i < sheetMgr.GetRangeEnd(); i++) {
|
||||
sheetMgr.DrawTo(screen, i * 32 % screen->w, i * 32 / screen->w * 32, i);
|
||||
}
|
||||
|
||||
pager.DrawTo(screen, &sheetMgr, 0, 0);
|
||||
// pager.DrawTo(screen, &sheetMgr, 0, 0);
|
||||
}
|
||||
|
||||
//-------------------------
|
||||
@@ -94,7 +94,8 @@ void TestificateScene::MouseButtonUp(SDL_MouseButtonEvent const& button) {
|
||||
void TestificateScene::KeyDown(SDL_KeyboardEvent const& key) {
|
||||
switch(key.keysym.sym) {
|
||||
case SDLK_ESCAPE:
|
||||
QuitEvent();
|
||||
// QuitEvent();
|
||||
SetNextScene(SceneList::EDITORSCENE);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user