public override bool FromScriptVariable(SequenceProcEnv environment, ScriptVariable variable, ref string errorMessage) { if (variable.IsNull()) { errorMessage = global::MotionDataHandler.Properties.Settings.Default.Msg_CannotSpecifyNull + ": " + this.ParamName; return(false); } this.Value = new Dictionary <string, string>(); IList <ScriptVariable> list = variable.ToList(); foreach (ScriptVariable row in list) { if (row.IsNull()) { continue; } IList <ScriptVariable> pair = row.ToList(); if (pair.Count < 2) { errorMessage = "各要素に二つの文字列が必要です"; return(false); } if (pair[0].IsNull() || pair[1].IsNull()) { errorMessage = "要素の文字列にnullを指定できません"; return(false); } this.Value[pair[0].ToString()] = pair[1].ToString(); } return(true); }
public override bool FromScriptVariable(SequenceProcEnv environment, ScriptVariable variable, ref string errorMessage) { IList <ScriptVariable> list = variable.ToList(); SequenceData parent = environment.SelectedSequence; if (this.Parent != null && this.Parent.Value != null) { parent = this.Parent.Value; } IList <string> borderNames = parent.Borders.GetLabelNames(true); List <string> ret = new List <string>(); foreach (ScriptVariable v in list) { string name = v.ToString(); if (!borderNames.Contains(name) && parent.Borders.DefaultName != name) { errorMessage = MotionDataHandler.Properties.Settings.Default.Msg_LabelNameNotFound + ": " + name; return(false); } ret.Add(name); } this.Value = ret; return(true); }
public override bool FromScriptVariable(SequenceProcEnv environment, ScriptVariable variable, ref string errorMessage) { SequenceData parent = environment.SelectedSequence; if (this.Parent != null && this.Parent.Value != null) { parent = this.Parent.Value; } IList <ScriptVariable> list = variable.ToList(); List <int> ret = new List <int>(); foreach (ScriptVariable v in list) { switch (v.Type) { case ScriptVariableType.Number: int index = v.ToInteger(); if (index < 0 || index >= parent.Values.ColumnCount) { errorMessage = MotionDataHandler.Properties.Settings.Default.Msg_IndexOutOfRange + ": " + index.ToString(); return(false); } ret.Add(index); break; case ScriptVariableType.String: string name = v.ToString(); int index2 = -1; for (int i = 0; i < parent.Values.ColumnNames.Length; i++) { if (parent.Values.ColumnNames[i] == name) { index2 = i; break; } } if (index2 == -1) { errorMessage = MotionDataHandler.Properties.Settings.Default.Msg_ColumnNameNotFound; return(false); } ret.Add(index2); return(true); default: errorMessage = MotionDataHandler.Properties.Settings.Default.Msg_SpecifyIndexOfColumnOrColumnName; return(false); } } this.Value = ret; return(true); }
public ScriptVariable Call(IList <ScriptVariable> args, ScriptConsole console) { ScriptVariable arg = null; if (args.Count >= 1) { arg = args[0]; } if (arg == null) { return(null); } return(new ListVariable(arg.ToList())); }
private ScriptVariable lengthOf(ScriptVariable arg) { if (arg.IsNull()) { return(null); } switch (arg.Type) { case ScriptVariableType.String: return(new NumberVariable(arg.ToString().Length)); case ScriptVariableType.List: return(new NumberVariable(arg.ToList().Count)); } return(null); }
public override bool FromScriptVariable(SequenceProcEnv environment, ScriptVariable variable, ref string errorMessage) { IList <ScriptVariable> list = variable.ToList(); List <SequenceData> sequences = new List <SequenceData>(); foreach (var str in list) { string name = str.ToString(); SequenceData sequence = environment.GetSequenceByTitle(name); if (sequence == null) { errorMessage = MotionDataHandler.Properties.Settings.Default.Msg_SequenceNotFound + ": " + name; return(false); } sequences.Add(sequence); } this.Value = sequences; return(true); }
public void Read(GameBoxReader r) { var classId = r.ReadUInt32(); Version = r.ReadInt32(); if (Version < 3) { return; } var typeCount = r.ReadByte(); var types = new ScriptVariable[typeCount]; for (var i = 0; i < typeCount; i++) { var varType = r.ReadByte(); types[i] = (ScriptType)varType switch { ScriptType.Array => ReadScriptArray(r), ScriptType.Struct => ReadScriptStruct(out int _, r), _ => new ScriptVariable((ScriptType)varType), }; } var varCount = r.ReadByte(); var metadata = new ScriptVariable[varCount]; for (var i = 0; i < varCount; i++) { var metadataVarName = r.ReadString(StringLengthPrefix.Byte); var typeIndex = r.ReadByte(); var type = types[typeIndex]; metadata[i] = ReadType(type.Clone(), r); metadata[i].Name = metadataVarName; } Metadata = metadata.ToList(); var facade = r.ReadUInt32(); }
public override bool FromScriptVariable(MotionProcEnv environment, ScriptVariable variable, ref string errorMessage) { IList <ScriptVariable> list = variable.ToList(); if (list.Count != 1) { errorMessage = MotionDataHandler.Properties.Settings.Default.Msg_SpecifyOneSequenceName; return(false); } var str = list[0]; string name = str.ToString(); Sequence.SequenceData sequence = environment.SequenceController.GetSequenceByTitle(name); if (sequence == null) { errorMessage = MotionDataHandler.Properties.Settings.Default.Msg_SequenceNotFound + ": " + name; return(false); } this.Value = sequence; return(true); }
protected override RunControlType ExecuteInternal(ScriptExecutionEnvironment env, out ScriptVariable returnValue) { returnValue = null; env.Variables.EnterScope(); try { env.Variables.Declare(this.Identifier, null, VariableStorage.FieldProperty.Default); ScriptVariable list = this.Enumerator.Calculate(env) ?? new ListVariable(); foreach (var tmp in list.ToList()) { env.Variables.Set(this.Identifier, tmp); RunControlType ctrl = this.Statement.Execute(env, out returnValue); if (ctrl == RunControlType.Break) { return(RunControlType.None); } if (ctrl == RunControlType.Return) { return(RunControlType.Return); } } } finally { env.Variables.ExitScope(); } return(RunControlType.None); }
public override bool FromScriptVariable(SequenceProcEnv environment, ScriptVariable variable, ref string errorMessage) { if (variable.IsNull()) { errorMessage = global::MotionDataHandler.Properties.Settings.Default.Msg_CannotSpecifyNull + ": " + this.ParamName; return(false); } IList <ScriptVariable> list = variable.ToList(); while (this.Value.Count <= list.Count) { this.Value.Add(0); } int index = 0; foreach (ScriptVariable row in list) { if (row.IsNull()) { this.Value[index] = 0; } else { decimal value = row.ToNumber(); this.Value[index] = value; } index++; } if (index < this.NumberOfArgs) { errorMessage = string.Format("{0} 個の数値が必要です", this.NumberOfArgs); return(false); } return(true); }
public void Read(GameBoxReader r) { var classId = r.ReadUInt32(); Version = r.ReadInt32(); var typeCount = r.ReadByte(); var types = new ScriptVariable[typeCount]; for (var i = 0; i < typeCount; i++) { var varType = r.ReadByte(); switch ((ScriptType)varType) { case ScriptType.Array: types[i] = ReadScriptArray(); break; case ScriptType.Struct: types[i] = ReadScriptStruct(out int defaultLength); break; default: types[i] = new ScriptVariable((ScriptType)varType); break; } } var varCount = r.ReadByte(); var metadata = new ScriptVariable[varCount]; for (var i = 0; i < varCount; i++) { var metadataVarName = r.ReadString(StringLengthPrefix.Byte); var typeIndex = r.ReadByte(); var type = types[typeIndex]; metadata[i] = ReadType(type.Clone()); metadata[i].Name = metadataVarName; } Metadata = metadata.ToList(); var facade = r.ReadUInt32(); ScriptArray ReadScriptArray() { ScriptVariable indexVar; var indexType = r.ReadByte(); // index if ((ScriptType)indexType == ScriptType.Struct) { indexVar = ReadScriptStruct(out int defaultLength); } else { indexVar = new ScriptVariable((ScriptType)indexType); } ScriptVariable valueVar; var arrayType = r.ReadByte(); // value if ((ScriptType)arrayType == ScriptType.Array) { valueVar = ReadScriptArray(); } else if ((ScriptType)arrayType == ScriptType.Struct) { valueVar = ReadScriptStruct(out int defaultLength); } else { valueVar = new ScriptVariable((ScriptType)arrayType); } ScriptArray array = new ScriptArray(new KeyValuePair <ScriptVariable, ScriptVariable>(indexVar, valueVar)); int counterArray = 0; while (r.ReadByte() == 0) { counterArray++; } r.BaseStream.Position -= 1; array.Unknown = counterArray; return(array); } ScriptStruct ReadScriptStruct(out int defaultLength) { var strc = new ScriptStruct(); var numMembers = r.ReadByte(); var structName = r.ReadString(); strc.StructName = structName; strc.Members = new ScriptVariable[numMembers]; defaultLength = 0; for (var i = 0; i < numMembers; i++) { ScriptVariable member; var memberName = r.ReadString(); var memberType = r.ReadByte(); switch ((ScriptType)memberType) { case ScriptType.Array: member = ReadScriptArray(); break; case ScriptType.Struct: member = ReadScriptStruct(out int defLength); defaultLength += defLength; break; default: member = new ScriptVariable((ScriptType)memberType); break; } switch (member.Type) { case ScriptType.Integer: r.ReadInt32(); defaultLength += 4; break; case ScriptType.Real: r.ReadSingle(); defaultLength += 4; break; case ScriptType.Vec2: r.ReadVec2(); defaultLength += 8; break; case ScriptType.Vec3: r.ReadVec3(); defaultLength += 12; break; case ScriptType.Int3: r.ReadInt3(); defaultLength += 12; break; case ScriptType.Int2: r.ReadInt2(); defaultLength += 8; break; case ScriptType.Array: break; case ScriptType.Struct: break; default: r.ReadByte(); defaultLength += 1; break; } member.Name = memberName; strc.Members[i] = member; } int counter = 0; while (r.ReadByte() == 0) { counter++; } r.BaseStream.Position -= 1; //int counter = 0; //while (r.ReadByte() == 0) counter++; // probably size of the struct in byte count? //r.BaseStream.Position -= 1; strc.Size = defaultLength + counter; // strc.Unknown = counter; //Progress += defaultLength; return(strc); } ScriptVariable ReadType(ScriptVariable type) { switch (type.Type) { case ScriptType.Boolean: type.Value = Convert.ToBoolean(r.ReadBoolean(true)); break; case ScriptType.Integer: type.Value = r.ReadInt32(); break; case ScriptType.Real: type.Value = r.ReadSingle(); break; case ScriptType.Text: type.Value = r.ReadString(StringLengthPrefix.Byte); break; case ScriptType.Vec2: type.Value = r.ReadVec2(); break; case ScriptType.Vec3: type.Value = r.ReadVec3(); break; case ScriptType.Int3: type.Value = r.ReadInt3(); break; case ScriptType.Int2: type.Value = r.ReadInt2(); break; case ScriptType.Array: var array = type as ScriptArray; var numElements = r.ReadByte(); if (numElements > 0) { ScriptVariable key; if (array.Reference.Key.Type == ScriptType.Void) { for (var i = 0; i < numElements; i++) { array.Elements[new ScriptVariable(ScriptType.Void) { Value = i }] = ReadType(array.Reference.Value.Clone()); } } else { key = ReadType(array.Reference.Key.Clone()); for (var i = 0; i < numElements; i++) { array.Elements[key] = ReadType(array.Reference.Value.Clone()); } } } break; case ScriptType.Struct: var strc = type as ScriptStruct; for (var i = 0; i < strc.Members.Length; i++) { strc.Members[i] = ReadType(strc.Members[i]); } break; default: throw new Exception(type.Type.ToString()); } return(type); } }