From 050b050d24d011013fe8b4450a61a0bec0066a90 Mon Sep 17 00:00:00 2001 From: Griatch Date: Sat, 18 Jul 2020 22:37:43 +0200 Subject: [PATCH] Make DefaultObject/Room/Exit's argument optional. Also resolves #2162. --- CHANGELOG.md | 2 ++ evennia/objects/objects.py | 39 ++++++++++++++++++++++++++------------ evennia/objects/tests.py | 2 +- 3 files changed, 30 insertions(+), 13 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 688cec7892..7450063360 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -65,6 +65,8 @@ without arguments starts a full interactive Python console. - Add `$random` inlinefunc, supports minval,maxval arguments that can be ints and floats. - Add `evennia.utils.inlinefuncs.raw()` as a helper to escape inlinefuncs in a string. - Make CmdGet/Drop/Give give proper error if `obj.move_to` returns `False`. +- Make `Object/Room/Exit.create`'s `account` argument optional. If not given, will set perms + to that of the object itself (along with normal Admin/Dev permission). ## Evennia 0.9 (2018-2019) diff --git a/evennia/objects/objects.py b/evennia/objects/objects.py index 0fcabca4a2..d2bb4c2b2c 100644 --- a/evennia/objects/objects.py +++ b/evennia/objects/objects.py @@ -2029,10 +2029,11 @@ class DefaultCharacter(DefaultObject): # lockstring of newly created rooms, for easy overloading. # Will be formatted with the appropriate attributes. - lockstring = "puppet:id({character_id}) or pid({account_id}) or perm(Developer) or pperm(Developer);delete:id({account_id}) or perm(Admin)" + lockstring = ("puppet:id({character_id}) or pid({account_id}) or perm(Developer) or pperm(Developer);" + "delete:id({account_id}) or perm(Admin)") @classmethod - def create(cls, key, account, **kwargs): + def create(cls, key, account=None, **kwargs): """ Creates a basic Character with default parameters, unless otherwise specified or extended. @@ -2041,8 +2042,8 @@ class DefaultCharacter(DefaultObject): Args: key (str): Name of the new Character. - account (obj): Account to associate this Character with. Required as - an argument, but one can fake it out by supplying None-- it will + account (obj, optional): Account to associate this Character with. + If unset supplying None-- it will change the default lockset and skip creator attribution. Kwargs: @@ -2249,7 +2250,7 @@ class DefaultRoom(DefaultObject): ) @classmethod - def create(cls, key, account, **kwargs): + def create(cls, key, account=None, **kwargs): """ Creates a basic Room with default parameters, unless otherwise specified or extended. @@ -2258,7 +2259,9 @@ class DefaultRoom(DefaultObject): Args: key (str): Name of the new Room. - account (obj): Account to associate this Room with. + account (obj, optional): Account to associate this Room with. If + given, it will be given specific control/edit permissions to this + object (along with normal Admin perms). If not given, default Kwargs: description (str): Brief description for this object. @@ -2287,13 +2290,20 @@ class DefaultRoom(DefaultObject): # Get description, if provided description = kwargs.pop("description", "") + # get locks if provided + locks = kwargs.pop("locks", "") + try: # Create the Room obj = create.create_object(**kwargs) - # Set appropriate locks - lockstring = kwargs.get("locks", cls.lockstring.format(id=account.id)) - obj.locks.add(lockstring) + # Add locks + if not locks and account: + locks = cls.lockstring.format(**{"id": account.id}) + elif not locks and not account: + locks = cls.lockstring(**{"id": obj.id}) + + obj.locks.add(locks) # Record creator id and creation IP if ip: @@ -2442,7 +2452,7 @@ class DefaultExit(DefaultObject): # Command hooks @classmethod - def create(cls, key, account, source, dest, **kwargs): + def create(cls, key, source, dest, account=None, **kwargs): """ Creates a basic Exit with default parameters, unless otherwise specified or extended. @@ -2486,13 +2496,18 @@ class DefaultExit(DefaultObject): description = kwargs.pop("description", "") + locks = kwargs.get("locks", "") + try: # Create the Exit obj = create.create_object(**kwargs) # Set appropriate locks - lockstring = kwargs.get("locks", cls.lockstring.format(id=account.id)) - obj.locks.add(lockstring) + if not locks and account: + locks = cls.lockstring.format(**{"id": account.id}) + elif not locks and not account: + locks = cls.lockstring.format(**{"id": obj.id}) + obj.locks.add(locks) # Record creator id and creation IP if ip: diff --git a/evennia/objects/tests.py b/evennia/objects/tests.py index 75f91cba36..a63bc87079 100644 --- a/evennia/objects/tests.py +++ b/evennia/objects/tests.py @@ -50,7 +50,7 @@ class DefaultObjectTest(EvenniaTest): def test_exit_create(self): description = "The steaming depths of the dumpster, ripe with refuse in various states of decomposition." obj, errors = DefaultExit.create( - "in", self.account, self.room1, self.room2, description=description, ip=self.ip + "in", self.room1, self.room2, account=self.account, description=description, ip=self.ip ) self.assertTrue(obj, errors) self.assertFalse(errors, errors)