Update the code in 0.0.1alpha

for basic usage in C and Julia with 2 files
This commit is contained in:
hypergraphUniverse 2022-03-07 11:07:16 +01:00
parent d9c731666c
commit 2e6010b2fb
3 changed files with 73 additions and 6 deletions

3
.gitignore vendored
View File

@ -1 +1,2 @@
*.json
*.json
*.txt

View File

@ -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

42
Main.jl Normal file
View File

@ -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