From 2e6010b2fbd097ce5ad042c7289e038a11b87d1f Mon Sep 17 00:00:00 2001 From: hypergraphUniverse <44737387+hypergraphUniverse@users.noreply.github.com> Date: Mon, 7 Mar 2022 11:07:16 +0100 Subject: [PATCH] Update the code in 0.0.1alpha for basic usage in C and Julia with 2 files --- .gitignore | 3 ++- FileCodeOutput.jl | 34 +++++++++++++++++++++++++++++----- Main.jl | 42 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 73 insertions(+), 6 deletions(-) create mode 100644 Main.jl diff --git a/.gitignore b/.gitignore index 94a2dd1..88428dd 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ -*.json \ No newline at end of file +*.json +*.txt \ No newline at end of file diff --git a/FileCodeOutput.jl b/FileCodeOutput.jl index d9cb3cc..46c090a 100644 --- a/FileCodeOutput.jl +++ b/FileCodeOutput.jl @@ -2,8 +2,9 @@ # Specified for Genshin Impact, Types are Float32 module FileCodeOutput +using Dates -export Print2DMatrix,Print3DMatrix +export Print2DMatrix,Print3DMatrix,PrintScriptVersion # syntax dictionary dictLanguage=Dict( @@ -29,19 +30,34 @@ dictLanguage=Dict( ), ); +# 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 + # Function to print 2D Data function Print2DMatrix(f,M;tabLen=0,varName="",codeStyle="C") global dictLanguage # print variableName if needed if varName!="" - print(f,varName); if codeStyle=="C" + print(f, "float "*varName); for i in 1:length(size(M)) print(f,"["*string(size(M)[i])*"]"); end + print(f,"="); + + elseif codeStyle=="Julia" + print(f,varName*"="); + + else + error("Keyword codeStyle unsupported!") end - print(f,"=\n"); end # print the mainpart of 2D Matrix @@ -68,13 +84,19 @@ function Print3DMatrix(f,M;tabLen=0,varName="",codeStyle="C") # print variableName if needed if varName!="" - print(f,varName); if codeStyle=="C" + print(f, "float "*varName); for i in 1:length(size(M)) print(f,"["*string(size(M)[i])*"]"); end + print(f,"="); + + elseif codeStyle=="Julia" + print(f,varName*"="); + + else + error("Keyword codeStyle unsupported!") end - print(f,"="); end # print the main part in different codeStyle @@ -85,11 +107,13 @@ function Print3DMatrix(f,M;tabLen=0,varName="",codeStyle="C") Print2DMatrix(f,M[i,:,:];tabLen=tabLen+1,codeStyle="C") end print(f,"}"); + elseif codeStyle=="Julia" print("Array{Float32,3}(undef,"*string(size(M)[1])*","*string(size(M)[2])*","*string(size(M)[3])*");\n"); for i in 1:size(M)[1] Print2DMatrix(f,M[i,:,:];varName=varName*"["*string(i)*",:,:]",codeStyle="Julia"); end + else error("Keyword codeStyle unsupported!") end diff --git a/Main.jl b/Main.jl new file mode 100644 index 0000000..9b73297 --- /dev/null +++ b/Main.jl @@ -0,0 +1,42 @@ +ScriptVersion = "0.0.1alpha" +# Very unstable alpha Version! + +# Locally include and use packages +if isdefined(@__MODULE__, :LookUpTable) + LookUpTable isa Module || error("LookUpTable is present and it is not a Module") +else + include("LookUpTable.jl") +end +using .LookUpTable + +if isdefined(@__MODULE__, :FileCodeOutput) + FileCodeOutput isa Module || error("FileCodeOutput is present and it is not a Module") +else + include("FileCodeOutput.jl") +end +using .FileCodeOutput + +if isdefined(@__MODULE__, :JSONPhraser) + JSONPhraser isa Module || error("JSONPhraser is present and it is not a Module") +else + include("JSONPhraser.jl") +end +using .JSONPhraser + +#=======================User configured Section==========================# +# Your Version Number +YourVersion= "0.1" + +# C(suitable for C and C++),Julia +codeStyle = "C" + +#=======================User configured Section==========================# + +M1=ReliAffixECDConverter(); +M2=ReliLevelECDConverter(); + +open("output.txt", "w") do file + PrintScriptVersion(file, ScriptVersion, YourVersion;codeStyle=codeStyle); + Print3DMatrix(file, M1 ; varName="reliSubstat",codeStyle=codeStyle); + Print3DMatrix(file, M2 ; varName="reliMainstat",codeStyle=codeStyle); +end \ No newline at end of file