- D1 Meta Docs - Denizen Script -
Home Page / Pi to one million places / Contact mcmonkey / Donate / Paste Scripts / Denizen Help /
You are browsing as a guest.
Login | Register








The script repo is an archive of historical scripts. For modern scripts, or to post your own, please use the Scripts forum section.





YAML Reader


By waterquarks
Created: 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 script
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
5700

readYAML:
  type: command
  debug: false
  name: readyaml
  description: Shows the entries of a YAML file in chat.
  usage: /readyaml <&lt>yamlID<&gt>
  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 <&lt>yamlID<&gt><&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