public void UnpackEvent(Event evt, StringBuilder code, bool compatibilityMode = false) { CurrentEventID = (int)evt.ID; string id = evt.ID.ToString(); string restBehavior = evt.RestBehavior.ToString(); Dictionary <Parameter, string> paramNames = ParamNames(evt); IEnumerable <string> argNameList = paramNames.Values.Distinct(); string evtArgs = string.Join(", ", argNameList); string eventName = EventName(evt.ID); if (eventName != null) { code.AppendLine($"// {eventName}"); } code.AppendLine($"Event({id}, {restBehavior}, function({evtArgs}) {{"); for (int insIndex = 0; insIndex < evt.Instructions.Count; insIndex++) { CurrentInsIndex = insIndex; Instruction ins = evt.Instructions[insIndex]; EMEDF.InstrDoc doc = docs.DOC[ins.Bank]?[ins.ID]; if (doc == null) { StringBuilder sb = new StringBuilder(); sb.AppendLine($@"Unable to read instruction at Event {CurrentEventID}, Index {CurrentInsIndex}."); sb.AppendLine($@"Unknown instruction id: {InstructionDocs.InstrDebugString(ins)}"); throw new Exception(sb.ToString()); } string funcName = doc.DisplayName; List <object> args; try { args = docs.UnpackArgsWithParams(ins, insIndex, doc, paramNames, (argDoc, val) => argDoc.GetDisplayValue(val), compatibilityMode); } catch (Exception ex) { var sb = new StringBuilder(); sb.AppendLine($@"Unable to unpack arguments for {funcName}({InstructionDocs.InstrDocDebugString(doc)}) at Event {CurrentEventID}, Index {CurrentInsIndex}."); sb.AppendLine($@"Instruction arg data: {InstructionDocs.InstrDebugString(ins)}"); sb.AppendLine(ex.Message); throw new Exception(sb.ToString()); } if (ins.Layer.HasValue) { args.Add(InstructionDocs.LayerString(ins.Layer.Value)); } string lineOfCode = $"{doc.DisplayName}({string.Join(", ", args)});"; code.AppendLine("\t" + lineOfCode); } code.AppendLine("});"); code.AppendLine(""); CurrentInsIndex = -1; CurrentEventID = -1; }
public override string ToString() => InstructionDocs.LayerString(Mask);