[SFF, WIP] Started SFF writer

This commit is contained in:
dpeter99 2022-06-13 13:37:18 +02:00
parent ee7ef58862
commit b4d27c8b39
8 changed files with 141 additions and 7 deletions

View File

@ -4,7 +4,7 @@ on:
push: push:
branches: [ main ] branches: [ main ]
paths-ignore: paths-ignore:
- 'docs/**' - 'projs/docs/**'
- 'specs/**' - 'specs/**'
jobs: jobs:

View File

View File

@ -0,0 +1,61 @@
#include "pch.h"
import Shadow.FileFormat;
std::string example_empty = "ShadowFileFormat_1_0_0";
std::string example_simple = "ShadowFileFormat_1_0_0 \n\
Assets:{ \
9:Content_9, \
10 : Content_10, \
11: Content_11, \
}, \
";
std::string example_multi_root =
"ShadowFileFormat_1_0_0 \n \
Assets:{ \
9:Content_9, \
}, \
Texture:{ \
texture:checker_board.png, \
}, \
";
std::string example_multi_level = "ShadowFileFormat_1_0_0 \n\
Assets:{ \
9: { \
\
}, \
}, \
";
std::string example_multi_level_content = "ShadowFileFormat_1_0_0 \n\
Assets:{ \
a: { \
0: ContentContent0, \
1: ContentContent1, \
2: ContentContent2, \
}, \
b: ContentB, \
}, \
";
std::stringstream streamFrom(std::string str) {
std::stringstream ss;
ss << str;
return ss;
}
TEST(EmptyFile, HasHeader) {
std::stringstream ss = streamFrom(example_empty);
//auto a = Shadow::SFF::SFFWriter::
//auto assets = a->GetChildByIndex(0);
//EXPECT_EQ(assets, nullptr);
}

View File

@ -21,6 +21,7 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClCompile Include="test.cpp" /> <ClCompile Include="test.cpp" />
<ClCompile Include="sff_writer_tests.cpp" />
<ClCompile Include="pch.cpp"> <ClCompile Include="pch.cpp">
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Create</PrecompiledHeader> <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Create</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Create</PrecompiledHeader> <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Create</PrecompiledHeader>

View File

@ -1,6 +1,10 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ImportGroup Label="PropertySheets">
<Import Project="../../Umbra.CPP.props" /> <Import Project="../../Umbra.CPP.props" />
</ImportGroup>
<PropertyGroup Label="Globals"> <PropertyGroup Label="Globals">
<VCProjectVersion>15.0</VCProjectVersion> <VCProjectVersion>15.0</VCProjectVersion>
<ProjectGuid>{B2E3515C-3FE0-44B9-9ABE-8584A836230F}</ProjectGuid> <ProjectGuid>{B2E3515C-3FE0-44B9-9ABE-8584A836230F}</ProjectGuid>
@ -24,8 +28,9 @@
</ClCompile> </ClCompile>
</ItemDefinitionGroup> </ItemDefinitionGroup>
<ItemGroup> <ItemGroup>
<ClCompile Include="src/SFFElement.cpp" /> <ClCompile Include="src/SFFWriter.ixx" />
<ClCompile Include="src/SFFParser.cpp" /> <!--<ClCompile Include="src/SFFElement.cpp" />-->
<!--<ClCompile Include="src/SFFParser.cpp" />-->
<ClCompile Include="src/SFFElement.ixx" /> <ClCompile Include="src/SFFElement.ixx" />
<ClCompile Include="src/Shadow.FileFormat.ixx" /> <ClCompile Include="src/Shadow.FileFormat.ixx" />
<ClCompile Include="src/SFFParser.ixx" /> <ClCompile Include="src/SFFParser.ixx" />

View File

@ -18,9 +18,6 @@
<ClCompile Include="src\SFFParser.cpp"> <ClCompile Include="src\SFFParser.cpp">
<Filter>Source Files</Filter> <Filter>Source Files</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="src/**/*.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="src/SFFElement.cpp"> <ClCompile Include="src/SFFElement.cpp">
<Filter>Source Files</Filter> <Filter>Source Files</Filter>
</ClCompile> </ClCompile>
@ -31,6 +28,7 @@
<ClCompile Include="src/Shadow.FileFormat.ixx" /> <ClCompile Include="src/Shadow.FileFormat.ixx" />
<ClCompile Include="src/SFFParser.ixx" /> <ClCompile Include="src/SFFParser.ixx" />
<ClCompile Include="src/SFFVersion.ixx" /> <ClCompile Include="src/SFFVersion.ixx" />
<ClCompile Include="SFFWriter.ixx" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClInclude Include="src/**/*.h"> <ClInclude Include="src/**/*.h">

View File

@ -0,0 +1,68 @@
module;
//#include <iostream>;
//#include <fstream>;
export module Shadow.FileFormat:SFFWriter;
import <string>;
import <iostream>;
import <fstream>;
import shadow_utils;
import :SFFElement;
import :SFFVersion;
namespace Shadow::SFF {
export class SFFParser
{
public:
static void WriteFile(SFFElement& root, std::string path)
{
std::ofstream writer(path);
writer << "ShadowFileFormat_1_0_0" << std::endl;
int depth = 0;
WriteElement(writer, root, depth);
writer.flush();
}
static void WriteElement(std::ostream& w, SFFElement& e, int &depth)
{
std::string head = (e.name + (e.isBlock ? ":{" : ":"));
//head = head.PadLeft(depth + head.Length, '\t');
head.insert(head.begin(), depth, '\t');
w << head << std::endl;
if (e.isBlock)
{
depth += 1;
w << std::endl;
for(auto& prop : e.properties)
{
WriteElement(w, prop.Value, depth);
}
std::string close = "}";
close.insert(head.begin(), depth, '\t');
w << close;
depth -= 1;
}
else
{
w << e.value << ",";
}
}
};
}

View File

@ -2,4 +2,5 @@ export module Shadow.FileFormat;
export import :SFFElement; export import :SFFElement;
export import :SFFParser; export import :SFFParser;
export import :SFFWriter;
export import :SFFVersion; export import :SFFVersion;