Skip to content

Commit

Permalink
Added directory cvar for saving and loading paths
Browse files Browse the repository at this point in the history
  • Loading branch information
CinderBlocc committed Apr 8, 2021
1 parent d978d90 commit c98e272
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 17 deletions.
4 changes: 2 additions & 2 deletions DollyCamPlugin2/DollyCamPlugin2.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,15 @@
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<AdditionalIncludeDirectories>$(BakkesModPath)bakkesmodsdk\include;$(ProjectDir)json\single_include\nlohmann;K:\cpplibs\json;K:\bakkesmod\BakkesMod-rewrite\BakkesMod Rewrite;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>$(BakkesModPath)bakkesmodsdk\include;$(ProjectDir)json\single_include\nlohmann;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>_WINDLL;%(PreprocessorDefinitions);_CRT_SECURE_NO_WARNINGS;</PreprocessorDefinitions>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
<LanguageStandard>stdcpp17</LanguageStandard>
</ClCompile>
<Link>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<AdditionalLibraryDirectories>$(BakkesModPath)bakkesmodsdk\lib;K:\cpplibs\json;K:\bakkesmod\BakkesMod-rewrite\x64\Release;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<AdditionalLibraryDirectories>$(BakkesModPath)bakkesmodsdk\lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
</Link>
<PostBuildEvent />
<PostBuildEvent>
Expand Down
35 changes: 30 additions & 5 deletions DollyCamPlugin2/dollycam.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -423,23 +423,31 @@ std::shared_ptr<InterpStrategy> DollyCam::CreateInterpStrategy(int interpStrateg
return std::make_shared<LinearInterpStrategy>(LinearInterpStrategy(currentPath, chaikinDegree));
}

void DollyCam::SaveToFile(std::string filename)
void DollyCam::SaveToFile(const std::string& saveDirectory, const std::string& filename)
{
std::filesystem::path filePath = GetFilePath(saveDirectory, filename);

std::map<std::string, CameraSnapshot> pathCopy;
for (auto& i : *currentPath)
{
pathCopy.insert_or_assign(std::to_string(i.first), i.second);
}
json j = pathCopy;
std::ofstream myfile;
myfile.open(filename);
std::ofstream myfile(filePath);
myfile << j.dump(4);
myfile.close();
}

void DollyCam::LoadFromFile(std::string filename)
bool DollyCam::LoadFromFile(const std::string& loadDirectory, const std::string& filename)
{
std::ifstream i(filename);
std::filesystem::path filePath = GetFilePath(loadDirectory, filename);
if (!std::filesystem::exists(filePath))
{
cvarManager->log("File does not exist!");
return false;
}

std::ifstream i(filePath);
json j;
i >> j;
currentPath->clear();
Expand All @@ -454,6 +462,23 @@ void DollyCam::LoadFromFile(std::string filename)

this->RefreshInterpData();
this->RefreshInterpDataRotation();

return true;
}

std::filesystem::path DollyCam::GetFilePath(const std::string& loadDirectory, const std::string& filename)
{
std::filesystem::path Output = loadDirectory;

if(loadDirectory.empty())
{
Output = gameWrapper->GetDataFolder() / "campaths";
}

//Append filename to path using directory separator
Output /= filename;

return Output;
}

std::shared_ptr<savetype> DollyCam::GetCurrentPath()
Expand Down
6 changes: 4 additions & 2 deletions DollyCamPlugin2/dollycam.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once
#include <memory>
#include <map>
#include <filesystem>
#include "utils\customrotator.h"
#include "bakkesmod\plugin\bakkesmodplugin.h"
#include "gameapplier.h"
Expand Down Expand Up @@ -50,8 +51,9 @@ class DollyCam
void RefreshInterpDataRotation();
std::string GetInterpolationMethod(bool locationInterp);
std::shared_ptr<InterpStrategy> CreateInterpStrategy(int interpStrategy);
void SaveToFile(std::string filename);
void LoadFromFile(std::string filename);
void SaveToFile(const std::string& saveDirectory, const std::string& filename);
bool LoadFromFile(const std::string& loadDirectory, const std::string& filename);
std::filesystem::path GetFilePath(const std::string& loadDirectory, const std::string& filename);
std::shared_ptr<savetype> GetCurrentPath();
void SetCurrentPath(std::shared_ptr<savetype> newPath);
};
Expand Down
13 changes: 5 additions & 8 deletions DollyCamPlugin2/dollycamplugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ void DollyCamPlugin::onLoad()
cvarManager->registerCvar("dolly_interpmode_rotation", "5", "Used interp mode for rotation", true, true, 0, true, 2000)
.addOnValueChanged(bind(&DollyCamPlugin::OnInterpModeChanged, this, _1, _2));

pathDirectory = std::make_shared<std::string>("");
cvarManager->registerCvar("dolly_path_directory", "", "Location for saving and loading paths", true).bindTo(pathDirectory);

cvarManager->registerCvar("dolly_render", "1", "Render the current camera path", true, true, 0, true, 1).bindTo(renderCameraPath);

Expand Down Expand Up @@ -79,7 +81,7 @@ void DollyCamPlugin::onLoad()

cvarManager->registerNotifier("dolly_bezier_weight", bind(&DollyCamPlugin::OnBezierCommand, this, _1), "Change bezier weight of given snapshot (Unsupported?). Usage: dolly_bezier_weight", PERMISSION_ALL);
cvarManager->registerCvar("dolly_chaikin_degree", "0", "Amount of times to apply chaikin to the spline", true, true, 0, true, 20).addOnValueChanged(bind(&DollyCamPlugin::OnChaikinChanged, this, _1, _2));;
cvarManager->registerCvar("dolly_spline_acc", "1000", "Spline interpolation time accuracy", true, true, 100, false);
cvarManager->registerCvar("dolly_spline_acc", "7500", "Spline interpolation time accuracy", true, true, 100, false);
dollyCam->SetRenderPath(true);
}

Expand Down Expand Up @@ -133,7 +135,7 @@ void DollyCamPlugin::OnAllCommand(std::vector<std::string> params)
return;
}
std::string filename = params.at(1);
dollyCam->SaveToFile(filename);
dollyCam->SaveToFile(*pathDirectory, filename);
}
else if (command.compare("dolly_path_load") == 0)
{
Expand All @@ -143,12 +145,7 @@ void DollyCamPlugin::OnAllCommand(std::vector<std::string> params)
return;
}
std::string filename = params.at(1);
if (!file_exists(filename))
{
cvarManager->log("File does not exist!");
return;
}
dollyCam->LoadFromFile(filename);
dollyCam->LoadFromFile(*pathDirectory, filename);
}
}

Expand Down
1 change: 1 addition & 0 deletions DollyCamPlugin2/dollycamplugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ class DollyCamPlugin : public BakkesMod::Plugin::BakkesModPlugin, public BakkesM
private:
std::shared_ptr<DollyCam> dollyCam;
std::shared_ptr<bool> renderCameraPath;
std::shared_ptr<std::string> pathDirectory;
CameraSnapshot selectedSnapshot;
bool IsApplicable();

Expand Down

0 comments on commit c98e272

Please sign in to comment.