Advertisement
reapersremorse

SaveJson_SavesWrongData

Jan 20th, 2022
36
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. extends Control
  2. """
  3. This project is a literal json generator. it creates .json files with the given names.
  4.  
  5. its ment to help minecraft devs or devs for other games.
  6.  
  7. ill be setting this up to be an all purpose all file type generation program
  8.  
  9. Current plans: Generate jsons and logs
  10.  
  11. Future: Generate .txt, .png, .gltf(Based off of an in app 3D custom editor im working on.)
  12. and basically anything else that devs may need or need placeholders for.
  13.  
  14. """
  15.  
  16.  
  17. var popup
  18. #var HasSave = false
  19.  
  20. onready var NewName
  21. onready var PATH = "user://jsons/"
  22. onready var thing_to_save = {
  23.     "parent": "minecraft:item/generated",
  24.     "textures": {
  25.         "layer0": "minecraft:item/"+str(NewName)
  26.         }
  27. }
  28.  
  29. onready var BG = $BG
  30. onready var FILE = $V/H6/FileFile
  31. onready var CUSTOMIZATION = $V/H6/Customization
  32. onready var HELPCREDITS = $V/H6/HelpAndCredits
  33.  
  34. onready var PREFIX = $V/H2/PREFIX_Edit
  35. onready var NAME = $V/H3/NAME_Edit
  36. onready var SUFFIX = $V/H4/SUFFIX_Edit
  37.  
  38. onready var AllNames:Array = []
  39. var Count = 0
  40.  
  41.  
  42. func csv_to_array(csv):
  43.     var array = []
  44.     var item = ""
  45.     for i in csv:
  46.         if i == " ":
  47.             continue
  48.         if i == ",":
  49.             array.append(item)
  50.             item = ""
  51.         else:
  52.             item += str(i)
  53.     array.append(item)
  54.     return array
  55.  
  56. func _ready():
  57.     var dir = Directory.new()
  58.     dir.open("user://")
  59.     dir.make_dir("jsons")
  60.     var NewDir = "user://jsons"
  61.    
  62.     var prefix_csv = $V/H2/PREFIX_Edit.text.replace(" ","_").replace("\n",",").replace(",,",",")
  63.     var adjective_csv = $V/H3/NAME_Edit.text.replace(" ","_").replace("\n",",").replace(",,",",")
  64.     var suffix_csv = $V/H4/SUFFIX_Edit.text.replace(" ","_").replace("\n",",").replace(",,",",")
  65.  
  66.  
  67.     var prefix = csv_to_array(prefix_csv)
  68.     var adjective = csv_to_array(adjective_csv)
  69.     var suffix = csv_to_array(suffix_csv)
  70.  
  71.     for p in prefix:
  72.         for a in adjective:
  73.             for s in suffix:
  74.                 NewName = p+"_"+a+"_"+s
  75.                 Save(PATH,NewName,thing_to_save)
  76.                 print(NewName)
  77.  
  78.  
  79. func _on_Start_confirmed() -> void:
  80.     Configs.HasSave = true
  81.  
  82. func Save(PATH : String,NewName, thing_to_save):
  83.     var file = File.new()
  84.     file.open(PATH+NewName+".json", File.WRITE)
  85.     file.store_var(to_json(thing_to_save))
  86.     file.close()
  87.  
  88.  
  89. #Load needs some work
  90. func Load (PATH:String) -> Dictionary:
  91.     var file = File.new()
  92.     file.open(PATH, File.READ)
  93.     var theDict = file.get_var()
  94.     file.close()
  95.     return theDict
  96.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement