Implemented unlocking of areas via clearing stages. Game fade in/out for state transitions. Asset loading for visual novel assets. Visual Novel command execution code implemented. Visual Novel basic rendering and input handling enabled.

This commit is contained in:
2023-11-28 18:29:06 -06:00
parent 3601e8b83a
commit a7f13e0077
21 changed files with 279 additions and 127 deletions
+84 -36
View File
@@ -35,9 +35,16 @@ SUCH DAMAGE.
#include "GameState.h"
#include "Crawler.h"
#include <fstream>
#include "DEFINES.h"
#include "Unlock.h"
#include "Menu.h"
INCLUDE_game
INCLUDE_GFX
VisualNovel VisualNovel::novel;
safemap<std::string,std::vector<std::unique_ptr<Command>>>VisualNovel::storyLevelData;
std::set<std::string>VisualNovel::graphicsToLoad;
void VisualNovel::Initialize(){
for(int chapter=1;chapter<=6;chapter++){
@@ -80,6 +87,17 @@ void VisualNovel::Initialize(){
case '{':{ //Start of a command.
auto&data=storyLevelData.at(currentStory);
auto AddImagesForLoading=[](std::vector<std::string>&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::vector<std::string>arguments;
@@ -97,12 +115,15 @@ void VisualNovel::Initialize(){
}else
if(line.find("{BACKGROUND")!=std::string::npos){//Background command
if(arguments.size()!=1)ERR("Arguments size is "<<arguments.size()<<". Expecting only 1 argument.")
graphicsToLoad.insert("story_background_image_location"_S+arguments[0]);
data.push_back(std::make_unique<BackgroundCommand>(arguments[0]));
}else
if(line.find("{LEFT")!=std::string::npos){//Left command
AddImagesForLoading(arguments);
data.push_back(std::make_unique<LeftCommand>(arguments));
}else
if(line.find("{RIGHT")!=std::string::npos){//Right command
AddImagesForLoading(arguments);
data.push_back(std::make_unique<RightCommand>(arguments));
}else
if(line.find("{PAUSE")!=std::string::npos){//Pause command
@@ -141,13 +162,51 @@ void VisualNovel::Initialize(){
};
void VisualNovel::LoadVisualNovel(std::string storyLevelName){
novel.storyLevel=storyLevelName;
GameState::ChangeState(States::STORY);
novel.activeText="";
novel.leftCharacters.clear();
novel.rightCharacters.clear();
novel.backgroundFilename="";
novel.commands.clear();
for(std::unique_ptr<Command>&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(commandIndex<commands.size()){
commandIndex++;
commands[commandIndex-1]->Execute(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(){}
@@ -155,60 +214,49 @@ 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){
}
:location(location){}
void BackgroundCommand::Execute(VisualNovel&vn){
vn.backgroundFilename=backgroundFilename;
vn.ExecuteNextCommand();
}
BackgroundCommand::BackgroundCommand(std::string backgroundFilename)
:backgroundFilename(backgroundFilename){
}
:backgroundFilename(backgroundFilename){}
void LeftCommand::Execute(VisualNovel&vn){
vn.leftCharacters=characters;
vn.ExecuteNextCommand();
}
LeftCommand::LeftCommand(std::vector<std::string>characters)
:characters(characters){
}
:characters(characters){}
void RightCommand::Execute(VisualNovel&vn){
vn.rightCharacters=characters;
vn.ExecuteNextCommand();
}
RightCommand::RightCommand(std::vector<std::string>characters)
:characters(characters){
}
:characters(characters){}
void SpeakerCommand::Execute(VisualNovel&vn){
vn.speakerDisplayName=displayedName;
vn.actualSpeakerName=actualSpeakerName;
vn.ExecuteNextCommand();
}
SpeakerCommand::SpeakerCommand(std::string speaker)
:displayedName(speaker),actualSpeakerName(speaker){
}
:displayedName(speaker),actualSpeakerName(speaker){}
SpeakerCommand::SpeakerCommand(std::string displayedName,std::string speaker)
:displayedName(displayedName),actualSpeakerName(speaker){
}
:displayedName(displayedName),actualSpeakerName(speaker){}
void DialogCommand::Execute(VisualNovel&vn){
vn.activeText=dialog;
}
DialogCommand::DialogCommand(std::string dialog)
:dialog(dialog){
}
:dialog(dialog){}
void PauseCommand::Execute(VisualNovel&vn){
}
PauseCommand::PauseCommand(){
}
void PauseCommand::Execute(VisualNovel&vn){}
PauseCommand::PauseCommand(){}