Date: 2014/09/10 12:18:04 UTC-07:00
Type: Denizen 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
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
editPackage:
# This references the ExamplePackage in this script NOT the one in the
# packages.yml file! We do this so the end user doesn't bork things (i hope).
- define readID 'PerkPoints_Configurations'
- define readPath 'PerkPoints_Configurations.packages.ExamplePackage'
- define writeID 'PerkPoints_packages'
- if !<yaml.list.contains[%readID%]> yaml 'load:<script.relative_filename>' 'id:%readID%'
# We need to check if the package exists
- define pack '<c.args.get[3].replace[.].with[-].escaped||null>'
- define syntax '/perkadmin pack edit \<<\>PackageName\<>\> \<<\>Option\<>\> \<<\>SubOption\<>\> \<<\>value\<>\>'
- inject locally packageExists
# Let's check the option the user wants to edit...
- define option '<c.args.get[4].replace[.].with[-].escaped||null>'
- define optionsList '<yaml[%readID%].list_keys[%readPath%]>'
- if !<def[optionsList].contains_case_sensitive[%option%]> {
- narrate "<&b>PerkPoints<&co> <&a>Available Options"
- narrate "<&b>PerkPoints<&co> <&f><def[optionsList].comma_separated>"
- narrate format:CmdSynFormat "/perkadmin pack edit %pack% \<<\>Option\<>\> \<<\>SubOption\<>\> \<<\>value\<>\>"
- queue stop
}
# Ok, that option exists, we'll define some data since we know it
- define readPath '%readPath%.%option%'
- define writePath '%writePath%.%option%'
- define value '<c.args.get[5].replace[.].with[-].escaped||null>'
# Let's check if that option has sub-options. If it does, do sanity check
# and define known data
- define subOptionsList '<yaml[%readID%].list_keys[%readPath%]||null>'
- if !<def[subOptionsList].is_empty>
&& !<def[subOptionsList].is[==].to[null]> {
- define subOption '<c.args.get[5].replace[.].with[-].escaped||null>'
- if !<def[subOptionsList].contains_case_sensitive[%subOption%]> {
- narrate "<&b>PerkPoints<&co> <&f>Available Sub Options"
- narrate "<&b>PerkPoints<&co> <&f><def[subOptionsList].comma_separated>"
- narrate format:CmdSynFormat "/perkadmin pack edit %pack% %option% \<<\>SubOption\<>\> \<<\>value\<>\>"
- queue stop
}
else {
- define readPath '%readPath%.%subOption%'
- define writePath '%writePath%.%subOption%'
- define value '<c.args.get[6].replace[.].with[-].escaped||null>'
}
}
# By now we should have a %readPath%, %writePath% and a %value%. Let's check
- if <def[value].is[==].to[null]> {
- narrate "<&b>PerkPoints<&co> <&c>You must specify a value!"
- narrate format:CmdSynFormat "/perkadmin pack edit %pack% <tern[<def[subOption].exists>]:%option% <def[subOption]||null> || %option%> \<<\>value\<>\>"
- queue stop
}
- if !<yaml[%readID%].contains[%readPath%]> {
- narrate "<&b>PerkPoints<&co> <&c>%readPath% does not exist!"
- queue stop
}
# Let's check if the user supplied the correct type for this option
- define ComparedToValue '<yaml[<def[readID]>].read[%readPath%]>'
- define TypeMatch '<proc[TypeMatch].context[%value%|%ComparedToValue%]>'
- if !<def[TypeMatch].get[1]> {
- narrate "<&b>PerkPoints<&co> <&c><def[readPath].split[.].last> option must be a <def[TypeMatch].get[3]> value!"
- queue stop
}
# Everything seems good, let's see if we're working with a list item or a
# single value and then make the edit
# If we're working with a list, we need to know if we're adding or removing
- if <yaml[%readID%].is_list[%readPath%]> {
- if <yaml[%writeID%].read[%writePath%].contains[%value%]> {
- yaml set %writePath%:<-:%value% 'id:%writeID%'
- narrate "<&b>PerkPoints<&co> <&b>Removed <&a>'<tern[<def[subOption].exists>]:%option% <def[subOption]||null> || %option%>'<&b> entry from <&a>%pack%<&a> package!"
}
else {
- yaml set %writePath%:->:%value% 'id:%writeID%'
- narrate "<&b>PerkPoints<&co> <&b>Added <&a>'<tern[<def[subOption].exists>]:%option% <def[subOption]||null> || %option%>'<&b> entry to <&a>%pack%<&a> package!"
}
}
else {
- yaml 'write:%writePath%' 'value:%value%' 'id:%writeID%'
- narrate "<&b>PerkPoints<&co> <&b>Set <&a>'<tern[<def[subOption].exists>]:%option% <def[subOption]||null> || %option%>'<&b> value for <&a>%pack%<&a> package!"
}
- if <yaml.list.contains[%readID%]> yaml unload 'id:%readID%'
- yaml 'savefile:PerkPoints/packages.yml' 'id:%writeID%'
- queue stop
packageExists:
# Did the user type in a package name?
- if <def[pack].is[==].to[null]> {
- narrate "<&b>PerkPoints<&co> <&c>You must specify a package name!"
- narrate format:CmdSynFormat "%syntax%"
- queue stop
}
- define syntax:!
- define writePath 'packages.%pack%'
# Does that package exist?
- define packList '<yaml[%writeID%].list_keys[packages].exclude[ExamplePackage]||null>'
- if !<def[packList].contains_case_sensitive[%pack%]> {
- narrate "<&b>PerkPoints<&co> <&c>Package <&b>%pack%<&c> does not exist!"
- queue stop
}