mirror of
https://github.com/evennia/evennia.git
synced 2026-04-05 15:37:17 +02:00
Updated HTML docs
This commit is contained in:
parent
3381394f33
commit
6356e0d4fa
61 changed files with 827 additions and 248 deletions
|
|
@ -59,110 +59,133 @@
|
|||
<span class="sd"> overhear (for example "s" sounds tend to be audible even when no other</span>
|
||||
<span class="sd"> meaning can be determined).</span>
|
||||
|
||||
<span class="sd">Usage:</span>
|
||||
<span class="sd">## Usage</span>
|
||||
|
||||
<span class="sd"> ```python</span>
|
||||
<span class="sd"> from evennia.contrib import rplanguage</span>
|
||||
<span class="sd">```python</span>
|
||||
<span class="sd">from evennia.contrib import rplanguage</span>
|
||||
|
||||
<span class="sd"> # need to be done once, here we create the "default" lang</span>
|
||||
<span class="sd"> rplanguage.add_language()</span>
|
||||
<span class="sd"># need to be done once, here we create the "default" lang</span>
|
||||
<span class="sd">rplanguage.add_language()</span>
|
||||
|
||||
<span class="sd"> say = "This is me talking."</span>
|
||||
<span class="sd"> whisper = "This is me whispering.</span>
|
||||
<span class="sd">say = "This is me talking."</span>
|
||||
<span class="sd">whisper = "This is me whispering.</span>
|
||||
|
||||
<span class="sd"> print rplanguage.obfuscate_language(say, level=0.0)</span>
|
||||
<span class="sd"> <<< "This is me talking."</span>
|
||||
<span class="sd"> print rplanguage.obfuscate_language(say, level=0.5)</span>
|
||||
<span class="sd"> <<< "This is me byngyry."</span>
|
||||
<span class="sd"> print rplanguage.obfuscate_language(say, level=1.0)</span>
|
||||
<span class="sd"> <<< "Daly ly sy byngyry."</span>
|
||||
<span class="sd">print rplanguage.obfuscate_language(say, level=0.0)</span>
|
||||
<span class="sd"><<< "This is me talking."</span>
|
||||
<span class="sd">print rplanguage.obfuscate_language(say, level=0.5)</span>
|
||||
<span class="sd"><<< "This is me byngyry."</span>
|
||||
<span class="sd">print rplanguage.obfuscate_language(say, level=1.0)</span>
|
||||
<span class="sd"><<< "Daly ly sy byngyry."</span>
|
||||
|
||||
<span class="sd"> result = rplanguage.obfuscate_whisper(whisper, level=0.0)</span>
|
||||
<span class="sd"> <<< "This is me whispering"</span>
|
||||
<span class="sd"> result = rplanguage.obfuscate_whisper(whisper, level=0.2)</span>
|
||||
<span class="sd"> <<< "This is m- whisp-ring"</span>
|
||||
<span class="sd"> result = rplanguage.obfuscate_whisper(whisper, level=0.5)</span>
|
||||
<span class="sd"> <<< "---s -s -- ---s------"</span>
|
||||
<span class="sd"> result = rplanguage.obfuscate_whisper(whisper, level=0.7)</span>
|
||||
<span class="sd"> <<< "---- -- -- ----------"</span>
|
||||
<span class="sd"> result = rplanguage.obfuscate_whisper(whisper, level=1.0)</span>
|
||||
<span class="sd"> <<< "..."</span>
|
||||
<span class="sd">result = rplanguage.obfuscate_whisper(whisper, level=0.0)</span>
|
||||
<span class="sd"><<< "This is me whispering"</span>
|
||||
<span class="sd">result = rplanguage.obfuscate_whisper(whisper, level=0.2)</span>
|
||||
<span class="sd"><<< "This is m- whisp-ring"</span>
|
||||
<span class="sd">result = rplanguage.obfuscate_whisper(whisper, level=0.5)</span>
|
||||
<span class="sd"><<< "---s -s -- ---s------"</span>
|
||||
<span class="sd">result = rplanguage.obfuscate_whisper(whisper, level=0.7)</span>
|
||||
<span class="sd"><<< "---- -- -- ----------"</span>
|
||||
<span class="sd">result = rplanguage.obfuscate_whisper(whisper, level=1.0)</span>
|
||||
<span class="sd"><<< "..."</span>
|
||||
|
||||
<span class="sd"> ```</span>
|
||||
<span class="sd">```</span>
|
||||
|
||||
<span class="sd"> To set up new languages, import and use the `add_language()`</span>
|
||||
<span class="sd"> helper method in this module. This allows you to customize the</span>
|
||||
<span class="sd"> "feel" of the semi-random language you are creating. Especially</span>
|
||||
<span class="sd"> the `word_length_variance` helps vary the length of translated</span>
|
||||
<span class="sd"> words compared to the original and can help change the "feel" for</span>
|
||||
<span class="sd"> the language you are creating. You can also add your own</span>
|
||||
<span class="sd"> dictionary and "fix" random words for a list of input words.</span>
|
||||
<span class="sd">## Custom languages</span>
|
||||
|
||||
<span class="sd"> Below is an example of "elvish", using "rounder" vowels and sounds:</span>
|
||||
<span class="sd">To set up new languages, you need to run `add_language()`</span>
|
||||
<span class="sd">helper function in this module. The arguments of this function (see below)</span>
|
||||
<span class="sd">are used to store the new language in the database (in the LanguageHandler,</span>
|
||||
<span class="sd">which is a type of Script).</span>
|
||||
|
||||
<span class="sd"> ```python</span>
|
||||
<span class="sd"> # vowel/consonant grammar possibilities</span>
|
||||
<span class="sd"> grammar = ("v vv vvc vcc vvcc cvvc vccv vvccv vcvccv vcvcvcc vvccvvcc "</span>
|
||||
<span class="sd"> "vcvvccvvc cvcvvcvvcc vcvcvvccvcvv")</span>
|
||||
<span class="sd">If you want to remember the language definitions, you could put them all</span>
|
||||
<span class="sd">in a module along with the `add_language` call as a quick way to</span>
|
||||
<span class="sd">rebuild the language on a db reset:</span>
|
||||
|
||||
<span class="sd"> # all not in this group is considered a consonant</span>
|
||||
<span class="sd"> vowels = "eaoiuy"</span>
|
||||
<span class="sd">```python</span>
|
||||
<span class="sd"># a stand-alone module somewhere under mygame. Just import this</span>
|
||||
<span class="sd"># once to automatically add the language!</span>
|
||||
|
||||
<span class="sd"> # you need a representative of all of the minimal grammars here, so if a</span>
|
||||
<span class="sd"> # grammar v exists, there must be atleast one phoneme available with only</span>
|
||||
<span class="sd"> # one vowel in it</span>
|
||||
<span class="sd"> phonemes = ("oi oh ee ae aa eh ah ao aw ay er ey ow ia ih iy "</span>
|
||||
<span class="sd"> "oy ua uh uw y p b t d f v t dh s z sh zh ch jh k "</span>
|
||||
<span class="sd"> "ng g m n l r w")</span>
|
||||
<span class="sd">from evennia.contrib.rpg.rpsystem import rplanguage</span>
|
||||
<span class="sd">grammar = (...)</span>
|
||||
<span class="sd">vowels = "eaouy"</span>
|
||||
<span class="sd"># etc</span>
|
||||
|
||||
<span class="sd"> # how much the translation varies in length compared to the original. 0 is</span>
|
||||
<span class="sd"> # smallest, higher values give ever bigger randomness (including removing</span>
|
||||
<span class="sd"> # short words entirely)</span>
|
||||
<span class="sd"> word_length_variance = 1</span>
|
||||
<span class="sd">rplanguage.add_language(grammar=grammar, vowels=vowels, ...)</span>
|
||||
<span class="sd">```</span>
|
||||
|
||||
<span class="sd"> # if a proper noun (word starting with capitalized letter) should be</span>
|
||||
<span class="sd"> # translated or not. If not (default) it means e.g. names will remain</span>
|
||||
<span class="sd"> # unchanged across languages.</span>
|
||||
<span class="sd"> noun_translate = False</span>
|
||||
<span class="sd">The variables of `add_language` allows you to customize the "feel" of</span>
|
||||
<span class="sd">the semi-random language you are creating. Especially</span>
|
||||
<span class="sd">the `word_length_variance` helps vary the length of translated</span>
|
||||
<span class="sd">words compared to the original. You can also add your own</span>
|
||||
<span class="sd">dictionary and "fix" random words for a list of input words.</span>
|
||||
|
||||
<span class="sd"> # all proper nouns (words starting with a capital letter not at the beginning</span>
|
||||
<span class="sd"> # of a sentence) can have either a postfix or -prefix added at all times</span>
|
||||
<span class="sd"> noun_postfix = "'la"</span>
|
||||
<span class="sd">## Example</span>
|
||||
|
||||
<span class="sd"> # words in dict will always be translated this way. The 'auto_translations'</span>
|
||||
<span class="sd"> # is instead a list or filename to file with words to use to help build a</span>
|
||||
<span class="sd"> # bigger dictionary by creating random translations of each word in the</span>
|
||||
<span class="sd"> # list *once* and saving the result for subsequent use.</span>
|
||||
<span class="sd"> manual_translations = {"the":"y'e", "we":"uyi", "she":"semi", "he":"emi",</span>
|
||||
<span class="sd"> "you": "do", 'me':'mi','i':'me', 'be':"hy'e", 'and':'y'}</span>
|
||||
<span class="sd">Below is an example module creating "elvish", using "rounder" vowels and sounds:</span>
|
||||
|
||||
<span class="sd"> rplanguage.add_language(key="elvish", phonemes=phonemes, grammar=grammar,</span>
|
||||
<span class="sd"> word_length_variance=word_length_variance,</span>
|
||||
<span class="sd"> noun_translate=noun_translate,</span>
|
||||
<span class="sd"> noun_postfix=noun_postfix, vowels=vowels,</span>
|
||||
<span class="sd"> manual_translations=manual_translations,</span>
|
||||
<span class="sd"> auto_translations="my_word_file.txt")</span>
|
||||
<span class="sd">```python</span>
|
||||
<span class="sd"># vowel/consonant grammar possibilities</span>
|
||||
<span class="sd">grammar = ("v vv vvc vcc vvcc cvvc vccv vvccv vcvccv vcvcvcc vvccvvcc "</span>
|
||||
<span class="sd"> "vcvvccvvc cvcvvcvvcc vcvcvvccvcvv")</span>
|
||||
|
||||
<span class="sd"> ```</span>
|
||||
<span class="sd"># all not in this group is considered a consonant</span>
|
||||
<span class="sd">vowels = "eaoiuy"</span>
|
||||
|
||||
<span class="sd"> This will produce a decicively more "rounded" and "soft" language</span>
|
||||
<span class="sd"> than the default one. The few manual_translations also make sure</span>
|
||||
<span class="sd"> to make it at least look superficially "reasonable".</span>
|
||||
<span class="sd"># you need a representative of all of the minimal grammars here, so if a</span>
|
||||
<span class="sd"># grammar v exists, there must be atleast one phoneme available with only</span>
|
||||
<span class="sd"># one vowel in it</span>
|
||||
<span class="sd">phonemes = ("oi oh ee ae aa eh ah ao aw ay er ey ow ia ih iy "</span>
|
||||
<span class="sd"> "oy ua uh uw y p b t d f v t dh s z sh zh ch jh k "</span>
|
||||
<span class="sd"> "ng g m n l r w")</span>
|
||||
|
||||
<span class="sd"> The `auto_translations` keyword is useful, this accepts either a</span>
|
||||
<span class="sd"> list or a path to a file of words (one per line) to automatically</span>
|
||||
<span class="sd"> create fixed translations for according to the grammatical rules.</span>
|
||||
<span class="sd"> This allows to quickly build a large corpus of translated words</span>
|
||||
<span class="sd"> that never change (if this is desired).</span>
|
||||
<span class="sd"># how much the translation varies in length compared to the original. 0 is</span>
|
||||
<span class="sd"># smallest, higher values give ever bigger randomness (including removing</span>
|
||||
<span class="sd"># short words entirely)</span>
|
||||
<span class="sd">word_length_variance = 1</span>
|
||||
|
||||
<span class="sd"># if a proper noun (word starting with capitalized letter) should be</span>
|
||||
<span class="sd"># translated or not. If not (default) it means e.g. names will remain</span>
|
||||
<span class="sd"># unchanged across languages.</span>
|
||||
<span class="sd">noun_translate = False</span>
|
||||
|
||||
<span class="sd"># all proper nouns (words starting with a capital letter not at the beginning</span>
|
||||
<span class="sd"># of a sentence) can have either a postfix or -prefix added at all times</span>
|
||||
<span class="sd">noun_postfix = "'la"</span>
|
||||
|
||||
<span class="sd"># words in dict will always be translated this way. The 'auto_translations'</span>
|
||||
<span class="sd"># is instead a list or filename to file with words to use to help build a</span>
|
||||
<span class="sd"># bigger dictionary by creating random translations of each word in the</span>
|
||||
<span class="sd"># list *once* and saving the result for subsequent use.</span>
|
||||
<span class="sd">manual_translations = {"the":"y'e", "we":"uyi", "she":"semi", "he":"emi",</span>
|
||||
<span class="sd"> "you": "do", 'me':'mi','i':'me', 'be':"hy'e", 'and':'y'}</span>
|
||||
|
||||
<span class="sd">rplanguage.add_language(key="elvish", phonemes=phonemes, grammar=grammar,</span>
|
||||
<span class="sd"> word_length_variance=word_length_variance,</span>
|
||||
<span class="sd"> noun_translate=noun_translate,</span>
|
||||
<span class="sd"> noun_postfix=noun_postfix, vowels=vowels,</span>
|
||||
<span class="sd"> manual_translations=manual_translations,</span>
|
||||
<span class="sd"> auto_translations="my_word_file.txt")</span>
|
||||
|
||||
<span class="sd">```</span>
|
||||
|
||||
<span class="sd">This will produce a decicively more "rounded" and "soft" language</span>
|
||||
<span class="sd">than the default one. The few manual_translations also make sure</span>
|
||||
<span class="sd">to make it at least look superficially "reasonable".</span>
|
||||
|
||||
<span class="sd">The `auto_translations` keyword is useful, this accepts either a</span>
|
||||
<span class="sd">list or a path to a file of words (one per line) to automatically</span>
|
||||
<span class="sd">create fixed translations for according to the grammatical rules.</span>
|
||||
<span class="sd">This allows to quickly build a large corpus of translated words</span>
|
||||
<span class="sd">that never change (if this is desired).</span>
|
||||
|
||||
<span class="sd">"""</span>
|
||||
<span class="kn">import</span> <span class="nn">re</span>
|
||||
<span class="kn">from</span> <span class="nn">random</span> <span class="kn">import</span> <span class="n">choice</span><span class="p">,</span> <span class="n">randint</span>
|
||||
<span class="kn">from</span> <span class="nn">collections</span> <span class="kn">import</span> <span class="n">defaultdict</span>
|
||||
<span class="kn">from</span> <span class="nn">random</span> <span class="kn">import</span> <span class="n">choice</span><span class="p">,</span> <span class="n">randint</span>
|
||||
|
||||
<span class="kn">from</span> <span class="nn">evennia</span> <span class="kn">import</span> <span class="n">DefaultScript</span>
|
||||
<span class="kn">from</span> <span class="nn">evennia.utils</span> <span class="kn">import</span> <span class="n">logger</span>
|
||||
|
||||
|
||||
<span class="c1"># ------------------------------------------------------------</span>
|
||||
<span class="c1">#</span>
|
||||
<span class="c1"># Obfuscate language</span>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue