- 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


Click here to create your own public paste ~ ~ click to duplicate and edit this paste


TitleConfig File Generator Example
TypeDenizen Script
Date2014/05/22 19:11:04 UTC-07:00
ByGuest
Other
Paste
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
29100
################################################################################
#                                                                              #
# Configurations                                                               #
#                                                                              #
# These are the default configurations. They will be used to build the user    #
# level config files on first run. Each parent node defines the file type and  #
# the child nodes that follow are the configurations for that config file type.#
#                                                                              #
#______________________________________________________________________________#
#                                                                              #
#__________DO_NOT_EDIT_THIS_FILE___EVERYTHING_IS_CONFIGURABLE_IN_GAME__________#
#                                                                              #
#______________________________________________________________________________#

'ConfigFileGeneratorTest_Configurations':
  type: task
  debug: false

  # Where you save this script file
  scriptPath'scripts/Network/Utilities/ConfigFileGeneratorTest.yml'


# ------ Single Value Test Config ------ #

  singleValues:
    keyA: 1
    keyB: 0.1
    keyC: -1
    keyD: NaN
    keyE: This is a StRiNg!


# ------ Single Lists ------ #

  singleLists:
    listA:
      - 1
      - 0.1
      - -1
      - NaN
      - This is a StRiNg!
    listB:
      - 2
      - 0.2
      - -2
      - nAn
      - This is a sTrInG!

# ------ Recursive Lists ------ #

  recursiveLists:
    list1:
      list1A:
        list1A1:
          key1A1A: 1
          list1A1A:
            - 1
            - 2
        list1A2:
          list1A2A:
            key1A2A1: 1
            list1A2A1:
              - 1
              - 2
    list2:
      list2A:
        key2A1: 1
        list2A1:
          - 1
          - 2


################################################################################
#
# Config File Generator Test Helper
#
#
# This script tells the s@ConfigFileGenerator which files to generate based
# on the configs above.

'ConfigFileGeneratorTestHelper':

  type: task
  debug: true
  script:
    - ^define readID 'ConfigFileGeneratorTest'
    - ^define basePath '<def[readID]>_Configurations'
    - ^define scriptPath '<s@<def[basePath]>.constant[scriptPath] || null>'
    - ^if <def[scriptPath].is[==].to[null]> {
      - announce "<&4><&n><def[readID]> <&4>is not a valid readID."
      - inject s@FinishCommand
      }
    - ^yaml 'load:<def[scriptPath]>' 'id:<def[readID]>]'

    - ^define keylist '<yaml[<def[readID]>].list_keys[<def[basePath]>].exclude[type|debug|scriptPath]>'

    - ^foreach <def[keylist]> {
      - define node <def[value]>

      - if !<server.has_file[%readID%/%node%.yml]> || <def[forcewrite]> {
        - if !<def[dryrun]> {
          - announce "<&5>Generating default %node%.yml file..." to_console
          }
        - announce "<&5>Generating default %node%.yml file..." to_flagged:admin
        - announce "" to_flagged:admin
        - define writePath '%node%'
        - define writeID '%readID%_%node%'
        - yaml create 'id:%writeID%'
        - run s@ConfigFileGeneratorTest def:<def[readID]>|<def[writeID]>|<def[basePath]>|<def[writePath]>|<def[dryrun]>|<def[verbose]>|<def[forcewrite]> instantly
        - if !<def[dryrun]> {
          - yaml 'savefile:%readID%/%node%.yml' 'id:%writeID%'
          - announce "<&e>%node%.yml <&6>Save Complete!" to_console
          - announce "<&e>%node%.yml <&6>Save Complete!" to_flagged:admin
          - announce "" to_flagged:admin
          - yaml unload 'id:%writeID%'
          }
          else {
          - announce "<&6>%node%.yml Dryrun Complete!" to_flagged:admin
          - announce "" to_flagged:admin
          - yaml unload 'id:%writeID%'
          }
        }
        else {
        - if !<def[dryrun]> {
          - announce "<&a>%node%.yml already exists!" to_console
          }
        - announce "<&a>%node%.yml already exists!" to_flagged:admin
        }
      }
    - ^if !<def[dryrun]> {
      - announce "<&3><def[readID]> has Completed!" to_console
      }
    - ^announce "<&3><def[readID]> has Completed!" to_flagged:admin


################################################################################
#
# Configuration File Generator
#
#
# This script generates default config files based on the definitions passed to
# it. It should be flexible enough to handle any script.
#
#   - run s@ConfigFileGenerator def:%readID%|%writeID%|%basePath%|%writePath%|%dryrun%|%verbose%|%forcewrite% instantly


