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:
CaitSith2 2021-03-28 16:52:32 -07:00
parent ef15fd2ed8
commit 9233a7e208
3 changed files with 25 additions and 16 deletions

View File

@ -6,6 +6,7 @@ import urllib.parse
import typing import typing
import os import os
from collections import Counter from collections import Counter
import string
import ModuleUpdate import ModuleUpdate
from BaseClasses import PlandoItem, PlandoConnection from BaseClasses import PlandoItem, PlandoConnection
@ -217,15 +218,7 @@ def main(args=None, callback=ERmain):
erargs.name[player] = f"Player{player}" erargs.name[player] = f"Player{player}"
elif not erargs.name[player]: # if name was not specified, generate it from filename 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] erargs.name[player] = os.path.splitext(os.path.split(path)[-1])[0]
new_name = [] erargs.name[player] = handle_name(erargs.name[player], player, name_counter)
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))
logging.info(erargs.name[player]) logging.info(erargs.name[player])
erargs.names = ",".join(erargs.name[i] for i in range(1, args.multi + 1)) erargs.names = ",".join(erargs.name[i] for i in range(1, args.multi + 1))
del (erargs.name) 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.") raise RuntimeError(f"All options specified in \"{option}\" are weighted as zero.")
def handle_name(name: str): class SafeDict(dict):
return name.strip().replace(' ', '_')[:16] 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]: def prefer_int(input_data: str) -> typing.Union[str, int]:

View File

@ -3,12 +3,14 @@ import tempfile
import random import random
import zlib import zlib
import json import json
from collections import Counter
from flask import request, flash, redirect, url_for, session, render_template from flask import request, flash, redirect, url_for, session, render_template
from EntranceRandomizer import parse_arguments from EntranceRandomizer import parse_arguments
from Main import main as ERmain from Main import main as ERmain
from Main import get_seed, seeddigits from Main import get_seed, seeddigits
from Mystery import handle_name
import pickle import pickle
from .models import * from .models import *
@ -82,13 +84,15 @@ def gen_game(gen_options, race=False, owner=None, sid=None):
erargs.progression_balancing = {} erargs.progression_balancing = {}
erargs.create_diff = True erargs.create_diff = True
name_counter = Counter()
for player, (playerfile, settings) in enumerate(gen_options.items(), 1): for player, (playerfile, settings) in enumerate(gen_options.items(), 1):
for k, v in settings.items(): for k, v in settings.items():
if v is not None: if v is not None:
getattr(erargs, k)[player] = v getattr(erargs, k)[player] = v
if not erargs.name[player]: 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)) erargs.names = ",".join(erargs.name[i] for i in range(1, playercount + 1))
del (erargs.name) del (erargs.name)

View File

@ -18,10 +18,11 @@
# http://www.yamllint.com/ # http://www.yamllint.com/
description: Template Name # Used to describe your yaml. Useful if you have multiple files 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 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. #{player} will be replaced with the player's slot number.
#%number% will be replaced with the counter value of the name. #{PLAYER} will be replaced with the player's slot number if that slot number is greater than 1.
#%% will become % after all of the above processing is complete on the name. #{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 ### ### Logic Section ###
# Warning: overworld_glitches is not available and minor_glitches is only partially implemented on the door-rando version # 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 glitches_required: # Determine the logic required to complete the seed