Corrected missing header dependencies in safemap. Story file parser implementation and command data storage works proper.

pull/28/head
sigonasr2 1 year ago
parent 90d465fd7b
commit 67bc955f83
  1. 2
      Crawler/Crawler.vcxproj
  2. 6
      Crawler/Crawler.vcxproj.filters
  3. 2
      Crawler/Version.h
  4. 48
      Crawler/VisualNovel.cpp
  5. 16
      Crawler/VisualNovel.h
  6. 3
      Crawler/safemap.h

@ -329,6 +329,7 @@
</ClInclude> </ClInclude>
<ClInclude Include="State_MainMenu.h" /> <ClInclude Include="State_MainMenu.h" />
<ClInclude Include="State_OverworldMap.h" /> <ClInclude Include="State_OverworldMap.h" />
<ClInclude Include="State_Story.h" />
<ClInclude Include="VisualNovel.h" /> <ClInclude Include="VisualNovel.h" />
<ClInclude Include="Test.h" /> <ClInclude Include="Test.h" />
<ClInclude Include="Theme.h" /> <ClInclude Include="Theme.h" />
@ -391,6 +392,7 @@
</ClCompile> </ClCompile>
<ClCompile Include="State_MainMenu.cpp" /> <ClCompile Include="State_MainMenu.cpp" />
<ClCompile Include="State_OverworldMap.cpp" /> <ClCompile Include="State_OverworldMap.cpp" />
<ClCompile Include="State_Story.cpp" />
<ClCompile Include="Test.cpp" /> <ClCompile Include="Test.cpp" />
<ClCompile Include="TestMenu.cpp" /> <ClCompile Include="TestMenu.cpp" />
<ClCompile Include="TestSubMenu.cpp" /> <ClCompile Include="TestSubMenu.cpp" />

@ -270,6 +270,9 @@
<ClInclude Include="VisualNovel.h"> <ClInclude Include="VisualNovel.h">
<Filter>Header Files</Filter> <Filter>Header Files</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="State_Story.h">
<Filter>Header Files\State</Filter>
</ClInclude>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClCompile Include="Player.cpp"> <ClCompile Include="Player.cpp">
@ -452,6 +455,9 @@
<ClCompile Include="VisualNovel.cpp"> <ClCompile Include="VisualNovel.cpp">
<Filter>Source Files</Filter> <Filter>Source Files</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="State_Story.cpp">
<Filter>Source Files\Game States</Filter>
</ClCompile>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<None Include="cpp.hint" /> <None Include="cpp.hint" />

@ -35,7 +35,7 @@ SUCH DAMAGE.
#define VERSION_MAJOR 0 #define VERSION_MAJOR 0
#define VERSION_MINOR 2 #define VERSION_MINOR 2
#define VERSION_PATCH 1 #define VERSION_PATCH 1
#define VERSION_BUILD 3160 #define VERSION_BUILD 3172
#define stringify(a) stringify_(a) #define stringify(a) stringify_(a)
#define stringify_(a) #a #define stringify_(a) #a

