If we can have "zlib", why not "vprops"? ![Smile :) :)](data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7)
This is a package of functions to make it easy to store and retrieve simple and complex datatypes in properties. It was inspired by the desire to let my script define all of its configuration variables with default values and associated properties, allowing the script user to either edit the script to change the default or set individual properties for specific users to override one or more defaults, but having actual properties set in your preferences file only if they override the script's default.
If I have 50 script variable and you override 3 of them for user A and 2 for user B, user A will have 3 properties and user B will have 2.
And it exists!
Here is documentation, of sorts:
This is a package of functions to make it easy to store and retrieve simple and complex datatypes in properties. It was inspired by the desire to let my script define all of its configuration variables with default values and associated properties, allowing the script user to either edit the script to change the default or set individual properties for specific users to override one or more defaults, but having actual properties set in your preferences file only if they override the script's default.
If I have 50 script variable and you override 3 of them for user A and 2 for user B, user A will have 3 properties and user B will have 2.
And it exists!
Code:
git checkout Veracity0/vprops
Here is documentation, of sorts:
Code:
since r17892;
// Properties are mappings from string to string: a (string) name has a (string) value.
//
// The string value can represent one of the following simple ASH data types:
//
// "string"
// "boolean" boolean to_boolean( string ); string to_string( boolean );
// "int" int to_int( string ); string to_string( int );
// "float" float to_float( string ); string to_string( float );
// "item" item to_item( string ); string to_string( item );
// "location" location to_location( string ); string to_string( location );
// "class" class to_class( string ); string to_string( class );
// "stat" stat to_stat( string ); string to_string( stat );
// "skill" skill to_skill( string ); string to_string( skill );
// "effect" effect to_effect( string ); string to_string( effect );
// "familiar" familiar to_familiar( string ); string to_string( familiar );
// "monster" monster to_monster( string ); string to_string( monster );
// "element" element to_element( string ); string to_string( element );
// "phylum" phylum to_phylum( string ); string to_string( phylum );
// "coinmaster" coinmaster to_coinmaster( string ); string to_string( coinmaster );
// "thrall" thrall to_thrall( string ); string to_string( thrall );
// "bounty" bounty to_bounty( string ); string to_string( bounty );
// "servant" servant to_servant( string ); string to_string( servant );
// "vykea" vykea to_vykea( string ); string to_string( vykea );
//
// They can also represent collections of those simple types:
//
// "list" -> TYPE [int] - an ordered collection, allowing duplicates.
// "set" -> boolean [TYPE] - an unordered collection with no duplicates
//
// Collections are put into strings by listing them in the natural order
// of the key, separated by a delimiter character. By default, the
// delimiter is "|", but "," or ";" or anything else can be used
//
// (Internally, this uses split_string(), which takes a regex, not a
// string. Since "|" is a special character in a regex, for convenience,
// we turn "|" into "\\|". But you are welcome to use an actual regex,
// rather than a "delimiter character" if you wish.)
//
// Since the key of a "list" is an int, the elements of the list are
// ordered and duplicate values are allowed.
//
// Since the key of a "set" is any datatype, the elements of the set
// are not ordered and duplicate keys are not allowed.
// You can use the appropriate built-in ASH function to convert between
// simple ASH data types and a string, or vice versa, as listed above.
//
// This package provides coercion functions for "list" and "set" types.
// The versions without "delimiter" assume "|".
// Sets:
boolean [boolean] to_set_of_boolean( string set, string delimiter );
boolean [boolean] to_set_of_boolean( string set );
string to_string( boolean [boolean] set, string delimiter );
string to_string( boolean [boolean] set );
boolean [int] to_set_of_int( string set, string delimiter );
boolean [int] to_set_of_int( string set );
string to_string( boolean [int] set, string delimiter );
string to_string( boolean [int] set );
boolean [float] to_set_of_float( string set, string delimiter );
boolean [float] to_set_of_float( string set );
string to_string( boolean [float] set, string delimiter );
string to_string( boolean [float] set );
boolean [string] to_set_of_string( string set, string delimiter );
boolean [string] to_set_of_string( string set );
string to_string( boolean [string] set, string delimiter );
string to_string( boolean [string] set );
boolean [item] to_set_of_item( string set, string delimiter );
boolean [item] to_set_of_item( string set );
string to_string( boolean [item] set, string delimiter );
string to_string( boolean [item] set );
boolean [location] to_set_of_location( string set, string delimiter );
boolean [location] to_set_of_location( string set );
string to_string( boolean [location] set, string delimiter );
string to_string( boolean [location] set );
boolean [class] to_set_of_class( string set, string delimiter );
boolean [class] to_set_of_class( string set );
string to_string( boolean [class] set, string delimiter );
string to_string( boolean [class] set );
boolean [stat] to_set_of_stat( string set, string delimiter );
boolean [stat] to_set_of_stat( string set );
string to_string( boolean [stat] set, string delimiter );
string to_string( boolean [stat] set );
boolean [skill] to_set_of_skill( string set, string delimiter );
boolean [skill] to_set_of_skill( string set );
string to_string( boolean [skill] set, string delimiter );
string to_string( boolean [skill] set );
boolean [effect] to_set_of_effect( string set, string delimiter );
boolean [effect] to_set_of_effect( string set );
string to_string( boolean [effect] set, string delimiter );
string to_string( boolean [effect] set );
boolean [familiar] to_set_of_familiar( string set, string delimiter );
boolean [familiar] to_set_of_familiar( string set );
string to_string( boolean [familiar] set, string delimiter );
string to_string( boolean [familiar] set );
boolean [monster] to_set_of_monster( string set, string delimiter );
boolean [monster] to_set_of_monster( string set );
string to_string( boolean [monster] set, string delimiter );
string to_string( boolean [monster] set );
boolean [element] to_set_of_element( string set, string delimiter );
boolean [element] to_set_of_element( string set );
string to_string( boolean [element] set, string delimiter );
string to_string( boolean [element] set );
boolean [phylum] to_set_of_phylum( string set, string delimiter );
boolean [phylum] to_set_of_phylum( string set );
string to_string( boolean [phylum] set, string delimiter );
string to_string( boolean [phylum] set );
boolean [coinmaster] to_set_of_coinmaster( string set, string delimiter );
boolean [coinmaster] to_set_of_coinmaster( string set );
string to_string( boolean [coinmaster] set, string delimiter );
string to_string( boolean [coinmaster] set );
boolean [thrall] to_set_of_thrall( string set, string delimiter );
boolean [thrall] to_set_of_thrall( string set );
string to_string( boolean [thrall] set, string delimiter );
string to_string( boolean [thrall] set );
boolean [bounty] to_set_of_bounty( string set, string delimiter );
boolean [bounty] to_set_of_bounty( string set );
string to_string( boolean [bounty] set, string delimiter );
string to_string( boolean [bounty] set );
boolean [servant] to_set_of_servant( string set, string delimiter );
boolean [servant] to_set_of_servant( string set );
string to_string( boolean [servant] set, string delimiter );
string to_string( boolean [servant] set );
boolean [vykea] to_set_of_vykea( string set, string delimiter );
boolean [vykea] to_set_of_vykea( string set );
string to_string( boolean [vykea] set, string delimiter );
string to_string( boolean [vykea] set );
// Lists:
boolean [int] to_list_of_boolean( string list, string delimiter );
boolean [int] to_list_of_boolean( string list );
string to_string( boolean [int] list, string delimiter );
string to_string( boolean [int] list );
int [int] to_list_of_int( string list, string delimiter );
int [int] to_list_of_int( string list );
string to_string( int [int] list, string delimiter );
string to_string( int [int] list );
float [int] to_list_of_float( string list, string delimiter );
float [int] to_list_of_float( string list );
string to_string( float [int] list, string delimiter );
string to_string( float [int] list );
string [int] to_list_of_string( string list, string delimiter );
string [int] to_list_of_string( string list );
string to_string( string [int] list, string delimiter );
string to_string( string [int] list );
item [int] to_list_of_item( string list, string delimiter );
item [int] to_list_of_item( string list );
string to_string( item [int] list, string delimiter );
string to_string( item [int] list );
location [int] to_list_of_location( string list, string delimiter );
location [int] to_list_of_location( string list );
string to_string( location [int] list, string delimiter );
string to_string( location [int] list );
class [int] to_list_of_class( string list, string delimiter );
class [int] to_list_of_class( string list );
string to_string( class [int] list, string delimiter );
string to_string( class [int] list );
stat [int] to_list_of_stat( string list, string delimiter );
stat [int] to_list_of_stat( string list );
string to_string( stat [int] list, string delimiter );
string to_string( stat [int] list );
skill [int] to_list_of_skill( string list, string delimiter );
skill [int] to_list_of_skill( string list );
string to_string( skill [int] list, string delimiter );
string to_string( skill [int] list );
effect [int] to_list_of_effect( string list, string delimiter );
effect [int] to_list_of_effect( string list );
string to_string( effect [int] list, string delimiter );
string to_string( effect [int] list );
familiar [int] to_list_of_familiar( string list, string delimiter );
familiar [int] to_list_of_familiar( string list );
string to_string( familiar [int] list, string delimiter );
string to_string( familiar [int] list );
monster [int] to_list_of_monster( string list, string delimiter );
monster [int] to_list_of_monster( string list );
string to_string( monster [int] list, string delimiter );
string to_string( monster [int] list );
element [int] to_list_of_element( string list, string delimiter );
element [int] to_list_of_element( string list );
string to_string( element [int] list, string delimiter );
string to_string( element [int] list );
phylum [int] to_list_of_phylum( string list, string delimiter );
phylum [int] to_list_of_phylum( string list );
string to_string( phylum [int] list, string delimiter );
string to_string( phylum [int] list );
coinmaster [int] to_list_of_coinmaster( string list, string delimiter );
coinmaster [int] to_list_of_coinmaster( string list );
string to_string( coinmaster [int] list, string delimiter );
string to_string( coinmaster [int] list );
thrall [int] to_list_of_thrall( string list, string delimiter );
thrall [int] to_list_of_thrall( string list );
string to_string( thrall [int] list, string delimiter );
string to_string( thrall [int] list );
bounty [int] to_list_of_bounty( string list, string delimiter );
bounty [int] to_list_of_bounty( string list );
string to_string( bounty [int] list, string delimiter );
string to_string( bounty [int] list );
servant [int] to_list_of_servant( string list, string delimiter );
servant [int] to_list_of_servant( string list );
string to_string( servant [int] list, string delimiter );
string to_string( servant [int] list );
vykea [int] to_list_of_vykea( string list, string delimiter );
vykea [int] to_list_of_vykea( string list );
string to_string( vykea [int] list, string delimiter );
string to_string( vykea [int] list );
// Values work best if they are "normalized".
//
// "seal tooth" is a normalized "item"
// "seal t" is not normalized.
// "snorkel|seal tooth" is a normalized "list" or "set" of "item"
// "snork|seal t" is not normalized
//
// This package provides functions to normalize string values. Since
// users can set properties to whatever they wish, it uses these
// functions itself, but user programs can also use them if they want to
// ensure that properties that they set are precise.
string normalize_value( string value, string type );
string normalize_list( string value, string type, string delimiter );
string normalize_list( string value, string type );
string normalize_set( string value, string type, string delimiter );
string normalize_set( string value, string type );
string normalize_value( string value, string type, string collection, string delimiter );
string normalize_value( string value, string type, string collection );
// define_property specifies that a particular property with NAME is of type TYPE.
// Optionally, you can declare that the value is a COLLECTION (either "list" or "set") with a DELIMITER
// NAME can be either built-in to KoLmafia or a custom user property.
// If it is a custom property, you can specify a DEFAULT value
//
// If the property exists, define_property will fetch the value,
// normalize it, and return it.
// If the property is custom and the value is not normalized,
// the property will be set with the normalized value.
// If the property is custom and the normalized value equals
// the normalized default value, the property will be removed.
//
// If the property does not exist, define_property will return the
// (normalized) default value and the property will remain unset.
string define_property( string name, string type, string def );
string define_property( string name, string type, string def, string collection );
string define_property( string name, string type, string def, string collection, string delimiter );
// You can use these in conjunction with the appropriate coercion
// function to extract the value of a property into the appropriate data
// type. For example:
//
// int prop1 = define_property( "prop1", "int", "12" ).to_int();
// boolean prop2 = define_property( "prop2", "boolean", "true" ).to_boolean();
// item prop3 = define_property( "prop3", "item", "snorkel" ).to_item();
// boolean [item] prop4 = define_property( "prop4", "item", "snorkel|seal tooth", "set" ).to_set_of_item();
// string [int] prop5 = define_property( "prop5", "string", "str1,str2,str3", "list", "," ).to_list_of_string( "," );