#pragma region License /* License (OLC-3) ~~~~~~~~~~~~~~~ Copyright 2018 - 2023 OneLoneCoder.com Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions or derivations of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions or derivative works in binary form must reproduce the above copyright notice. This list of conditions and the following disclaimer must be reproduced in the documentation and/or other materials provided with the distribution. 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #pragma endregion #include "VisualNovel.h" #include "GameState.h" #include "Crawler.h" #include #include "DEFINES.h" #include "Unlock.h" #include "Menu.h" INCLUDE_game INCLUDE_GFX VisualNovel VisualNovel::novel; safemap>>VisualNovel::storyLevelData; std::setVisualNovel::graphicsToLoad; void VisualNovel::Initialize(){ for(int chapter=1;chapter<=6;chapter++){ std::string chapterFilename="assets/"+"story_directory"_S+"Chapter "+std::to_string(chapter)+".txt"; std::ifstream file(chapterFilename); if(!file)ERR("Failed to open file "<args; size_t counter=0; while(text.find(',',counter)!=std::string::npos){ std::string arg=text.substr(counter,text.find(',',counter)-counter); counter=text.find(',',counter)+1; if(arg.find(',')!=std::string::npos)ERR("Found an erraneous comma inside parsed arg "<&arguments){ for(std::string&arg:arguments){ if(arg=="story_player_name"_S){ graphicsToLoad.insert("character_image_location"_S+"Player_F.png"); graphicsToLoad.insert("character_image_location"_S+"Player_M.png"); }else{ graphicsToLoad.insert("character_image_location"_S+arg+".png"); } } }; size_t spacePos=line.find(' '); std::vectorarguments; if(spacePos!=std::string::npos){//There are arguments to parse... size_t endingBracePos=line.find('}',spacePos+1); if(endingBracePos==std::string::npos)ERR("Cannot parse arguments from "<(arguments[0])); }else if(line.find("{BACKGROUND")!=std::string::npos){//Background command if(arguments.size()!=1)ERR("Arguments size is "<(arguments[0])); }else if(line.find("{LEFT")!=std::string::npos){//Left command AddImagesForLoading(arguments); data.push_back(std::make_unique(arguments)); }else if(line.find("{RIGHT")!=std::string::npos){//Right command AddImagesForLoading(arguments); data.push_back(std::make_unique(arguments)); }else if(line.find("{PAUSE")!=std::string::npos){//Pause command if(arguments.size()!=0)ERR("Arguments size is "<()); }else{ ERR("Unknown command "<arguments=ReadCSVArgs(args); if(arguments.size()>2)ERR("Expecting a maximum of two arguments for parsed args in "<(arguments[0])); }else{ data.push_back(std::make_unique(arguments[0],arguments[1])); } }break; default:{ auto&data=storyLevelData.at(currentStory); data.push_back(std::make_unique(line)); }break; } } } storyLevelData.SetInitialized(); }; void VisualNovel::LoadVisualNovel(std::string storyLevelName){ novel.storyLevel=storyLevelName; novel.activeText=""; novel.leftCharacters.clear(); novel.rightCharacters.clear(); novel.backgroundFilename=""; novel.commands.clear(); for(std::unique_ptr&command:storyLevelData.at(storyLevelName)){ novel.commands.push_back(command.get()); } GameState::ChangeState(States::STORY,0.5f); novel.ExecuteNextCommand(); novel.prevTheme=Menu::GetCurrentTheme().GetThemeName(); Menu::themeSelection="Purple"; } void VisualNovel::Update(){ if(game->KEY_CONFIRM.Pressed()){ novel.ExecuteNextCommand(); } locationDisplayTime=std::max(0.f,locationDisplayTime-game->GetElapsedTime()); } void VisualNovel::ExecuteNextCommand(){ if(commandIndexExecute(novel); }else{ Unlock::UnlockCurrentMap(); Menu::themeSelection=novel.prevTheme; GameState::ChangeState(States::OVERWORLD_MAP,0.5f); } } void VisualNovel::Draw(){ if(backgroundFilename!=""){ game->DrawDecal({0,0},GFX["backgrounds/"+backgroundFilename].Decal()); }else{ game->FillRectDecal({0,0},game->GetScreenSize()); } if(locationDisplayTime>0){ vi2d textSize=game->GetTextSizeProp(locationDisplayText)*2; game->FillRectDecal(game->GetScreenSize()/2-textSize/2-vi2d{4,4},textSize+vi2d{8,8},BLACK); game->DrawRectDecal(game->GetScreenSize()/2-textSize/2-vi2d{4,4},textSize+vi2d{8,8},WHITE); game->DrawShadowStringPropDecal(game->GetScreenSize()/2-textSize/2,locationDisplayText,WHITE,VERY_DARK_BLUE,{2.f,2.f}); } if(activeText.length()>0){ Menu::DrawThemedWindow({24.f,game->GetScreenSize().y-60.f},{48.f,-12.f}); Menu::DrawThemedWindow({24.f,game->GetScreenSize().y-48.f},{game->GetScreenSize().x-48.f,20.f}); } } VisualNovel::VisualNovel(){} Command::Command(){} void LocationCommand::Execute(VisualNovel&vn){ vn.locationDisplayTime=5.f; vn.locationDisplayText=location; vn.ExecuteNextCommand(); } LocationCommand::LocationCommand(std::string location) :location(location){} void BackgroundCommand::Execute(VisualNovel&vn){ vn.backgroundFilename=backgroundFilename; vn.ExecuteNextCommand(); } BackgroundCommand::BackgroundCommand(std::string backgroundFilename) :backgroundFilename(backgroundFilename){} void LeftCommand::Execute(VisualNovel&vn){ vn.leftCharacters=characters; vn.ExecuteNextCommand(); } LeftCommand::LeftCommand(std::vectorcharacters) :characters(characters){} void RightCommand::Execute(VisualNovel&vn){ vn.rightCharacters=characters; vn.ExecuteNextCommand(); } RightCommand::RightCommand(std::vectorcharacters) :characters(characters){} void SpeakerCommand::Execute(VisualNovel&vn){ vn.speakerDisplayName=displayedName; vn.actualSpeakerName=actualSpeakerName; vn.ExecuteNextCommand(); } SpeakerCommand::SpeakerCommand(std::string speaker) :displayedName(speaker),actualSpeakerName(speaker){} SpeakerCommand::SpeakerCommand(std::string displayedName,std::string speaker) :displayedName(displayedName),actualSpeakerName(speaker){} void DialogCommand::Execute(VisualNovel&vn){ vn.activeText=dialog; } DialogCommand::DialogCommand(std::string dialog) :dialog(dialog){} void PauseCommand::Execute(VisualNovel&vn){} PauseCommand::PauseCommand(){}