global.gd 593 B

1234567891011121314151617181920212223242526
  1. extends Node
  2. var fish_species = []
  3. func _ready():
  4. var fish_species_json = load_json_file("res://data/fish_species.json")
  5. if (fish_species_json != null):
  6. fish_species = fish_species_json["fish_species_list"]
  7. func load_json_file(path):
  8. var file = File.new()
  9. if (file.open(path, file.READ) != OK):
  10. return
  11. var text = file.get_as_text()
  12. var data_parse = JSON.parse(text)
  13. if (data_parse.error != OK):
  14. return
  15. var data = data_parse.result
  16. return data
  17. func get_fish_species(species_id):
  18. for fish in fish_species:
  19. if (species_id == fish["species_id"]):
  20. return fish
  21. return null