Error reporting is better now.
This commit is contained in:
parent
5c6582628d
commit
2ac4e42645
22
codegen.py
22
codegen.py
|
@ -133,30 +133,35 @@ def generate(officer=None,name=None):
|
||||||
out=[]
|
out=[]
|
||||||
if len(pieces)==6: rank=cap=int(pieces.pop(-1))
|
if len(pieces)==6: rank=cap=int(pieces.pop(-1))
|
||||||
else: rank,cap=12,12
|
else: rank,cap=12,12
|
||||||
|
try:
|
||||||
for n in zip(pieces,tables.displays_nogun,tables.displays_nogun_str):
|
for n in zip(pieces,tables.displays_nogun,tables.displays_nogun_str):
|
||||||
ind=lookup_piece(n[0],n[1])
|
ind=lookup_piece(n[0],n[1],n[2])
|
||||||
rank,cap=min(rank,pro[n[2]][ind][0]),min(cap,pro[n[2]][ind][1])
|
rank,cap=min(rank,pro[n[2]][ind][0]),min(cap,pro[n[2]][ind][1])
|
||||||
|
if 0 in [rank,cap]: print(f"{n[0]} is locked, go unlock it first.")
|
||||||
out.append(ind)
|
out.append(ind)
|
||||||
if gun: out.insert(1,lookup_piece(gun,tables.guns,True))
|
if gun: out.insert(1,lookup_piece(gun,tables.guns,'guns',True))
|
||||||
else: out.insert(1,tables.gunmaps_wrapped[out[0]])
|
else: out.insert(1,tables.gunmaps_wrapped[out[0]])
|
||||||
|
except LookupException as ex: print(ex); return
|
||||||
rank,cap=min(rank,pro['guns'][out[1]][0]),min(cap,pro['guns'][out[1]][1]) # Derp2, forgot to actually cap on gun
|
rank,cap=min(rank,pro['guns'][out[1]][0]),min(cap,pro['guns'][out[1]][1]) # Derp2, forgot to actually cap on gun
|
||||||
|
if 0 in [rank,cap]: return # Already warned about locks earlier.
|
||||||
cap=(cap-(cap<10)+(cap>10))//3 # Derp
|
cap=(cap-(cap<10)+(cap>10))//3 # Derp
|
||||||
if rank<1 or cap<0: print("You have selected a locked item, go unlock it first."); return
|
try: out[-1]=tables.clas[out[0]].index(out[-1])
|
||||||
out[-1]=tables.clas[out[0]].index(out[-1])
|
except ValueError: print(f"{tables.classes[out[0]]} can't get talent {tables.talent[out[-1]]}, options are {list(map(lambda x:tables.talent[x],tables.clas[out[0]]))}"); return
|
||||||
muxed=shared.muxhero(out[0],out[3],out[4])
|
muxed=shared.muxhero(out[0],out[3],out[4])
|
||||||
meds=[]
|
meds=[]
|
||||||
if muxed in pro['medals']: meds=shared.muxmedals(pro['medals'][muxed])
|
if muxed in pro['medals']: meds=shared.muxmedals(pro['medals'][muxed])
|
||||||
return encode.encode(name,*out,rank,cap,0,*meds)
|
return encode.encode(name,*out,rank,cap,0,*meds)
|
||||||
|
|
||||||
def lookup_piece(piece,table,partial=False):
|
def lookup_piece(piece,table,name,partial=False):
|
||||||
if len(piece)<3: p=piece.upper()
|
if len(piece)<3: p=piece.upper()
|
||||||
else: p=piece.capitalize() # Bloody Americans
|
else: p=piece.capitalize() # Bloody Americans
|
||||||
if not partial:
|
if not partial:
|
||||||
try: return table.index(p)
|
try: return table.index(p)
|
||||||
except ValueError: return None
|
except ValueError: raise LookupException(f"Couldn't resolve {piece} from {name}")
|
||||||
res=list(filter(lambda x:x.startswith(p),table))
|
res=list(filter(lambda x:p in x,table))
|
||||||
if len(res)!=1: return None # Ambiguous lookups not allowed
|
if len(res)!=1: raise LookupException(f"Couldn't resolve {piece} with partial match from {name} (found {len(res)} possibilities)") # Ambiguous lookups not allowed
|
||||||
return table.index(res[0])
|
return table.index(res[0])
|
||||||
|
class LookupException(Exception): pass
|
||||||
|
|
||||||
def ranks():
|
def ranks():
|
||||||
for n,m in zip(tables.displays_str,tables.displays):
|
for n,m in zip(tables.displays_str,tables.displays):
|
||||||
|
@ -167,4 +172,5 @@ def ranks():
|
||||||
|
|
||||||
load_conf()
|
load_conf()
|
||||||
|
|
||||||
|
|
||||||
if __name__=="__main__": print("Please open an interpreter and use 'import codegen', this script doesn't serve as an entrypoint on its own yet.")
|
if __name__=="__main__": print("Please open an interpreter and use 'import codegen', this script doesn't serve as an entrypoint on its own yet.")
|
||||||
|
|
Loading…
Reference in New Issue
Block a user