item utilities #254
Aliases: item utilities, iu
9 verbs · 15 properties · 0 children
Verbs
| Verb | Spec | Flags | Definer | Lines |
|---|---|---|---|---|
plural_to_type | this none this | rxd | #254 | 8 |
type_to_plural | this none this | rxd | #254 | 7 |
typeof | this none this | rxd | #254 | 18 |
name_to_type | this none this | rxd | #254 | 8 |
type_to_name | this none this | rxd | #254 | 7 |
plurals names pluralsc namesc | this none this | rxd | #254 | 13 |
group_by_type | this none this | rxd | #254 | 13 |
add_type | this none this | rxd | #254 | 16 |
is_a | this none this | rxd | #254 | 11 |
Properties
| Property | Definer | Flags | Owner | Value |
|---|---|---|---|---|
classes | #254 | rc | #361 | list of 11{#107, #288, #306, {#804, #723, #835}, {#868, #877, #890, #1086, #1423, #1570, #5287, #9701, #48018, #103253, #217130, #287228, #306253, #409798}, #5714, {#659, #38845}, #931, #27317, #2044, #665} |
names | #254 | rc | #361 | list of 11{"weapon", "ammo", "clothing", "medical", "consumable", "chemical", "artifact", "container", "trophy", "recipe", "part"} |
plurals | #254 | rc | #361 | list of 11{"weapons", "ammo", "clothing", "medical", "consumables", "chemicals", "artifacts", "containers", "trophies", "recipes", "parts"} |
matches | #254 | rc | #361 | list of 11{{"weapon", "weapons"}, {"ammo"}, {"clothes", "clothing", "armor", "cloth"}, {"medical", "med"}, {"foods", "food", "consumables"}, {"chemical"}, {"artifact", "artifacts", "arts"}, {"containers"}, {"trophies", "trophy"}, {"recipe", "recipes"}, {"part", "parts"}} |
help_msg | #72 | rc | #361 | list of 25{"", " Item types are integers.", "", " Getting item types:", " :typeof(obj) => int", "", " :group_by_type(list of objs) => ", " {list of type 1, list of type 2, ... , ", " list of unclassified objs}", "", " Information about types (index # == item type #):", " :plurals() => list of plural names of item classes.", " :names() => list of singular names of item classes.", "", " (also :pluralsc() and namesc() for capitalized.)", "", " :type_to_plural(int itemtype) => plural for this type.", " :type_to_name(int itemtype) => singular for this type.", "", " Matching:", " :plural_to_type(str) => itemtype if any match, or 0", " :name_to_type(str) => itemtype if any match, or 0", "", " Adding new item types, wizards:", " Use a verb so you can modify all 3 props at once. Add things to the END of lists, only, and start with .names and .plurals, then finally .classes. The format of the props is simple and self-explanatory."} |
aliases | #1 | rc | #361 | {"item utilities", "iu"} |
description | #1 | rc | #361 | <clear> |
object_size | #1 | r | #29 | {7191, 1298434413} |
hidden_verbs | #1 | rc | #361 | <clear> |
phelp_msg | #1 | rc | #361 | <clear> |
weight | #1 | rc | #361 | <clear> |
owner_verbs | #1 | rc | #361 | <clear> |
plural_name | #1 | rc | #361 | <clear> |
client_image | #1 | rc | #361 | <clear> |
listening | #1 | rc | #361 | <clear> |
Ancestry
Ancestors (nearest first): #72 Generic Utilities Package → #1 root
Children: none
Call graph
Source
plural_to_type
Referenced by
none
Source
1"$iu:plural_to_type(STR plural item class) => INT itemtype"; 2{s} = args; 3for i in [1..length(this.plurals)] 4if (s == this.plurals[i]) 5return i; 6endif 7endfor 8return 0;
type_to_plural
Referenced by
none
Source
1"$iu:type_to_plural(INT itemtype) => STR plural name for item class"; 2{i} = args; 3if ((i < 1) || (i > length(this.plurals))) 4raise(E_INVARG, "Invalid item type", i); 5return ""; 6endif 7return this.plurals[i];
typeof
Referenced by
- #254:group_by_type line 6:
this:typeof
Source
1"$iu:typeof(OBJ item) => INT itemtype"; 2{o} = args; 3o = is_a(o, $glob) ? o.item | o; 4for i in [1..length(this.classes)] 5class = this.classes[i]; 6if (typeof(class) == OBJ) 7if (is_a(o, class)) 8return i; 9endif 10else 11for c in (class) 12if (is_a(o, c)) 13return i; 14endif 15endfor 16endif 17endfor 18return 0;
name_to_type
Referenced by
none
Source
1"$iu:name_to_type(STR singular name of item class) => INT itemtype"; 2{s} = args; 3for i in [1..length(this.names)] 4if (s == this.names[i]) 5return i; 6endif 7endfor 8return 0;
type_to_name
Referenced by
none
Source
1"$iu:type_to_name(INT itemtype) => STR singular name for item class"; 2{i} = args; 3if ((i < 1) || (i > length(this.names))) 4raise(E_INVARG, "Invalid item type", i); 5return ""; 6endif 7return this.names[i];
plurals names pluralsc namesc
Referenced by
- #6:tell_contents line 2:
$iu:pluralsc - #54:tell_contents line 2:
$iu:pluralsc - #345:look_self line 1:
$iu:pluralsc
Source
1capitalize = 0; 2if (verb[$] == "c") 3prop = verb[1..$ - 1]; 4l = {}; 5for x in (this.(prop)) 6i = index("abcdefghijklmnopqrstuvwxyz", x[1]); 7x[1] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"[i]; 8l = {@l, x}; 9endfor 10return l; 11else 12return this.(verb); 13endif
group_by_type
Referenced by
- #6:tell_contents line 24:
$iu:group_by_type - #44:match_many line 44:
$iu:group_by_type - #54:tell_contents line 22:
$iu:group_by_type - #345:look_self line 12:
$iu:group_by_type
Source
1"$iu:group_by_type(LIST objs) => {LIST type1objs, LIST type2objs, ..., LIST unclassified objs}"; 2{objs} = args; 3buckets = $lu:make(length(this.classes) + 1, {}); 4for o in (objs) 5yield; 6type = this:typeof(o); 7if (type) 8buckets[type] = {@buckets[type], o}; 9else 10buckets[$] = {@buckets[$], o}; 11endif 12endfor 13return buckets;
add_type
Referenced by
none
Source
1if (!caller_perms().wizard) 2return E_PERM; 3endif 4{name, plural, matches, class} = args; 5if (!(typeof(class) in {OBJ, LIST})) 6return E_INVARG; 7endif 8if ((name in this.names) || (plural in this.plurals)) 9return E_INVARG; 10endif 11matches = setadd(matches, name); 12matches = setadd(matches, plural); 13this.names = {@this.names, name}; 14this.plurals = {@this.plurals, plural}; 15this.matches = {@this.matches, matches}; 16this.classes = {@this.classes, class};
is_a
Referenced by
- #44:match_many line 39:
$iu:is_a
Source
1":is_a(OBJ what, INT class) => Is what a member of class?"; 2{what, classnum} = args; 3class = this.classes[classnum]; 4class = (typeof(class) == OBJ) ? {class} | class; 5matchtype = is_a(what, $glob) ? what.item | what; 6for c in (class) 7if (is_a(matchtype, c)) 8return 1; 9endif 10endfor 11return 0;