Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ; main.ahk
- ; by Aporokizzu
- ; 2023.03.02
- #Include "Yaml.ahk"
- strStripCrlf(str) {
- str := RegExReplace(str, "`n")
- str := RegExReplace(str, "`r")
- return str
- }
- writeFile(data, fn) {
- fn := strStripCrlf(fn)
- f := FileOpen(fn, "w")
- f.Write(data)
- f.Close()
- }
- class JsonShine {
- __New(jsonFile) {
- this._ready := false
- this._needsExtraFudging := false
- this.__setup(jsonFile)
- }
- __STR_JSON_HLPROBJ_NAME() {
- retVal := "funky_cold_medina"
- return retVal
- }
- __STR_TRUE(addQuotes := true) {
- retVal := "-*-vrai-*-"
- if (addQuotes) {
- retVal := '"' retVal '"'
- }
- return retVal
- }
- __STR_FALSE(addQuotes := true) {
- retVal := "-*-faux-*-"
- if (addQuotes) {
- retVal := '"' retVal '"'
- }
- return retVal
- }
- __STR_NULL(addQuotes := true) {
- retVal := "-*-null-*-"
- if (addQuotes) {
- retVal := '"' retVal '"'
- }
- return retVal
- }
- __setup(jsonFile) {
- checkJson := FileExist(jsonFile)
- if (!checkJson) {
- Return
- }
- this._fullPath := jsonFile
- SplitPath(this._fullPath, &justFn, &justDir)
- this._fileName := justFn
- this._folderName := justDir
- rawData := FileRead(this._fullPath)
- this._needsExtraFudging := this.__isArrayJson(rawData)
- rawData := this.__fudgeJson(rawData)
- this._data := Yaml(rawData)
- this._ready := true
- }
- __isArrayJson(data) {
- firstChar := SubStr(data, 1, 1)
- if (firstChar = "[") {
- return True
- }
- return False
- }
- __fudgeJson(data) {
- if (this._needsExtraFudging) {
- data := '{"' this.__STR_JSON_HLPROBJ_NAME() '":' data '}'
- }
- data := StrReplace(data, "true", this.__STR_TRUE())
- data := StrReplace(data, "false", this.__STR_FALSE())
- data := StrReplace(data, "null", this.__STR_NULL())
- return data
- }
- __unfudgeJson(data) {
- if (this._needsExtraFudging) {
- startPos := (InStr(data, this.__STR_NULL()) - 2)
- dataLen := (StrLen(data) - (startPos + 1))
- data := SubStr(data, startPos, dataLen)
- }
- data := StrReplace(data, this.__STR_TRUE(), "true")
- data := StrReplace(data, this.__STR_FALSE(), "false")
- data := StrReplace(data, this.__STR_NULL(), "null")
- return data
- }
- __writeFullPath(data, fullPath := this._fullPath) {
- if (this._needsExtraFudging) {
- data := "[`n" data "`n]"
- }
- writeFile(data, fullPath)
- }
- data() {
- if (this._needsExtraFudging) {
- return (this._data[this.__STR_JSON_HLPROBJ_NAME()])
- }
- return (this._data)
- }
- dump() {
- if (this._ready) {
- this.__polish()
- data := Yaml(this.data(), -69)
- data := this.__unfudgeJson(data)
- this.__writeFullPath(data)
- }
- }
- __polish() {
- ; TO BE OVERWRITTEN
- }
- }
- class ClassesJson extends JsonShine {
- dataParams(idx := 2) {
- return this.data()[idx]["params"]
- }
- __genParam(leadSeqArr := [], pttrnArr := [], loopLen := 99) {
- retVal := []
- leadSeqArrLen := leadSeqArr.Length
- pttrnArrLen := pttrnArr.Length
- if ((leadSeqArrLen != 0) and (pttrnArrLen != 0)) {
- retVal := leadSeqArr
- remainingCharsInParamSeq := ((loopLen - leadSeqArrLen) - 1)
- count := 0
- currentChar := Ceil(leadSeqArr[leadSeqArrLen])
- Loop remainingCharsInParamSeq {
- count += 1
- additive := Ceil(pttrnArr[count])
- currentChar += additive
- retVal.Push((Ceil(currentChar) + 0))
- if (count = pttrnArrLen) {
- count := 0
- }
- }
- }
- return retVal
- }
- __polish() {
- this.data().Capacity := 2
- setDataParam(idx, leadSeq, pttrn) {
- paramLen := this.dataParams(2)[idx].Length
- param := this.__genParam(leadSeq, pttrn, paramLen)
- paramLen := param.Length
- this.dataParams(2)[idx] := []
- Loop paramLen {
- currentItem := (param[A_Index] + 0)
- this.dataParams(2)[idx].push(currentItem)
- }
- }
- setDataParam(1, [1, 8], [8])
- setDataParam(2, [0, 128], [0])
- setDataParam(3, [1, 16], [2, 1, 1, 1])
- setDataParam(4, [0, 32], [3, 2])
- }
- }
- class Main {
- __New(jsonFile) {
- this._jsonSrc := jsonFile
- }
- run() {
- clsssJson := ClassesJson(this._jsonSrc)
- clsssJson.dump()
- }
- }
- jsonFn := A_ScriptDir "\" "Classes.json"
- App := Main(jsonFn)
- App.run()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement