Paste #4234: Untitled Paste

Date: 2014/05/09 13:10:02 UTC-07:00
Type: Denizen Script

View Raw Paste Download This Paste
Copy Link


################################################################################
#                                                                              #
# 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__________#
#                                                                              #
#______________________________________________________________________________#

'ConfigFileGeneratorTestConfigurations':
  type: task
  debug: false

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


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

  singleValues:
    keyA: 1
    keyA: 0.1
    keyA: -1
    keyA: NaN
    keyA: 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:
        value1: 1
        list1:
          - 1
          - 2
    list2:
      list2A:
        list2A1:
          value1: 1
          list1:
            - 1
            - 2
        list2A2:
          list2A2A:
            value1: 1
            value1:
              - 1
              - 2


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

  type: task
  debug: true
  script:

    - ^define scriptPath '<s@ConfigFileGeneratorTest.constant[scriptPath]>'
    - ^define readID 'ConfigFileGeneratorTest'
    - ^yaml 'load:<def[scriptPath]>' 'id:%readID%'

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

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

      - if !<server.has_file[ConfigFileGeneratorTest/%node%.yml]> {
        - narrate "<&a>Generating default %node%.yml file..."
        - define basePath 'ConfigFileGeneratorTest'
        - define writePath '%node%'
        - define writeID 'ConfigFileGeneratorTest_%node%'
        - yaml create 'id:%writeID%'
        - inject s@ConfigFileGenerator
        - narrate "<&b>Done!"
        - if !<def[dryrun]> yaml savefile:ConfigFileGeneratorTest/%node%.yml 'id:%writeID%'
        - yaml unload 'id:%writeID%'
        }
        else narrate "<&a>%node%.yml already exists!"
      }
    - narrate "<&6>Done!"


################################################################################
#
# 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
# 


'BasicConfigFileGenerator':
  type: task
  debug: true
  definitions: readID|writeID|basePath|writePath
  script:
    - ^define keylist '<yaml[%readID%].list_keys[%basePath%.%writePath%]>'
    - ^foreach <def[keylist]> {
      - define key '<def[value]>'
      - define oldWritePath '%writePath%'
      - define writePath '%writePath%.%key%'
      - narrate "<&a>Next Path<&co> <&b>%basePath%.%writePath%"
      - inject s@ConfigFileGenerator
      - define writePath '%oldWritePath%'
      - narrate "<&4>Done!"
      }
    - ^narrate "<&6>Done!"






"ConfigFileGeneratorTestCommand":
  type: world
  debug: false
  events:

    on cfgtest command:
    - define dryrun true
    - inject s@ConfigFileGeneratorTestHelper
    - inject s@FinishCommand