Skip to content

Commit 5641ecb

Browse files
committed
Add verb-editor support to $prog
1 parent 531d66f commit 5641ecb

4 files changed

Lines changed: 107 additions & 7 deletions

File tree

src/player.moo

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ object PLAYER
1515

1616
override description = "You see a player who should get around to describing themself.";
1717

18-
verb "l look" (any none none) owner: ARCH_WIZARD flags: "rxd"
18+
verb "l*ook" (any none none) owner: ARCH_WIZARD flags: "rxd"
1919
"Look at an object. Collects the descriptive attributes and then emits them to the player.";
2020
"If we don't have a match, that's a 'I don't see that there...'";
2121
if (dobjstr == "")
@@ -70,7 +70,7 @@ object PLAYER
7070
transformed = event:transform_for(connection_obj, content_type);
7171
except e (ANY)
7272
transformed = "FAILED EVENT: " + toliteral(event) + "
73-
" + toliteral(e);
73+
" + toliteral(e);
7474
endtry
7575
"Iterate the transformed values and have it turn into its output form. Strings output as strings, while HTML trees are transformed, etc.";
7676
output = {};

src/prog.moo

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,15 @@ object PROG
33
parent: BUILDER
44
location: FIRST_ROOM
55
owner: WIZ
6+
wizard: true
7+
programmer: true
68
fertile: true
79
readable: true
810

