def _proto(**kwargs): return disdict(kwargs, ';')
def _protoDecoder(specProto, stateProto): nil = lambda s: {} f = disdict(specProto, ';') if specProto else nil g = disdict(stateProto, ';') if stateProto else nil return lambda spec, state: {**f(spec), **g(state)}
def _tabProto(**kwargs): return disdict(kwargs, '\t')
dict(trailKey=keyStroke, menuCommand=str, initiallyVisible=boolish, globallyVisible=boolish, circleRadius=int, fillColor=rgbColor, lineColor=rgbColor, selectedTransparency=int, unSelectedTransparency=int, edgePointBuffer=int, edgeDisplayBuffer=int, lineWidth=float), dict(globalVisibility=boolish, startMapId=str, numPoints=int, points=varargs(disdict(dict(x=int, y=int), ',')))), # counters.Labeler label=_protoDecoder( dict( labelKey=keyStroke, menuCommand=str, fontSize=int, textBg=rgbColor, textFg=rgbColor, verticalPos=valign, verticalOffset=int, horizontalPos=halign, horizontalOffset=int, verticalJust=valign, horizontalJust=halign, nameFormat=str,
typ, *vs = disconcat(cmd, '\t') d = _noteTypes.get(typ) assert d, "Uncrecognized note type {:s} in {:s}".format(typ, s) note = dict(type=d['type']) if vs and vs[0]: note.update(seqdict(d['proto'], vs)) notes[typ] = note return notes _componentDecoders = dict( # module/map/BoardPicker BoardPicker=_tabProto(id=str, name=str, x=int, y=int), #TODO name can be optional name/rev # module/turn/TurnTracker.java #TODO parse level state TurnTracker=_tabProto(id=str, levels=varargs(disdict(dict(turn=int, state=str), '|'))), NOTE=noteDecoder ) def decodeComponent(state): cmd = disconcat(state, COMMAND_SEPARATOR)[0] id = disconcat(cmd, '\t')[0] result = dict(state=state) for kind, decoder in _componentDecoders.items(): if kind in id: result = dict(kind=kind) try: result.update(decoder(state)) except: print('Failed to parse state for {!s}: {:s}'.format(result, state))