'ConfigFileGeneratorTest':
  type: task
  debug: true
  definitions: readID|writeID|basePath|writePath|dryrun|verbose|forcewrite
  script:
    - ^define keylist '<yaml[<def[readID]>].list_keys[<def[basePath]>.<def[writePath]>]>'
    - ^if <def[keylist]> != null {
      - inject s@ConfigFileGeneratorTest p:foreachKeylist instantly
      }
      else {
      - define entry '<yaml[<def[readID]>].read[<def[basePath]>.<def[writePath]>]>'
      - define entryList '<yaml[<def[readID]>].read[<def[basePath]>.<def[writePath]>].as_list>'
      - if !<def[dryrun]> {
        - announce "<&a>Next Path<&co> <&b><def[basePath]>.<def[writePath]>" to_console
        }
      - if <def[dryrun]> || <def[verbose]> {
        - announce "<&a>Next Path<&co> <&b><def[basePath]>.<def[writePath]>" to_flagged:admin
        }
      - if <def[entryList].as_list.size.is[MORE].than[1]> {
        - inject s@ConfigFileGeneratorTest p:foreachEntrylist instantly
        }
        else {
        - inject s@ConfigFileGeneratorTest p:singleEntry instantly
        }
      }

  foreachKeylist:
    - foreach <def[keylist]> {
      - define key '<def[value]>'
      - define oldWritePath '<def[writePath]>'
      - define writePath '%writePath%.%key%'
      - run s@ConfigFileGeneratorTest def:<def[readID]>|<def[writeID]>|<def[basePath]>|<def[writePath]>|<def[dryrun]>|<def[verbose]>|<def[forcewrite]> instantly
      - define writePath '%oldWritePath%'
      }

  foreachEntrylist:
    - yaml 'write:%writePath%' 'id:%writeID%'
    - foreach <def[entryList]> {
      - if !<def[dryrun]> {
        - announce "<&9>%writePath%<&co> <&2>%value%" to_console
        - yaml set <def[writePath]>:->:<def[value]> 'id:<def[writeID]>'
        }
      - if <def[dryrun]> || <def[verbose]> {
        - announce "<&9>%writePath%<&co> <&2>%value%" to_flagged:admin
        }
      }
    - if <def[dryrun]> || <def[verbose]> {
      - announce "<&3>*-----*" to_flagged:admin
      - announce "" to_flagged:admin
      }

  singleEntry:
    - if <def[dryrun].is[==].to[false]> {
      - announce "<&c>%writePath%<&co> <&e>%entry%" to_console
      - yaml 'write:<def[writePath]>' 'value:<def[entry]>' 'id:<def[writeID]>'
      }
    - if <def[dryrun].is[==].to[true]> || <def[verbose].is[==].to[true]> {
      - announce "<&c>%writePath%<&co> <&e>%entry%" to_flagged:admin
      - announce "<&4>*-----*" to_flagged:admin
      - announce "" to_flagged:admin
      }



################################################################################
#
# Configuration File Generator Command
#
#
'ConfigFileGeneratorTestCommand':
  type: world
  debug: false
  events:

    on cfgtest command:
    - if !<player.has_permission[denizen.cfgtest]> queue stop
    - define dryrun '<tern[<c.args.contains[--dryrun]>]:true || false>'
    - define verbose '<tern[<c.args.contains[--verbose]>]:true || false>'
    - define forcewrite '<tern[<c.args.contains[--force]>]:true || false>'
    - if <c.args.find[-f].is[MORE].than[0]> {
      - define file <c.args.get[<c.args.find[-f].add[1].as_int>]>
      }
    - if <c.args.find[-i].is[MORE].than[0]> {
      - define readID <c.args.get[<c.args.find[-i].add[1].as_int>]>
      - narrate "%readID%"
      }
      else {
      - narrate "<&4>You must specify the readID!"
      }
    - narrate "<&b>dryrun<&co> <&a>%dryrun%"
    - narrate "<&b>verbose<&co> <&a>%verbose%"
    - narrate "<&b>forcewrite<&co> <&a>%forcewrite%"
    - inject s@ConfigFileGeneratorTestHelper
    - inject s@FinishCommand



################################################################################
#
# Command Testing
#
#
'TestCommandHandler':
  type: world
  debug: false
  events:

    on cmdtest command:
    - if !<player.has_permission[denizen.cmdtest]> queue stop
    - define dryrun '<tern[<c.args.contains[--dryrun]>]:true || false>'
    - define verbose '<tern[<c.args.contains[--verbose]>]:true || false>'
    - define forcewrite '<tern[<c.args.contains[--force]>]:true || false>'
    - if <c.args.find[-a].is[MORE].than[0]> {
      - define a <c.args.get[<c.args.find[-a].add[1].as_int>]>
      - narrate "<&b>a<&co> <&a>%a%"
      }
    - if <c.args.find[-b].is[MORE].than[0]> {
      - define b <c.args.get[<c.args.find[-b].add[1].as_int>]>
      - narrate "<&b>b<&co> <&a>%b%"
      }
    - if <c.args.find[-c].is[MORE].than[0]> {
      - define c <c.args.get[<c.args.find[-c].add[1].as_int>]>
      - narrate "<&b>c<&co> <&a>%c%"
      }
    - narrate "<&b>dryrun<&co> <&a>%dryrun%"
    - narrate "<&b>verbose<&co> <&a>%verbose%"
    - inject s@FinishCommand

################################################################################
#
# Clear Chat Command
#
#
'ClearChatCommand':
  type: world
  debug: false
  events:

    on clearchat command:
    - if !<player.has_permission[denizen.clearchat]> queue stop
    - repeat 100 {
      - narrate ""
      }
    - inject s@FinishCommand



RawRaw



Pastes made: 65395