Update the code in 0.0.1alpha
for basic usage in C and Julia with 2 files
This commit is contained in:
parent
d9c731666c
commit
2e6010b2fb
3
.gitignore
vendored
3
.gitignore
vendored
@ -1 +1,2 @@
|
|||||||
*.json
|
*.json
|
||||||
|
*.txt
|
@ -2,8 +2,9 @@
|
|||||||
# Specified for Genshin Impact, Types are Float32
|
# Specified for Genshin Impact, Types are Float32
|
||||||
|
|
||||||
module FileCodeOutput
|
module FileCodeOutput
|
||||||
|
using Dates
|
||||||
|
|
||||||
export Print2DMatrix,Print3DMatrix
|
export Print2DMatrix,Print3DMatrix,PrintScriptVersion
|
||||||
|
|
||||||
# syntax dictionary
|
# syntax dictionary
|
||||||
dictLanguage=Dict(
|
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 to print 2D Data
|
||||||
function Print2DMatrix(f,M;tabLen=0,varName="",codeStyle="C")
|
function Print2DMatrix(f,M;tabLen=0,varName="",codeStyle="C")
|
||||||
global dictLanguage
|
global dictLanguage
|
||||||
|
|
||||||
# print variableName if needed
|
# print variableName if needed
|
||||||
if varName!=""
|
if varName!=""
|
||||||
print(f,varName);
|
|
||||||
if codeStyle=="C"
|
if codeStyle=="C"
|
||||||
|
print(f, "float "*varName);
|
||||||
for i in 1:length(size(M))
|
for i in 1:length(size(M))
|
||||||
print(f,"["*string(size(M)[i])*"]");
|
print(f,"["*string(size(M)[i])*"]");
|
||||||
end
|
end
|
||||||
|
print(f,"=");
|
||||||
|
|
||||||
|
elseif codeStyle=="Julia"
|
||||||
|
print(f,varName*"=");
|
||||||
|
|
||||||
|
else
|
||||||
|
error("Keyword codeStyle unsupported!")
|
||||||
end
|
end
|
||||||
print(f,"=\n");
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# print the mainpart of 2D Matrix
|
# print the mainpart of 2D Matrix
|
||||||
@ -68,13 +84,19 @@ function Print3DMatrix(f,M;tabLen=0,varName="",codeStyle="C")
|
|||||||
|
|
||||||
# print variableName if needed
|
# print variableName if needed
|
||||||
if varName!=""
|
if varName!=""
|
||||||
print(f,varName);
|
|
||||||
if codeStyle=="C"
|
if codeStyle=="C"
|
||||||
|
print(f, "float "*varName);
|
||||||
for i in 1:length(size(M))
|
for i in 1:length(size(M))
|
||||||
print(f,"["*string(size(M)[i])*"]");
|
print(f,"["*string(size(M)[i])*"]");
|
||||||
end
|
end
|
||||||
|
print(f,"=");
|
||||||
|
|
||||||
|
elseif codeStyle=="Julia"
|
||||||
|
print(f,varName*"=");
|
||||||
|
|
||||||
|
else
|
||||||
|
error("Keyword codeStyle unsupported!")
|
||||||
end
|
end
|
||||||
print(f,"=");
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# print the main part in different codeStyle
|
# 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")
|
Print2DMatrix(f,M[i,:,:];tabLen=tabLen+1,codeStyle="C")
|
||||||
end
|
end
|
||||||
print(f,"}");
|
print(f,"}");
|
||||||
|
|
||||||
elseif codeStyle=="Julia"
|
elseif codeStyle=="Julia"
|
||||||
print("Array{Float32,3}(undef,"*string(size(M)[1])*","*string(size(M)[2])*","*string(size(M)[3])*");\n");
|
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]
|
for i in 1:size(M)[1]
|
||||||
Print2DMatrix(f,M[i,:,:];varName=varName*"["*string(i)*",:,:]",codeStyle="Julia");
|
Print2DMatrix(f,M[i,:,:];varName=varName*"["*string(i)*",:,:]",codeStyle="Julia");
|
||||||
end
|
end
|
||||||
|
|
||||||
else
|
else
|
||||||
error("Keyword codeStyle unsupported!")
|
error("Keyword codeStyle unsupported!")
|
||||||
end
|
end
|
||||||
|
42
Main.jl
Normal file
42
Main.jl
Normal 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
|
Loading…
Reference in New Issue
Block a user