@ -41,7 +41,7 @@ safemap<std::string,std::vector<std::unique_ptr<Command>>>VisualNovel::storyLeve
void VisualNovel::Initialize(){ void VisualNovel::Initialize(){
for(int chapter=1;chapter<=6;chapter++){ for(int chapter=1;chapter<=6;chapter++){
std::string chapterFilename="story_directory"_S+"Chapter "+std::to_string(chapter)+".txt"; std::string chapterFilename="assets/"+"story_directory"_S+"Chapter "+std::to_string(chapter)+".txt";
std::ifstream file(chapterFilename); std::ifstream file(chapterFilename);
if(!file)ERR("Failed to open file "<<chapterFilename) if(!file)ERR("Failed to open file "<<chapterFilename)
std::string line; std::string line;
@ -71,8 +71,6 @@ void VisualNovel::Initialize(){
line=trim(line); line=trim(line);
if(line.length()==0)continue; //It's a blank line, so we skip it. if(line.length()==0)continue; //It's a blank line, so we skip it.
auto&data=storyLevelData.at(currentStory);
switch(line[0]){ switch(line[0]){
case '=':{ //Initializes a new story section. case '=':{ //Initializes a new story section.
currentStory=line.substr(3,line.find('=',3)-3); currentStory=line.substr(3,line.find('=',3)-3);
@ -80,13 +78,18 @@ void VisualNovel::Initialize(){
storyLevelData[currentStory]; storyLevelData[currentStory];
}break; }break;
case '{':{ //Start of a command. case '{':{ //Start of a command.
auto&data=storyLevelData.at(currentStory);
size_t spacePos=line.find(' '); size_t spacePos=line.find(' ');
if(spacePos==std::string::npos)ERR("Cannot parse arguments from "<<line<<": No space found"); std::vector<std::string>arguments;
size_t endingBracePos=line.find('}',spacePos+1);
if(endingBracePos==std::string::npos)ERR("Cannot parse arguments from "<<line<<": No closing ending brace found") if(spacePos!=std::string::npos){//There are arguments to parse...
std::string args=line.substr(spacePos+1,endingBracePos-(spacePos+1)); size_t endingBracePos=line.find('}',spacePos+1);
if(args.find(' ')!=std::string::npos||args.find('}')!=std::string::npos)ERR("Cannot parse args, found invalid tokens in "<<args) if(endingBracePos==std::string::npos)ERR("Cannot parse arguments from "<<line<<": No closing ending brace found")
std::vector<std::string>arguments=ReadCSVArgs(args); std::string args=line.substr(spacePos+1,endingBracePos-(spacePos+1));
if(line.size()==0||line[0]==' '||args.find('}')!=std::string::npos)ERR("Cannot parse args, found invalid tokens in "<<args)
arguments=ReadCSVArgs(args);
}
if(line.find("{LOCATION")!=std::string::npos){//Location command if(line.find("{LOCATION")!=std::string::npos){//Location command
if(arguments.size()!=1)ERR("Arguments size is "<<arguments.size()<<". Expecting only 1 argument.") if(arguments.size()!=1)ERR("Arguments size is "<<arguments.size()<<". Expecting only 1 argument.")
@ -110,6 +113,8 @@ void VisualNovel::Initialize(){
} }
}break; }break;
case '[':{ case '[':{
auto&data=storyLevelData.at(currentStory);
size_t endingBracePos=line.find(']'); size_t endingBracePos=line.find(']');
if(endingBracePos==std::string::npos)ERR("Cannot parse arguments from "<<line<<": No closing ending bracket found") if(endingBracePos==std::string::npos)ERR("Cannot parse arguments from "<<line<<": No closing ending bracket found")
std::string args=line.substr(1,endingBracePos-1); std::string args=line.substr(1,endingBracePos-1);
@ -123,6 +128,8 @@ void VisualNovel::Initialize(){
} }
}break; }break;
default:{ default:{
auto&data=storyLevelData.at(currentStory);
data.push_back(std::make_unique<DialogCommand>(line)); data.push_back(std::make_unique<DialogCommand>(line));
}break; }break;
} }
@ -143,50 +150,59 @@ void VisualNovel::Draw(){
} }
VisualNovel::VisualNovel(){}
Command::Command(){} Command::Command(){}
void LocationCommand::Execute(VisualNovel&vn){ void LocationCommand::Execute(VisualNovel&vn){
} }
LocationCommand::LocationCommand(std::string location){ LocationCommand::LocationCommand(std::string location)
:location(location){
} }
void BackgroundCommand::Execute(VisualNovel&vn){ void BackgroundCommand::Execute(VisualNovel&vn){
} }
BackgroundCommand::BackgroundCommand(std::string backgroundFilename){ BackgroundCommand::BackgroundCommand(std::string backgroundFilename)
:backgroundFilename(backgroundFilename){
} }
void LeftCommand::Execute(VisualNovel&vn){ void LeftCommand::Execute(VisualNovel&vn){
} }
LeftCommand::LeftCommand(std::vector<std::string>characters){ LeftCommand::LeftCommand(std::vector<std::string>characters)
:characters(characters){
} }
void RightCommand::Execute(VisualNovel&vn){ void RightCommand::Execute(VisualNovel&vn){
} }
RightCommand::RightCommand(std::vector<std::string>characters){ RightCommand::RightCommand(std::vector<std::string>characters)
:characters(characters){
} }
void SpeakerCommand::Execute(VisualNovel&vn){ void SpeakerCommand::Execute(VisualNovel&vn){
} }
SpeakerCommand::SpeakerCommand(std::string speaker){ SpeakerCommand::SpeakerCommand(std::string speaker)
:displayedName(speaker),actualSpeakerName(speaker){
} }
SpeakerCommand::SpeakerCommand(std::string displayedName,std::string speaker){ SpeakerCommand::SpeakerCommand(std::string displayedName,std::string speaker)
:displayedName(displayedName),actualSpeakerName(speaker){
} }
void DialogCommand::Execute(VisualNovel&vn){ void DialogCommand::Execute(VisualNovel&vn){
} }
DialogCommand::DialogCommand(std::string dialog){ DialogCommand::DialogCommand(std::string dialog)
:dialog(dialog){
} }

@ -38,6 +38,12 @@ SUCH DAMAGE.
class VisualNovel; class VisualNovel;
class Command{
virtual void Execute(VisualNovel&vn)=0;
protected:
Command();
};
class PauseCommand final:public Command{ class PauseCommand final:public Command{
public: public:
void Execute(VisualNovel&vn)override; void Execute(VisualNovel&vn)override;
@ -88,12 +94,6 @@ public:
LocationCommand(std::string location); LocationCommand(std::string location);
}; };
class Command{
virtual void Execute(VisualNovel&vn)=0;
protected:
Command();
};
class VisualNovel{ class VisualNovel{
std::string storyLevel; std::string storyLevel;
std::string activeText; std::string activeText;
@ -101,13 +101,13 @@ class VisualNovel{
std::vector<std::string>rightCharacters; std::vector<std::string>rightCharacters;
std::string backgroundFilename; std::string backgroundFilename;
std::vector<Command*>commands; std::vector<Command*>commands;
int commandIndex; int commandIndex=0;
static safemap<std::string,std::vector<std::unique_ptr<Command>>>storyLevelData; static safemap<std::string,std::vector<std::unique_ptr<Command>>>storyLevelData;
static VisualNovel novel; static VisualNovel novel;
VisualNovel();
public: public:
VisualNovel()=delete;
VisualNovel(VisualNovel&)=delete; VisualNovel(VisualNovel&)=delete;
VisualNovel(VisualNovel&&)=delete; VisualNovel(VisualNovel&&)=delete;
static void Initialize(); static void Initialize();

@ -33,6 +33,9 @@ SUCH DAMAGE.
#pragma endregion #pragma endregion
#pragma once #pragma once
#include "Error.h" #include "Error.h"
#include <functional>
#include <map>
#include <unordered_map>
//A class that has an initialization lock so that when the lock is activated, any further gets that are missing items in it will report themselves for easier debugging detection. //A class that has an initialization lock so that when the lock is activated, any further gets that are missing items in it will report themselves for easier debugging detection.
template<typename T,typename O> template<typename T,typename O>

Loading…
Cancel
Save