YAML Reader
By
waterquarksCreated: 2018/11/15 05:44:43 UTC-08:00 (6 years and 39 days ago)
Edited: 2018/11/23 11:27:31 UTC-08:00 (6 years and 31 days ago)
Likes: 0
Denizen Version: 1.0.3
Script Version: 1.0
Description:
BlackCoyote's in game YAML viewer (https://one.denizenscript.com/denizen/repo/entry/95) revamped!
Displays the entries of a YAML file in chat (or in the console), taking full advantage of sorting tags in order to do it in only one queue!
Added:
- Tab completion.
- Thorough validations.
- Formatting (lists are now displayed neatly, in a multi-line format).
- Efficiently encapsulated the code in one script container!
Download script |
View raw scriptreadYAML:
type: command
debug: false
name: readyaml
description: Shows the entries of a YAML file in chat.
usage: /readyaml <<>yamlID<>>
tab complete:
- define yamlList "<yaml.list>"
- if "<def[yamlList].is_empty>":
- determine li@
- if "<c.args.size>" > "1":
- determine li@
- define yamlID "<c.args.get[1]||>"
- determine "<def[yamlList].filter[starts_with[<def[yamlID]>]]>"
script:
- define yamlList "<yaml.list>"
- if "<def[yamlList].is_empty>":
- narrate "<&6>There are no YAML files loaded."
- queue clear
- define yamlID "<c.args.get[1]||null>"
- if "<def[yamlID]>" == null:
- narrate "<&6>Specify the ID of the file you wish to view."
- narrate "<&6>Usage<&co> <&c><&dq>/readyaml <<>yamlID<>><&dq><&6>."
- queue clear
- if "<def[yamlList].contains[<def[yamlID]>].not>":
- narrate "<&6>There is no loaded file by the name of <&c><&dq><def[yamlID]><&dq><&6>."
- queue clear
- define keys "<yaml[<def[yamlID]>].list_keys[]>"
- if "<def[keys].is_empty>":
- narrate "<&6>The file specified exists, but is empty."
- queue clear
- define deep_keys "<yaml[<def[yamlID]>].list_deep_keys[]>"
- foreach "<def[keys]>":
- define key "<def[value]>"
- define subkeys "<def[deep_keys].filter[starts_with[<def[value]>]]>"
- define subkeys "<def[subkeys].sort_by_number[split_by[.].size]>"
- foreach "<def[subkeys]>":
- define subkey "<def[value]>"
- define sp "<el@.pad_left[<def[subkey].split_by[.].size.sub[1].mul[2]>]>"
- define subkey_formatted "<def[subkey]>"
- if "<def[subkey].contains[.]>":
- define subkey_formatted "<def[subkey].after_last[.]>"
- define aux "<def[subkeys].filter[starts_with[<def[subkey]>]]>"
- define aux "<def[aux].filter[to_list.count[.].is[MORE].than[<def[subkey].to_list.count[.]>]]>"
- if "<def[aux].size>" > "1":
- narrate "<def[sp]><&a><def[subkey_formatted]><&co>"
- else:
- define value "<yaml[<def[yamlID]>].read[<def[subkey]>]>"
- if "<def[value].type>" == "List":
- narrate "<def[sp]><&a><def[subkey_formatted]><&co>"
- foreach "<def[value]>":
- narrate "<def[sp]> <&7>- <&f><def[value]>"
- else:
- narrate "<def[sp]><&a><def[subkey_formatted]><&co> <&f><def[value]>"
View History