1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-24 22:14:36 +02:00

- minor fixes to JSON

- music will resume correctly after battles
This commit is contained in:
Ivan Savenko 2011-08-20 11:27:09 +00:00
parent 8fa540b4da
commit 7eb82278d9
8 changed files with 36 additions and 19 deletions

View File

@ -1450,7 +1450,8 @@ void CAdvMapInt::select(const CArmedInstance *sel, bool centerView /*= true*/)
assert(sel);
LOCPLINT->cb->setSelection(sel);
selection = sel;
CCS->musich->playMusic(CCS->musich->terrainMusics[LOCPLINT->cb->getTile(sel->visitablePos())->tertype]);
if (LOCPLINT->battleInt == NULL)
CCS->musich->playMusic(CCS->musich->terrainMusics[LOCPLINT->cb->getTile(sel->visitablePos())->tertype]);
if(centerView)
centerOn(sel);

View File

@ -27,6 +27,7 @@
#include "CCreatureWindow.h"
#include "CVideoHandler.h"
#include "../lib/CTownHandler.h"
#include "../lib/map.h"
#include <boost/assign/list_of.hpp>
#include <boost/foreach.hpp>
#include <boost/lexical_cast.hpp>
@ -1431,6 +1432,12 @@ CBattleInterface::CBattleInterface(const CCreatureSet * army1, const CCreatureSe
bTacticNextStack();
active = 0;
}
CCS->musich->stopMusic();
int channel = CCS->soundh->playSoundFromSet(CCS->soundh->battleIntroSounds);
CCS->soundh->setCallback(channel, boost::bind(&CMusicHandler::playMusicFromSet, CCS->musich, CCS->musich->battleMusics, -1));
}
CBattleInterface::~CBattleInterface()
@ -1478,7 +1485,15 @@ CBattleInterface::~CBattleInterface()
delete siegeH;
curInt->battleInt = NULL;
//TODO:restart music (can be AI or terrain). May be easier to backup and restore it instead of re-selecting
//TODO: play AI tracks if battle was during AI turn
//if (!curInt->makingTurn)
//CCS->musich->playMusicFromSet(CCS->musich->aiMusics, -1);
if(adventureInt && adventureInt->selection)
{
int terrain = LOCPLINT->cb->getTile(adventureInt->selection->visitablePos())->tertype;
CCS->musich->playMusic(CCS->musich->terrainMusics[terrain], -1);
}
}
void CBattleInterface::setPrintCellBorders(bool set)

View File

@ -331,6 +331,8 @@ CMusicHandler::CMusicHandler()
#undef VCMI_MUSIC_FILE
// Vectors for helper
aiMusics += musicBase::AITheme0, musicBase::AITheme1, musicBase::AITheme2;
battleMusics += musicBase::combat1, musicBase::combat2,
musicBase::combat3, musicBase::combat4;

View File

@ -157,6 +157,7 @@ public:
// Musics
std::map<musicBase::musicID, std::string> musics;
std::vector<musicBase::musicID> aiMusics;
std::vector<musicBase::musicID> battleMusics;
std::vector<musicBase::musicID> townMusics;
std::vector<musicBase::musicID> terrainMusics;

View File

@ -571,10 +571,6 @@ void CPlayerInterface::battleStart(const CCreatureSet *army1, const CCreatureSet
SDL_Delay(20);
boost::unique_lock<boost::recursive_mutex> un(*pim);
CCS->musich->stopMusic();
int channel = CCS->soundh->playSoundFromSet(CCS->soundh->battleIntroSounds);
CCS->soundh->setCallback(channel, boost::bind(&CMusicHandler::playMusicFromSet, CCS->musich, CCS->musich->battleMusics, -1));
GH.pushInt(battleInt);
}

View File

@ -2,28 +2,28 @@
{
"difficulty":
[
{
{
"human": { "wood" : 30, "mercury": 15, "ore": 30, "sulfur": 15, "crystal": 15, "gems": 15, "gold": 30000, "mithril": 0 },
"ai": { "wood" : 5, "mercury": 2, "ore": 5, "sulfur": 2, "crystal": 2, "gems": 2, "gold": 5000, "mithril": 0 }
},
{
{
"human": { "wood" : 20, "mercury": 10, "ore": 20, "sulfur": 10, "crystal": 10, "gems": 10, "gold": 20000, "mithril": 0 },
"ai": { "wood" : 10, "mercury": 4, "ore": 10, "sulfur": 4, "crystal": 4, "gems": 4, "gold": 7500, "mithril": 0 }
},
{
{
"human": { "wood" : 15, "mercury": 7, "ore": 15, "sulfur": 7, "crystal": 7, "gems": 7, "gold": 15000, "mithril": 0 },
"ai": { "wood" : 15, "mercury": 7, "ore": 15, "sulfur": 7, "crystal": 7, "gems": 7, "gold": 10000, "mithril": 0 }
},
{
{
"human": { "wood" : 10, "mercury": 4, "ore": 10, "sulfur": 4, "crystal": 4, "gems": 4, "gold": 10000, "mithril": 0 },
"ai": { "wood" : 15, "mercury": 7, "ore": 15, "sulfur": 7, "crystal": 7, "gems": 7, "gold": 10000, "mithril": 0 }
}
},
{
"human": { "wood" : 0, "mercury": 0, "ore": 0 , "sulfur": 0, "crystal": 0, "gems": 0, "gold": 0, "mithril": 0 },
"human": { "wood" : 0, "mercury": 0, "ore": 0 , "sulfur": 0, "crystal": 0, "gems": 0, "gold": 0, "mithril": 0 },
"ai": { "wood" : 15, "mercury": 7, "ore": 15, "sulfur": 7, "crystal": 7, "gems": 7, "gold": 10000, "mithril": 0 }
}
]

View File

@ -20,7 +20,8 @@ JsonNode::JsonNode(std::string input):
JsonParser parser(input, *this);
}
JsonNode::JsonNode(const char *filename)
JsonNode::JsonNode(const char *filename):
type(DATA_NULL)
{
std::ifstream file(filename);
std::string str((std::istreambuf_iterator<char>(file)),
@ -246,12 +247,13 @@ JsonParser::JsonParser(const std::string inputString, JsonNode &root):
pos(0)
{
extractValue(root);
extractWhitespace(false);
//Warn if there are any non-whitespace symbols left
if (input.find_first_not_of(" \r\t\n", pos) != std::string::npos)
if (pos < input.size())
error("Not all file was parsed!", true);
//TODO: better way to show errors
//TODO: better way to show errors (like printing file name as well)
tlog2<<errors;
}
@ -290,7 +292,7 @@ bool JsonParser::extractValue(JsonNode &node)
}
}
bool JsonParser::extractWhitespace()
bool JsonParser::extractWhitespace(bool verbose)
{
while (true)
{
@ -317,7 +319,7 @@ bool JsonParser::extractWhitespace()
pos = input.find('\n', pos);
}
if (pos >= input.size())
if (pos >= input.size() && verbose)
return error("Unexpected end of file!");
return true;
}

View File

@ -43,7 +43,7 @@ public:
//Create tree from Json-formatted input
explicit JsonNode(std::string input);
//Create tree from JSON file
JsonNode(const char *filename);
explicit JsonNode(const char *filename);
//Copy c-tor
JsonNode(const JsonNode &copy);
@ -101,7 +101,7 @@ class JsonParser
bool extractEscaping(std::string &str);
bool extractLiteral(const std::string &literal);
bool extractString(std::string &string);
bool extractWhitespace();
bool extractWhitespace(bool verbose = true);
bool extractSeparator();
//Methods for extracting JSON data