2022-03-07 09:08:54 +00:00
|
|
|
# This is the Module for Code output in different style
|
|
|
|
# Specified for Genshin Impact, Types are Float32
|
|
|
|
|
|
|
|
module FileCodeOutput
|
2022-03-07 10:07:16 +00:00
|
|
|
using Dates
|
2022-03-07 09:08:54 +00:00
|
|
|
|
2022-03-07 10:07:16 +00:00
|
|
|
export Print2DMatrix,Print3DMatrix,PrintScriptVersion
|
2022-03-07 09:08:54 +00:00
|
|
|
|
|
|
|
# syntax dictionary
|
|
|
|
dictLanguage=Dict(
|
|
|
|
"C"=>Dict(
|
|
|
|
"termsuffix"=> "f",
|
|
|
|
"termSplitter" => ", ",
|
|
|
|
"lineStart" => "{",
|
|
|
|
"lineEnd" => "},",
|
|
|
|
"matrixStart" => "{",
|
|
|
|
"matrixEnd" => "}",
|
|
|
|
"comment" => "//",
|
|
|
|
"terminator" => ";",
|
|
|
|
),
|
|
|
|
"Julia"=>Dict(
|
|
|
|
"termsuffix" => "f0",
|
|
|
|
"termSplitter" => " ",
|
|
|
|
"lineStart" => "",
|
|
|
|
"lineEnd" => ";",
|
|
|
|
"matrixStart" => "[",
|
|
|
|
"matrixEnd" => "]",
|
|
|
|
"comment" => "#",
|
|
|
|
"terminator" => ";",
|
|
|
|
),
|
|
|
|
);
|
|
|
|
|
2022-03-07 10:07:16 +00:00
|
|
|
# Function to print Basic infomation
|
|
|
|
function PrintScriptVersion(f,s::String,v::String;codeStyle="C")
|
|
|
|
print(f,dictLanguage[codeStyle]["comment"]*" This is a piece of code generated by hypergraph\\GenshinDataConverter\n");
|
|
|
|
print(f,dictLanguage[codeStyle]["comment"]*" Code Style: "*codeStyle*"\n");
|
|
|
|
print(f,dictLanguage[codeStyle]["comment"]*" Script Version: "*s*"\n");
|
|
|
|
print(f,dictLanguage[codeStyle]["comment"]*" Your Version: "*v*"\n");
|
|
|
|
print(f,dictLanguage[codeStyle]["comment"]*" Time of Code Generation: "*Dates.format(now(), "yyyy-mm-dd HH:MM")*"\n");
|
|
|
|
end
|
|
|
|
|
2022-03-07 09:08:54 +00:00
|
|
|
# Function to print 2D Data
|
|
|
|
function Print2DMatrix(f,M;tabLen=0,varName="",codeStyle="C")
|
|
|
|
global dictLanguage
|
|
|
|
|
|
|
|
# print variableName if needed
|
|
|
|
if varName!=""
|
|
|
|
if codeStyle=="C"
|
2022-03-07 10:07:16 +00:00
|
|
|
print(f, "float "*varName);
|
2022-03-07 09:08:54 +00:00
|
|
|
for i in 1:length(size(M))
|
|
|
|
print(f,"["*string(size(M)[i])*"]");
|
|
|
|
end
|
2022-03-07 10:07:16 +00:00
|
|
|
print(f,"=");
|
|
|
|
|
|
|
|
elseif codeStyle=="Julia"
|
|
|
|
print(f,varName*"=");
|
|
|
|
|
|
|
|
else
|
|
|
|
error("Keyword codeStyle unsupported!")
|
2022-03-07 09:08:54 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# print the mainpart of 2D Matrix
|
|
|
|
print(f, repeat(" ",tabLen*4) * dictLanguage[codeStyle]["matrixStart"] * "\n");
|
|
|
|
for i in 1:size(M)[1]
|
|
|
|
print(f, repeat(" ", (tabLen+1)*4) * dictLanguage[codeStyle]["lineStart"]);
|
|
|
|
for j in 1:size(M)[2]
|
|
|
|
print(f, string(M[i,j]) * dictLanguage[codeStyle]["termsuffix"] * dictLanguage[codeStyle]["termSplitter"]);
|
|
|
|
end
|
|
|
|
print(f, dictLanguage[codeStyle]["lineEnd"] * "\n");
|
|
|
|
end
|
|
|
|
print(f, repeat(" ",tabLen*4) * dictLanguage[codeStyle]["matrixEnd"]);
|
|
|
|
|
|
|
|
# print Terminator
|
|
|
|
(varName!="")&&print(f, dictLanguage[codeStyle]["terminator"]);
|
|
|
|
(varName=="")&&print(f, dictLanguage[codeStyle]["termSplitter"]);
|
|
|
|
print(f,"\n");
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
# Function to print 3D Data
|
|
|
|
function Print3DMatrix(f,M;tabLen=0,varName="",codeStyle="C")
|
|
|
|
global dictlanguage
|
|
|
|
|
|
|
|
# print variableName if needed
|
|
|
|
if varName!=""
|
|
|
|
if codeStyle=="C"
|
2022-03-07 10:07:16 +00:00
|
|
|
print(f, "float "*varName);
|
2022-03-07 09:08:54 +00:00
|
|
|
for i in 1:length(size(M))
|
|
|
|
print(f,"["*string(size(M)[i])*"]");
|
|
|
|
end
|
2022-03-07 10:07:16 +00:00
|
|
|
print(f,"=");
|
|
|
|
|
|
|
|
elseif codeStyle=="Julia"
|
|
|
|
print(f,varName*"=");
|
|
|
|
|
|
|
|
else
|
|
|
|
error("Keyword codeStyle unsupported!")
|
2022-03-07 09:08:54 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# print the main part in different codeStyle
|
|
|
|
if codeStyle=="C"
|
|
|
|
print(f,"\n");
|
|
|
|
print(f,repeat(" ",tabLen*4) * "{\n");
|
|
|
|
for i in 1:size(M)[1]
|
|
|
|
Print2DMatrix(f,M[i,:,:];tabLen=tabLen+1,codeStyle="C")
|
|
|
|
end
|
|
|
|
print(f,"}");
|
2022-03-07 10:07:16 +00:00
|
|
|
|
2022-03-07 09:08:54 +00:00
|
|
|
elseif codeStyle=="Julia"
|
2022-03-07 10:22:00 +00:00
|
|
|
print(f,"fill(0f0,"*string(size(M)[1])*","*string(size(M)[2])*","*string(size(M)[3])*");\n");
|
2022-03-07 09:08:54 +00:00
|
|
|
for i in 1:size(M)[1]
|
|
|
|
Print2DMatrix(f,M[i,:,:];varName=varName*"["*string(i)*",:,:]",codeStyle="Julia");
|
|
|
|
end
|
2022-03-07 10:07:16 +00:00
|
|
|
|
2022-03-07 09:08:54 +00:00
|
|
|
else
|
|
|
|
error("Keyword codeStyle unsupported!")
|
|
|
|
end
|
|
|
|
|
|
|
|
# print Terminator
|
|
|
|
(varName!="")&&(codeStyle=="C")&&print(f, dictLanguage[codeStyle]["terminator"]);
|
|
|
|
print(f,"\n");
|
|
|
|
end
|
|
|
|
|
|
|
|
# Function to print a Sturcture/Dictionary or such
|
|
|
|
# function PrintDict()
|
|
|
|
# end
|
|
|
|
|
|
|
|
end
|
|
|
|
|