Note Editor (#49)(an instance of Generic Editor made by Hacker)VERB SOURCE CODE: e*dit:
if (this:changed(who = player in this.active))
player:tell("You are still editing ", this:working_on(who), ". Please type ABORT
or SAVE first.");
elseif (spec = this:parse_invoke(dobjstr, verb))
this:init_session(who, @spec);
endif
.
save:
if (!(who = this:loaded(player)))
player:tell(this:nothing_loaded_msg());
return;
endif
if (!dobjstr)
note = this.objects[who];
elseif (1 == (note = this:note_match_failed(dobjstr)))
return;
else
this.objects[who] = note;
endif
text = this:text(who);
strmode = (length(text) <= 1) && this.strmode[who];
if (strmode)
text = text ? text[1] | "";
endif
if (ERR == typeof(result = this:set_note_text(note, text)))
player:tell("Text not saved to ", this:working_on(who), ": ", result);
if ((result == E_TYPE) && (typeof(note) == OBJ))
player:tell("Do `mode list' and try saving again.");
elseif (!dobjstr)
player:tell("Use `save' with an argument to save the text elsewhere.");
endif
else
player:tell("Text written to ", this:working_on(who), strmode ? " as a single
string." | ".");
this:set_changed(who, 0);
endif
.
init_session:
if (this:ok(who = args[1]))
this.strmode[who] = strmode = typeof(text = args[3]) == STR;
this:load(who, strmode ? text ? {text} | {} | text);
this.objects[who] = args[2];
player:tell("Now editing ", this:working_on(who), ".", strmode ? " [string mode]"
| "");
endif
.
working_on:
if (!(who = args[1]))
return "????";
endif
spec = this.objects[who];
if (typeof(spec) == LIST)
object = spec[1];
prop = spec[2];
else
object = spec;
prop = 0;
endif
return valid(object) ? tostr("\"", object.name, "\"(", object, ")", prop ? "." +
prop | "") | tostr(prop ? ("." + prop) + " on " | "", "invalid object (", object,
")");
.
parse_invoke:
":parse_invoke(string,verb)";
" string is the actual commandline string indicating what we are to edit";
" verb is the command verb that is attempting to invoke the editor";
if (!(string = args[1]))
player:tell_lines({("Usage: " + args[2]) + "
note_text:
"WIZARDLY";
if ((caller != $note_editor) || (caller_perms() != $note_editor.owner))
return E_PERM;
endif
set_task_perms(player);
if (typeof(spec = args[1]) == OBJ)
text = spec:text();
else
text = spec[1].(spec[2]);
endif
if (((tt = typeof(text)) in {ERR, STR}) || ((tt == LIST) && ((!text) || (typeof(text[1])
== STR))))
return text;
else
return E_TYPE;
endif
.
set_note_text:
"WIZARDLY";
if ((caller != $note_editor) || (caller_perms() != $note_editor.owner))
return E_PERM;
endif
set_task_perms(player);
if (typeof(spec = args[1]) == OBJ)
return spec:set_text(args[2]);
elseif ($object_utils:has_verb(spec[1], "set_" + spec[2]))
attempt = spec[1]:("set_" + spec[2])(args[2]);
endif
if (typeof(attempt) == ERR)
return spec[1].(spec[2]) = args[2];
else
return attempt;
endif
.
note_match_failed:
if (pp = $code_utils:parse_propref(string = args[1]))
object = pp[1];
prop = pp[2];
else
object = string;
prop = 0;
endif
if ($command_utils:object_match_failed(note = player:my_match_object(object, this:get_room(player)),
object))
elseif (prop)
if (!$object_utils:has_property(note, prop))
player:tell(object, " has no \".", prop, "\" property.");
else
return {note, prop};
endif
elseif ((!$object_utils:has_callable_verb(note, "text")) || (!$object_utils:has_callable_verb(note,
"set_text")))
return {note, "description"};
"... what we used to do. but why barf? that's no fun...";
player:tell(object, "(", note, ") doesn't look like a note.");
else
return note;
endif
return 1;
.
w*hat:
pass(@args);
if ((who = this:loaded(player)) && this.strmode[who])
player:tell("Text will be stored as a single string instead of a list when possible.");
endif
.
mode:
"mode [string|list]";
if (!(who = this:loaded(player)))
player:tell(this:nothing_loaded_msg());
return;
endif
if (index("string", dobjstr) == 1)
this.strmode[who] = mode = 1;
player:tell("Now in string mode:");
elseif (index("list", dobjstr) == 1)
this.strmode[who] = mode = 0;
player:tell("Now in list mode:");
elseif (dobjstr)
player:tell("Unrecognized mode: ", dobjstr);
player:tell("Should be one of `string' or `list'");
return;
else
player:tell("Currently in ", mode = this.strmode[who] ? "string " | "list ",
"mode:");
endif
if (mode)
player:tell(" store text as a single string instead of a list when possible.");
else
player:tell(" always store text as a list of strings.");
endif
.
local_editing_info:
what = args[1];
text = args[2];
cmd = (typeof(text) == STR) ? "@set-note-string" | "@set-note-text";
name = (typeof(what) == OBJ) ? what.name | tostr(what[1].name, ".", what[2]);
note = (typeof(what) == OBJ) ? what | tostr(what[1], ".", what[2]);
return {name, text, tostr(cmd, " ", note)};
.
PROPERTY DATA:       strmode       objects CHILDREN: Callable Note Editor |