From c87f11dcfb6f808cdffc273ec5d0aedf0a98d21e Mon Sep 17 00:00:00 2001 From: Julie Iaccarino <1904063+biscuitWizard@users.noreply.github.com> Date: Sun, 16 Feb 2020 09:15:08 -0800 Subject: [PATCH] Added additional information to the prototype application command flag. --- evennia/commands/default/building.py | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/evennia/commands/default/building.py b/evennia/commands/default/building.py index ffa1cf97fd..2c56d13e3e 100644 --- a/evennia/commands/default/building.py +++ b/evennia/commands/default/building.py @@ -19,6 +19,7 @@ from evennia.utils.eveditor import EvEditor from evennia.utils.evmore import EvMore from evennia.prototypes import spawner, prototypes as protlib, menus as olc_menus from evennia.utils.ansi import raw +from evennia.prototypes.menus import _format_diff_text_and_options COMMAND_DEFAULT_CLASS = class_from_module(settings.COMMAND_DEFAULT_CLASS) @@ -2061,7 +2062,6 @@ class CmdTypeclass(COMMAND_DEFAULT_CLASS): return new_typeclass = prototype["typeclass"] self.switches.append("force") - self.switches.append("reset") if "show" in self.switches or "examine" in self.switches: string = "%s's current typeclass is %s." % (obj.name, obj.__class__) @@ -2095,6 +2095,31 @@ class CmdTypeclass(COMMAND_DEFAULT_CLASS): hooks = "at_object_creation" if update else "all" old_typeclass_path = obj.typeclass_path + # special prompt for the user in cases where we want + # to confirm changes. + if "prototype" in self.switches: + diff, _ = spawner.prototype_diff_from_object(prototype, obj) + txt, options = _format_diff_text_and_options(diff, objects=[obj]) + prompt = "Applying prototype '%s' over '%s' will cause the follow changes:\n%s\n" % \ + ( + prototype["key"], + obj.name, + "\n".join(txt) + ) + if not reset: + prompt += "\n|yWARNING:|n Use the /reset switch to apply the prototype over a blank state." + prompt += "\nAre you sure you want to apply these changes [yes]/no?" + answer = yield (prompt) + answer = "yes" if answer == "" else answer + if answer and answer not in ("yes", "y", "no", "n"): + caller.msg( + "Canceled: Either accept the default by pressing return or specify yes/no." + ) + return + elif answer.strip().lower() in ("n", "no"): + caller.msg("Canceled: No object was modified.") + return + # we let this raise exception if needed obj.swap_typeclass( new_typeclass, clean_attributes=reset, clean_cmdsets=reset, run_start_hooks=hooks