911
verb eval (any any any) owner: ARCH_WIZARD flags: "rxd"
12+
if (player != caller)
13+
raise(E_PERMS);
14+
endif
1015
set_task_perms(player);
1116
answer = eval("return " + argstr + ";");
1217
if (answer[1])
@@ -16,4 +21,75 @@ object PROG
1621
endif
1722
player:tell(result_event);
1823
endverb
24+
25+
verb "@edit" (any any any) owner: ARCH_WIZARD flags: "rxd"
26+
"Edit a verb on an object using the presentation system.";
27+
"Usage: @edit <object>:<verb> [info]";
28+
"Examples: @edit #1:look_self, @edit player:tell, @edit $match:match_object info";
29+
if (player != caller)
30+
raise(E_PERMS);
31+
endif
32+
set_task_perms(player);
33+
"Check for usage errors";
34+
if (!argstr)
35+
player:tell($event:mk_error(player, "Usage: " + verb + " <object>:<verb> [info]"));
36+
return;
37+
endif
38+
"Parse arguments - check for 'info' mode";
39+
args_list = argstr:split(" ");
40+
verbref_string = args_list[1];
41+
"Parse the verb reference";
42+
parsed = verbref_string:parse_verbref();
43+
if (!parsed)
44+
player:tell($event:mk_error(player, "Invalid verb reference format. Use 'object:verb'"));
45+
return;
46+
endif
47+
{object_str, verb_name} = parsed;
48+
"Match the object";
49+
target_obj = $match:match_object(object_str, player);
50+
if (typeof(target_obj) == ERR)
51+
if (target_obj == E_INVARG("No object found matching '" + object_str + "'"))
52+
player:tell($event:mk_error(player, "I don't see '" + object_str + "' here."));
53+
else
54+
player:tell($event:mk_error(player, "Error matching object: " + tostr(target_obj)));
55+
endif
56+
return;
57+
endif
58+
"Find and retrieve the verb code";
59+
try
60+
"Find where the verb is actually defined";
61+
verb_location = target_obj:find_verb_definer(verb_name);
62+
if (verb_location == #-1)
63+
player:tell($event:mk_error(player, "Verb '" + tostr(verb_name) + "' not found on " + target_obj.name + " or its ancestors."));
64+
return;
65+
endif
66+
"Get verb information for editor";
67+
verb_info_data = verb_info(verb_location, verb_name);
68+
{verb_owner, verb_flags, verb_names} = verb_info_data;
69+
"Open the editor";
70+
player:present_editor(verb_location, verb_name);
71+
player:tell($event:mk_info(player, "Opened verb editor for " + tostr(target_obj) + ":" + tostr(verb_name)));
72+
except (E_VERBNF)
73+
player:tell($event:mk_error(player, "Verb '" + tostr(verb_name) + "' not found on " + target_obj.name + "."));
74+
return;
75+
endtry
76+
endverb
77+
78+
verb present_editor (this none this) owner: ARCH_WIZARD flags: "rxd"
79+
if (caller != this)
80+
raise(E_PERM);
81+
endif
82+
{verb_location, verb_name} = args;
83+
editor_id = "edit-" + tostr(verb_location) + "-" + verb_name;
84+
editor_title = "Edit " + verb_name + " on " + tostr(verb_location);
85+
obj_str = tostr(verb_location);
86+
if (obj_str[1] == "#")
87+
object_curie = "oid:" + obj_str[2..$];
88+
elseif (obj_str[1] == "$")
89+
object_curie = "sysobj:" + obj_str[2..$];
90+
else
91+
object_curie = obj_str;
92+
endif
93+
present(player, editor_id, "text/plain", "verb-editor", "", {{"object", object_curie}, {"verb", verb_name}, {"title", editor_title}});
94+
endverb
1995
endobject

src/root.moo

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,4 +83,28 @@ object ROOT
8383
!("all_verbs" in all_verbs) || (!("test_all_verbs" in all_verbs) && return E_ASSERT);
8484
return true;
8585
endverb
86+
87+
verb find_verb_definer (this none this) owner: HACKER flags: "rxd"
88+
"Find verb on object or its ancestors, returning the object that actually defines the verb.";
89+
"Uses ancestors() builtin and verb_info() to handle aliases, wildcards, and inheritance.";
90+
"Usage: obj:find_verb_definer(verb_name)";
91+
{verb_name} = args;
92+
"Check this object first";
93+
try
94+
verb_info(this, verb_name);
95+
return this;
96+
except (E_VERBNF)
97+
endtry
98+
"Then check ancestors";
99+
ancestor_list = ancestors(this);
100+
for ancestor in (ancestor_list)
101+
try
102+
verb_info(ancestor, verb_name);
103+
return ancestor;
104+
except (E_VERBNF)
105+
continue;
106+
endtry
107+
endfor
108+
return #-1;
109+
endverb
86110
endobject

src/str_proto.moo

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -471,7 +471,7 @@ object STR_PROTO
471471
endif
472472
object = tostr(object);
473473
endif
474-
return {object, tosym(verbname)};
474+
return {object, verbname};
475475
endverb
476476

477477
verb test_parse_verbref (this none this) owner: HACKER flags: "rxd"
@@ -484,15 +484,15 @@ object STR_PROTO
484484
result != should && raise(E_ASSERT, ": should be " + toliteral(should) + " was: " + toliteral(result));
485485
end
486486
begin
487-
let {result, should} = {"$string:look_self":parse_verbref(), {"$string", 'look_self}};
487+
let {result, should} = {"$string:look_self":parse_verbref(), {"$string", "look_self"}};
488488
result != should && raise(E_ASSERT, "$string:look_self should be " + toliteral(should) + " was: " + toliteral(result));
489489
end
490490
begin
491-
let {result, should} = {"#1:look_self":parse_verbref(), {"#1", 'look_self}};
491+
let {result, should} = {"#1:look_self":parse_verbref(), {"#1", "look_self"}};
492492
result != should && raise(E_ASSERT, "#1:look_self should be " + toliteral(should) + " was: " + toliteral(result));
493493
end
494494
begin
495-
let {result, should} = {"honk:look_self":parse_verbref(), {"honk", 'look_self}};
495+
let {result, should} = {"honk:look_self":parse_verbref(), {"honk", "look_self"}};
496496
result != should && raise(E_ASSERT, "honk:look_self should be " + toliteral(should) + " was: " + toliteral(result));
497497
end
498498
endverb
@@ -677,7 +677,7 @@ object STR_PROTO
677677
endif
678678
object = tostr(object);
679679
endif
680-
return {object, tosym(verbname)};
680+
return {object, verbname};
681681
endverb
682682

683683
verb test_split (this none this) owner: HACKER flags: "rxd"

0 commit comments

Comments
 (0)