Generic version, with tags

Applicable everywhere
This commit is contained in:
Alexander Yakovlev 2023-01-30 06:47:51 +06:00
parent 839b4431a2
commit 991814c43f
2 changed files with 50 additions and 31 deletions

50
typeclasses/oatmeal.py Normal file
View File

@ -0,0 +1,50 @@
"""
Tracery Object
This is a joke object that changes its description every time you look at it.
Requires installing pytracery as a pip dependency.
As Kate Compton puts it: "I can easily generate 10,000 bowls of plain oatmeal, with each oat being in a different position and different orientation, and mathematically speaking they will all be completely unique. But the user will likely just see a lot of oatmeal."
This relies on default Tracery and does not have a model memory (i.e. you cannot procgen object attributs based on its description and vice versa).
"""
from typeclasses.objects import Object
import tracery
from tracery.modifiers import base_english
"""
An oatmeal object has an "origin" attribute.
You make a table of rules with attributes, like:
set movie/origin:rules = ['This is #genre.a# #movie# about #subject.s#.', '#subject.s.capitalize# #sequel#: The #family.capitalize# Of All #movie.s.capitalize#!']
The table has to have category "rules" and the main entry point is called "origin". The rest is up to you:
set movie/sequel:rules = ['from hell #number#','#number#','the Resurrection','Origins','Rebooted','Reimagined','Again']
set movie/family:rules = ['mother','father','aunt','xyther','grunkle','grandpa','grandma']
set movie/number:rules = ['2','3','4','5','6','II','III','IV','V','VI','XXIII','MCMXCIII']
set movie/movie:rules = ['movie', 'flick', 'animation', 'anime', 'moving picture', 'picture']
set movie/genre:rules = ['action', 'romance', 'thriller', 'horror', 'abstract', 'slice-of-life', 'comedy', 'documentary']
set movie/subject:rules = ['wombat', '#pair# love #polycule#', 'smartphone', 'astronaut', 'explosion']
set movie/pair:rules = ['gay','aromantic','nonbinary','clueless','crazy']
set movie/polycule:rules = ['triange', 'pair', '3D icosahedron', 'polycule']
And you'll get stuff like "Crazy love polycules Reimagined: The Father Of All Animations!"
"""
class OatmealObject(Object):
"""
Can't be a self.db.desc because we *need* a function here.
"""
def get_display_desc(self, looker, **kwargs):
rules = {}
attrs = self.attributes.get(category='rules', return_obj=True)
for attr in attrs:
v = attr.value.deserialize()
if isinstance(v, list) or isinstance(v, str):
rules[attr.key] = v
if rules == {}:
return "No set of rules detected. Set the intro point with: |wset object/origin:rules = 'text'|n"
grammar = tracery.Grammar(rules)
grammar.add_modifiers(base_english)
return grammar.flatten("#origin#")
pass

View File

@ -1,31 +0,0 @@
"""
Movie Screen
This is a joke object that changes its description every time you look at it.
Requires installing pytracery as a pip dependency.
"""
from typeclasses.objects import Object
import tracery
from tracery.modifiers import base_english
class MovieScreen(Object):
rules = {
'origin': ['This is #genre.a# #movie# about #subject.s#.', '#subject.s.capitalize# #sequel#: The #family.capitalize# Of All #movie.s.capitalize#!'],
'sequel': ['from hell #number#','#number#','the Resurrection','Origins','Rebooted','Reimagined','Again'],
'family': ['mother','father','aunt','xyther','grunkle','grandpa','grandma'],
'number': ['2','3','4','5','6','II','III','IV','V','VI','XXIII','MCMXCIII'],
'movie': ['movie', 'flick', 'animation', 'anime', 'moving picture', 'picture'],
'genre': ['action', 'romance', 'thriller', 'horror', 'abstract', 'slice-of-life', 'comedy', 'documentary'],
'subject': ['wombat', 'stoner', '#pair# love #polycule#', 'smartphone', 'astronaut', 'explosion'],
'pair': ['gay','aromantic','nonbinary','clueless','crazy'],
'polycule': ['triange', 'pair', '3D icosahedron', 'polycule']
}
"""
Can't be a self.db.desc because we *need* a function here.
"""
def get_display_desc(self, looker, **kwargs):
grammar = tracery.Grammar(self.rules)
grammar.add_modifiers(base_english)
return grammar.flatten("#origin#")
pass