From 945d3a2f03d9dfc48e18204cf98c8273c7b983f2 Mon Sep 17 00:00:00 2001 From: hypergraphUniverse <44737387+hypergraphUniverse@users.noreply.github.com> Date: Mon, 7 Mar 2022 10:08:54 +0100 Subject: [PATCH] initial commit of Modules --- .gitignore | 1 + FileCodeOutput.jl | 107 ++++++++++++++++++++++++++++++++++++++++++++++ JSONPhraser.jl | 86 +++++++++++++++++++++++++++++++++++++ LookUpTable.jl | 87 +++++++++++++++++++++++++++++++++++++ 4 files changed, 281 insertions(+) create mode 100644 .gitignore create mode 100644 FileCodeOutput.jl create mode 100644 JSONPhraser.jl create mode 100644 LookUpTable.jl diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..94a2dd1 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +*.json \ No newline at end of file diff --git a/FileCodeOutput.jl b/FileCodeOutput.jl new file mode 100644 index 0000000..d9cb3cc --- /dev/null +++ b/FileCodeOutput.jl @@ -0,0 +1,107 @@ +# This is the Module for Code output in different style +# Specified for Genshin Impact, Types are Float32 + +module FileCodeOutput + +export Print2DMatrix,Print3DMatrix + +# 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" => ";", + ), +); + +# 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" + for i in 1:length(size(M)) + print(f,"["*string(size(M)[i])*"]"); + end + end + print(f,"=\n"); + 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!="" + print(f,varName); + if codeStyle=="C" + for i in 1:length(size(M)) + print(f,"["*string(size(M)[i])*"]"); + end + end + print(f,"="); + 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,"}"); + 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 + + # 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 + diff --git a/JSONPhraser.jl b/JSONPhraser.jl new file mode 100644 index 0000000..570911f --- /dev/null +++ b/JSONPhraser.jl @@ -0,0 +1,86 @@ +# Convert json Data form Dimbreath/GenshinData into Matrix/Array + +module JSONPhraser +export ReliAffixECDConverter,ReliLevelECDConverter + +using JSON + +if isdefined(@__MODULE__, :LookUpTable) + VectorFunctions isa Module || error("LookUpTable is present and it is not a Module") +else + include("LookUpTable.jl") +end +using .LookUpTable + +# Convert ReliquaryAffixExcelConfigData.json into Matrix +# Substat of Artifacts +function ReliAffixECDConverter() + + # Read form JSON File + dict = Dict() + open("ReliquaryAffixExcelConfigData.json", "r") do f + dict=JSON.parse(f) # parse and transform data + end + + # Initialize with empty Array + # Rank, Substats, Sequence + dataSet=Array{Float32,3}(undef,5,length(LookUpTable.substatProject),4); + + # fill in the data + for i in 1:length(dict) + + # read ID for identification + this_id=string(dict[i]["Id"]); + this_rank=parse(Int64,this_id[1]); + this_seq=parse(Int64,this_id[6]); + # ID e.g. 501244 first digit is Rank, last digit is The Sequence Number in same substat + + # Skip the 9xxxxxx ID + if !(1<=this_rank<=5) + continue; + end + + # Skip the Substat not covered in LookUpTable.substatProject + if !SubstatHasKey(dict[i]["PropType"]) + continue; + end + + # Sort Data + dataSet[ this_rank, SubstatLookUp(dict[i]["PropType"]), this_seq ] = dict[i]["PropValue"]; + end + return dataSet +end + +# Convert ReliquaryLevelExcelConfigData.json into Matrix +# Mainstat of Artifacts +function ReliLevelECDConverter() + dict = Dict() + + # Read form JSON File + open("ReliquaryLevelExcelConfigData.json", "r") do f + dict=JSON.parse(f) # parse and transform data + end + + # Rank, Substats, Level + dataSet=Array{Float32,3}(undef,5,length(LookUpTable.mainstatProject),21); + + for i in 1:length(dict) + + # Skip the Data with no rank + if !(haskey(dict[i],"Rank")) + continue; + end + + # Sort Data + for j in 1:length(dict[i]["AddProps"]) + # Skip the Mainstat not covered in LookUpTable.mainstatProject + if !MainstatHasKey(dict[i]["AddProps"][j]["PropType"]) + continue; + end + dataSet[ dict[i]["Rank"], MainstatLookUp(dict[i]["AddProps"][j]["PropType"]), dict[i]["Level"] ] = dict[i]["AddProps"][j]["Value"]; + end + end + return dataSet +end + +end \ No newline at end of file diff --git a/LookUpTable.jl b/LookUpTable.jl new file mode 100644 index 0000000..bb094de --- /dev/null +++ b/LookUpTable.jl @@ -0,0 +1,87 @@ +module LookUpTable + +export SubstatHasKey,SubstatLookUp,MainstatHasKey,MainstatLookUp + +#=================user configured section===================# + +# Please add your output substat Sequence that you wish +substatProject=Dict( + "hp"=>1, + "hp_percent"=>2, + "attack"=>3, + "attack_percent"=>4, + "defence"=>5, + "defence_percent"=>6, + "charge_efficiency"=>7, + "element_mastery"=>8, + "critical"=>9, + "critical_hurt"=>10, +) + +# Please add your output mainstat Sequence that you wish +mainstatProject=Dict( + "hp"=>1, + "hp_percent"=>2, + "attack"=>3, + "attack_percent"=>4, + "defence"=>5, + "defence_percent"=>6, + "critical"=>7, + "critical_hurt"=>8, + "charge_efficiency"=>9, + "heal_add"=>10, + "element_mastery"=>11, + "fire_add_hurt"=>12, + "elec_add_hurt"=>13, + "water_add_hurt"=>14, + "wind_add_hurt"=>15, + "rock_add_hurt"=>16, + "ice_add_hurt"=>17, + "physical_add_hurt"=>18, +) + + +#==============end of user configured section===============# + +# constant look-up table + +statIntern=Dict( + "FIGHT_PROP_HP"=>"hp", + "FIGHT_PROP_HP_PERCENT"=>"hp_percent", + "FIGHT_PROP_ATTACK"=>"attack", + "FIGHT_PROP_ATTACK_PERCENT"=>"attack_percent", + "FIGHT_PROP_DEFENSE"=>"defence", + "FIGHT_PROP_DEFENSE_PERCENT"=>"defence_percent", + "FIGHT_PROP_CRITICAL"=>"critical", + "FIGHT_PROP_CRITICAL_HURT"=>"critical_hurt", + "FIGHT_PROP_CHARGE_EFFICIENCY"=>"charge_efficiency", + "FIGHT_PROP_HEAL_ADD"=>"heal_add", + "FIGHT_PROP_ELEMENT_MASTERY"=>"element_mastery", + "FIGHT_PROP_FIRE_ADD_HURT"=>"fire_add_hurt", + "FIGHT_PROP_ELEC_ADD_HURT"=>"elec_add_hurt", + "FIGHT_PROP_WATER_ADD_HURT"=>"water_add_hurt", + "FIGHT_PROP_WIND_ADD_HURT"=>"wind_add_hurt", + "FIGHT_PROP_ROCK_ADD_HURT"=>"rock_add_hurt", + "FIGHT_PROP_GRASS_ADD_HURT"=>"grass_add_hurt", + "FIGHT_PROP_ICE_ADD_HURT"=>"ice_add_hurt", + "FIGHT_PROP_PHYSICAL_ADD_HURT"=>"physical_add_hurt", + "FIGHT_PROP_FIRE_SUB_HURT"=>"fire_sub_hurt", +); + +function SubstatHasKey(s::String) + return haskey(substatProject,statIntern[s]) +end + +function SubstatLookUp(s::String) + return substatProject[statIntern[s]] +end + +function MainstatHasKey(s::String) + return haskey(mainstatProject,statIntern[s]) +end + +function MainstatLookUp(s::String) + return mainstatProject[statIntern[s]] +end + +end \ No newline at end of file