name variable changes
* Convert %number%, %player% and %% to {number}, {player} and %. * added {NUMBER} - output number if greater than 1. * added {PLAYER}, output player slot number if greater than 1.
This commit is contained in:
parent
ef15fd2ed8
commit
9233a7e208
26
Mystery.py
26
Mystery.py
|
@ -6,6 +6,7 @@ import urllib.parse
|
|||
import typing
|
||||
import os
|
||||
from collections import Counter
|
||||
import string
|
||||
|
||||
import ModuleUpdate
|
||||
from BaseClasses import PlandoItem, PlandoConnection
|
||||
|
@ -217,15 +218,7 @@ def main(args=None, callback=ERmain):
|
|||
erargs.name[player] = f"Player{player}"
|
||||
elif not erargs.name[player]: # if name was not specified, generate it from filename
|
||||
erargs.name[player] = os.path.splitext(os.path.split(path)[-1])[0]
|
||||
new_name = []
|
||||
name_counter[erargs.name[player]] += 1
|
||||
for name in erargs.name[player].split("%%"):
|
||||
if "%number%" in name:
|
||||
name = name.replace("%number%", str(name_counter[erargs.name[player]]))
|
||||
if "%player%" in name:
|
||||
name = name.replace("%player%", str(player))
|
||||
new_name.append(name)
|
||||
erargs.name[player] = handle_name("%".join(new_name))
|
||||
erargs.name[player] = handle_name(erargs.name[player], player, name_counter)
|
||||
logging.info(erargs.name[player])
|
||||
erargs.names = ",".join(erargs.name[i] for i in range(1, args.multi + 1))
|
||||
del (erargs.name)
|
||||
|
@ -295,8 +288,19 @@ def get_choice(option, root, value=None) -> typing.Any:
|
|||
raise RuntimeError(f"All options specified in \"{option}\" are weighted as zero.")
|
||||
|
||||
|
||||
def handle_name(name: str):
|
||||
return name.strip().replace(' ', '_')[:16]
|
||||
class SafeDict(dict):
|
||||
def __missing__(self, key):
|
||||
return '{' + key + '}'
|
||||
|
||||
|
||||
def handle_name(name: str, player: int, name_counter: Counter):
|
||||
name_counter[name] += 1
|
||||
new_name = "%".join([x.replace("%number%", "{number}").replace("%player%", "{player}") for x in name.split("%%")])
|
||||
new_name = string.Formatter().vformat(new_name, (), SafeDict(number=name_counter[name],
|
||||
NUMBER=(name_counter[name] if name_counter[name] > 1 else ''),
|
||||
player=player,
|
||||
PLAYER=(player if player > 1 else '')))
|
||||
return new_name.strip().replace(' ', '_')[:16]
|
||||
|
||||
|
||||
def prefer_int(input_data: str) -> typing.Union[str, int]:
|
||||
|
|
|
@ -3,12 +3,14 @@ import tempfile
|
|||
import random
|
||||
import zlib
|
||||
import json
|
||||
from collections import Counter
|
||||
|
||||
from flask import request, flash, redirect, url_for, session, render_template
|
||||
|
||||
from EntranceRandomizer import parse_arguments
|
||||
from Main import main as ERmain
|
||||
from Main import get_seed, seeddigits
|
||||
from Mystery import handle_name
|
||||
import pickle
|
||||
|
||||
from .models import *
|
||||
|
@ -82,13 +84,15 @@ def gen_game(gen_options, race=False, owner=None, sid=None):
|
|||
erargs.progression_balancing = {}
|
||||
erargs.create_diff = True
|
||||
|
||||
name_counter = Counter()
|
||||
for player, (playerfile, settings) in enumerate(gen_options.items(), 1):
|
||||
for k, v in settings.items():
|
||||
if v is not None:
|
||||
getattr(erargs, k)[player] = v
|
||||
|
||||
if not erargs.name[player]:
|
||||
erargs.name[player] = os.path.split(playerfile)[-1].split(".")[0]
|
||||
erargs.name[player] = os.path.splitext(os.path.split(playerfile)[-1])[0]
|
||||
erargs.name[player] = handle_name(erargs.name[player], player, name_counter)
|
||||
|
||||
erargs.names = ",".join(erargs.name[i] for i in range(1, playercount + 1))
|
||||
del (erargs.name)
|
||||
|
|
|
@ -18,10 +18,11 @@
|
|||
# http://www.yamllint.com/
|
||||
|
||||
description: Template Name # Used to describe your yaml. Useful if you have multiple files
|
||||
name: YourName%number% # Your name in-game. Spaces will be replaced with underscores and there is a 16 character limit
|
||||
#%player% will be replaced with actual player number.
|
||||
#%number% will be replaced with the counter value of the name.
|
||||
#%% will become % after all of the above processing is complete on the name.
|
||||
name: YourName{number} # Your name in-game. Spaces will be replaced with underscores and there is a 16 character limit
|
||||
#{player} will be replaced with the player's slot number.
|
||||
#{PLAYER} will be replaced with the player's slot number if that slot number is greater than 1.
|
||||
#{number} will be replaced with the counter value of the name.
|
||||
#{NUMBER} will be replaced with the counter value of the name if the counter value is greater than 1.
|
||||
### Logic Section ###
|
||||
# Warning: overworld_glitches is not available and minor_glitches is only partially implemented on the door-rando version
|
||||
glitches_required: # Determine the logic required to complete the seed
|
||||
|
|
Loading…
Reference in New Issue