From 060b99ab59d473f023811f89356b0818cb6f935b Mon Sep 17 00:00:00 2001 From: Zergling_man Date: Mon, 2 Jan 2023 23:36:34 +1100 Subject: [PATCH] init commit --- codegen.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/codegen.py b/codegen.py index 9946afb..14e2b98 100644 --- a/codegen.py +++ b/codegen.py @@ -123,15 +123,20 @@ def generate(officer=None): rank,cap=min(rank,pro[n[2]][ind][0]),min(cap,pro[n[2]][ind][1]) out.append(ind) cap=(cap-(cap<10)+(cap>10))//3 # Derp - if gun: out.insert(1,lookup_piece(gun,displays.guns)) + if gun: out.insert(1,lookup_piece(gun,tables.guns,True)) else: out.insert(1,tables.gunmaps_wrapped[out[0]]) out[-1]=tables.clas[out[0]].index(out[-1]) return encode.encode(active_profile,*out,rank,cap) -def lookup_piece(piece,table): +def lookup_piece(piece,table,partial=False): if len(piece)<3: p=piece.upper() else: p=piece.capitalize() # Bloody Americans - return table.index(p) + if not partial: + try: return table.index(p) + except ValueError: return None + res=list(filter(lambda x:x.startswith(p),table)) + if len(res)!=1: return None # Ambiguous lookups not allowed + return table.index(res[0]) def ranks(): for n,m in zip(tables.displays_str,tables.displays):