public ScriptValue Call(ScriptValue thisObject, ScriptValue[] args, int length) { var obj = args[0].valueType == ScriptValue.scriptValueType ? args[0].scriptValue : null; var map = new ScriptMap(m_script); if (obj is ScriptArray) { map.SetValue(ScriptConst.IteratorNext, m_script.CreateFunction(new ArrayPairs((ScriptArray)obj, map))); } else if (obj is ScriptMap) { map.SetValue(ScriptConst.IteratorNext, m_script.CreateFunction(new MapPairs((ScriptMap)obj, map))); } else if (obj is ScriptUserdata) { map.SetValue(ScriptConst.IteratorNext, m_script.CreateFunction(new UserdataPairs((ScriptUserdata)obj, map))); } else if (obj is ScriptInstance) { map.SetValue(ScriptConst.IteratorNext, m_script.CreateFunction(new InstancePairs((ScriptInstance)obj, map))); } else if (obj is ScriptType) { map.SetValue(ScriptConst.IteratorNext, m_script.CreateFunction(new TypePairs((ScriptType)obj, map))); } else if (obj is ScriptGlobal) { map.SetValue(ScriptConst.IteratorNext, m_script.CreateFunction(new GlobalPairs((ScriptGlobal)obj, map))); } else { throw new ExecutionException("pairs 必须用于 array, map, type, global 或者 继承 IEnumerable 的 userdata 类型"); } return(new ScriptValue(map)); }
public const double Epsilon = 1.401298E-45; //一个很小的浮点数 public static void Load(Script script) { var map = new ScriptMap(script); map.SetValue("PI", new ScriptValue(PI)); map.SetValue("Deg2Rad", new ScriptValue(Deg2Rad)); //角度转弧度 角度*此值=弧度 map.SetValue("Rad2Deg", new ScriptValue(Rad2Deg)); //弧度转角度 弧度*此值=角度 map.SetValue("Epsilon", new ScriptValue(Epsilon)); //一个很小的浮点数 map.SetValue("min", script.CreateFunction(new min())); //取最小值 map.SetValue("max", script.CreateFunction(new max())); //取最大值 map.SetValue("abs", script.CreateFunction(new abs())); //取绝对值 map.SetValue("floor", script.CreateFunction(new floor())); //向下取整 map.SetValue("ceil", script.CreateFunction(new ceil())); //向上取整 map.SetValue("round", script.CreateFunction(new round())); //四舍五入 map.SetValue("clamp", script.CreateFunction(new clamp())); //指定最大最小值取合适值 map.SetValue("sqrt", script.CreateFunction(new sqrt())); //开平方根 map.SetValue("pow", script.CreateFunction(new pow())); //幂运算 map.SetValue("log", script.CreateFunction(new log())); //返回指定数字的对数 //三角函数 map.SetValue("sin", script.CreateFunction(new sin())); // map.SetValue("sinh", script.CreateFunction(new sinh())); // map.SetValue("asin", script.CreateFunction(new asin())); // map.SetValue("cos", script.CreateFunction(new cos())); // map.SetValue("cosh", script.CreateFunction(new cosh())); // map.SetValue("acos", script.CreateFunction(new acos())); // map.SetValue("tan", script.CreateFunction(new tan())); // map.SetValue("tanh", script.CreateFunction(new tanh())); // map.SetValue("atan", script.CreateFunction(new atan())); // script.SetGlobal("math", new ScriptValue(map)); }
public void DrawnMapGeneration() { Color[] colourMap = new Color[mWidth * mHeight]; float[,] noiseMap = ScriptMap.NoiseMapGen(mWidth, mHeight, seed, octaves, lacunarity, persistance, scale, offset); for (int i = 0; i < mHeight; i++) { for (int j = 0; j < mWidth; j++) { float currentHeight = noiseMap[j, i]; for (int k = 0; k < terrains.Length; k++) { if (currentHeight <= terrains[k].terrainHeight) { colourMap[i * mWidth + j] = terrains[k].terrainColour; break; } } } } MapDisplayGen mapCanvas = FindObjectOfType <MapDisplayGen>(); if (drawMode == DrawMode.noiseMap) { mapCanvas.DrawTexMap(TextGen.textHeightMap(noiseMap)); } else if (drawMode == DrawMode.colourMap) { mapCanvas.DrawTexMap(TextGen.textColourMap(colourMap, mWidth, mHeight)); } }
const string Language = "Language"; //该字段是否有多国语言 //解析一个网络协议 // public static ScriptTable Deserialize(Script script, byte[] data, string layoutTableName) { // return Read(script, new ScorpioReader(data), null, "", layoutTableName, true); // } /// <summary> /// 脚本 读取excel文件数据内容 /// </summary> /// <param name="script">脚本引擎</param> /// <param name="fileName">文件名字</param> /// <param name="reader">文件读取</param> /// <param name="dataArray">数据集合</param> /// <param name="layoutTableName">布局</param> /// <param name="keyName">主key名字</param> /// <param name="MD5">文件结构MD5</param> /// <returns></returns> public static ScriptMap ReadDatas(string fileName, IScorpioReader reader, ScriptMap dataArray, string layoutTableName, string keyName, string MD5) { using (reader) { var script = dataArray.getScript(); var iRow = TableUtil.ReadHead(reader, fileName, MD5); //数据行数 var layout = script.Global.GetValue(layoutTableName).Get <ScriptArray>(); //数据结构 for (var i = 0; i < iRow; ++i) { var data = Read(script, reader, layout); //读取一行数据 var keyValue = data.GetValue(keyName); //获取key值 data.SetValue("ID", keyValue); var key = keyValue.Value; if (dataArray.ContainsKey(key)) { var value = dataArray.GetValue(key).Get <ScriptMap>(); foreach (var pair in data) { value.SetValue(pair.Key, pair.Value); } } else { dataArray.SetValue(key, new ScriptValue(data)); } } return(dataArray); } }
void btDelete_Click(object sender, RoutedEventArgs e) { ColumnMap.Remove(lineConfig.ColumnName); ScriptMap.Remove(lineConfig.ColumnName); root.Children.Remove(lineConfig.currentLine); lineConfig.Visibility = System.Windows.Visibility.Hidden; }
void line_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) { Line line = sender as Line; lineConfig.ColumnName = line.Tag.ToString(); lineConfig.currentLine = line; lineConfig.TransferScript.Text = ""; string transString = ""; // 判断这个类型的解析器是否存在 if (ScriptMap.ContainsKey(line.Tag.ToString())) { transString = ScriptMap[line.Tag.ToString()]; } if (string.IsNullOrEmpty(transString)) { transString = TRANSFER_SCRIPT; } lineConfig.TransferScript.Text = transString; lineConfig.Visibility = System.Windows.Visibility.Visible; }
private static ScriptMap ReadScript(GameFile script) { string scriptName = Path.GetFileNameWithoutExtension(script.Name); // Unzip script.SetFormat <Bokuract.Packs.GZip>(); script.Stream.Seek(0, SeekMode.Origin); script.Format.Read(); var unscript = script.Files[0] as GameFile; // and uncompress the blocks unscript.SetFormat <Bokuract.Packs.Pack>(new object[] { false }); unscript.Stream.Seek(0, SeekMode.Origin); unscript.Format.Read(); var dialogsFile = unscript.Files[1] as GameFile; // Parse each block dialogsFile.Stream.Seek(0, SeekMode.Origin); DataReader reader = new DataReader(dialogsFile.Stream); uint numBlocks = reader.ReadUInt32(); ScriptMap scriptMap = new ScriptMap(scriptName); scriptMap.Dialogs = new Dialog[numBlocks]; for (int i = 0; i < numBlocks; i++) { scriptMap.Dialogs[i] = ParseScript(dialogsFile.Stream, i); } return(scriptMap); }
public static void Load(Script script) { var protoString = script.TypeString; var map = new ScriptMap(script); map.SetValue("format", protoString.GetValue("format")); map.SetValue("cs_format", protoString.GetValue("csFormat")); map.SetValue("isnullorempty", protoString.GetValue("isNullOrEmpty")); map.SetValue("join", protoString.GetValue("join")); map.SetValue("length", script.CreateFunction(new length())); map.SetValue("substring", script.CreateFunction(new substring())); map.SetValue("tolower", script.CreateFunction(new toLower())); map.SetValue("toupper", script.CreateFunction(new toUpper())); map.SetValue("trim", script.CreateFunction(new trim())); map.SetValue("replace", script.CreateFunction(new replace())); map.SetValue("indexof", script.CreateFunction(new indexOf())); map.SetValue("lastindexof", script.CreateFunction(new lastIndexOf())); map.SetValue("startswith", script.CreateFunction(new startsWith())); map.SetValue("endswith", script.CreateFunction(new endsWith())); map.SetValue("contains", script.CreateFunction(new contains())); map.SetValue("split", script.CreateFunction(new split(script))); map.SetValue("at", script.CreateFunction(new at())); script.SetGlobal("string", new ScriptValue(map)); }
public static void Load(Script script) { var map = new ScriptMap(script); map.SetValue("fieldTypeOf", script.CreateFunction(new fieldTypeOf())); map.SetValue("isType", script.CreateFunction(new isType())); script.SetGlobal("userdata", new ScriptValue(map)); }
public static void Load(Script script) { var map = new ScriptMap(script); map.SetValue("encode", script.CreateFunction(new encode())); map.SetValue("decode", script.CreateFunction(new decode(script))); script.SetGlobal("json", new ScriptValue(map)); }
private void AddScriptMapToSite(ManagementScope scope, string siteId) { var scriptMap = new ScriptMap { Executable = @"c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll", Extension = ".mvc", }; AddScriptMapToSite(scope, siteId, scriptMap); }
void ParseClass(string name, ScriptMap table) { var classes = new PackageClass(); foreach (var pair in table) { var fieldName = pair.Key as string; if (string.IsNullOrEmpty(fieldName)) { throw new Exception($"Class:{name} Field:{fieldName} 参数出错 参数模版 \"[索引],[类型],[是否数组=false],[注释]\""); } var value = pair.Value.ToString(); var infos = value.Split(','); if (infos.Length < 2) { throw new Exception($"Class:{name} Field:{fieldName} 参数出错 参数模版 \"[索引],[类型],[是否数组=false],[注释]\""); } var packageField = new FieldClass(this) { Name = fieldName, Index = infos[0].ToInt32(), Type = infos[1], IsArray = infos.Length > 2 && infos[2].ToBoolean(), Comment = infos.Length > 3 ? infos[3] : "", }; if (!packageField.IsBasic) { if (!Script.HasGlobal(packageField.Type) && //判断网络协议自定义类 !Script.HasGlobal(ENUM_KEYWORD + packageField.Type) && //判断是否是枚举 !Script.HasGlobal(MESSAGE_KEYWORD + packageField.Type) && //判断网络协议自定义类 !Script.HasGlobal(TABLE_KEYWORD + packageField.Type) //判断Table内嵌类 ) { throw new Exception($"Class:{name} Field:{fieldName} 未知类型:{packageField.Type}"); } } classes.Fields.Add(packageField); } classes.Fields.Sort((m1, m2) => { return(m1.Index.CompareTo(m2.Index)); }); if (name.StartsWith(MESSAGE_KEYWORD)) //协议结构 { name = name.Substring(MESSAGE_KEYWORD.Length); Messages[name] = classes; } else if (name.StartsWith(TABLE_KEYWORD)) //table结构 { name = name.Substring(TABLE_KEYWORD.Length); Tables[name] = classes; } else { Classes[name] = classes; } classes.Name = name; }
public ScriptMap NamespaceMappings() { var result = ScriptMap.Constructor(null) as ScriptMap; foreach (var data in _nsmap) { result.Insert(ValueFactory.Create(data.Key), ValueFactory.Create(data.Value)); } return(result); }
public UserdataPairs(ScriptUserdata userdata, ScriptMap itorResult) { var ienumerable = userdata.Value as System.Collections.IEnumerable; if (ienumerable == null) { throw new ExecutionException("pairs 只支持继承 IEnumerable 的类"); } m_Enumerator = ienumerable.GetEnumerator(); m_ItorResult = itorResult; }
ScriptValue ParseMap() { var map = new ScriptMap(m_Script); var ret = new ScriptValue(map); while (true) { var ch = EatWhiteSpace; switch (ch) { case RIGHT_BRACE: return(ret); case COMMA: continue; case END_CHAR: throw new ExecutionException("Json解析, 未找到 map 结尾 [}]"); case QUOTES: { var key = ParseString(); if (EatWhiteSpace != ':') { throw new ExecutionException("Json解析, key值后必须跟 [:] 赋值"); } map.SetValue(key, ReadObject()); break; } case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': case '-': { --m_Index; var key = ParseNumber(); if (EatWhiteSpace != ':') { throw new ExecutionException("Json解析, key值后必须跟 [:] 赋值"); } map.SetValue(key, ReadObject()); break; } default: { throw new ExecutionException("Json解析, key值 未知符号 : " + ch); } } } }
public static void Load(Script script) { var map = new ScriptMap(script); map.SetValue("get", script.CreateFunction(new get())); map.SetValue("post", script.CreateFunction(new post())); map.SetValue("urlencode", script.CreateFunction(new urlencode())); map.SetValue("urldecode", script.CreateFunction(new urldecode())); map.SetValue("qpencode", script.CreateFunction(new qpencode())); map.SetValue("qpdecode", script.CreateFunction(new qpdecode())); script.SetGlobal("net", new ScriptValue(map)); }
public static void Load(Script script) { var map = new ScriptMap(script); map.SetValue("count", script.CreateFunction(new count())); map.SetValue("clear", script.CreateFunction(new clear())); map.SetValue("remove", script.CreateFunction(new remove())); map.SetValue("containskey", script.CreateFunction(new containskey())); map.SetValue("keys", script.CreateFunction(new keys())); map.SetValue("values", script.CreateFunction(new values())); script.SetGlobal("table", new ScriptValue(map)); }
public static void Load(Script script) { var map = new ScriptMap(script); map.SetValue("platform", script.CreateFunction(new platform())); map.SetValue("isWindows", script.CreateFunction(new isWindows())); map.SetValue("isLinux", script.CreateFunction(new isLinux())); map.SetValue("isOSX", script.CreateFunction(new isOSX())); map.SetValue("machineName", script.CreateFunction(new machineName())); map.SetValue("userName", script.CreateFunction(new userName())); map.SetValue("dotnetVersion", script.CreateFunction(new dotnetVersion())); map.SetValue("version", script.CreateFunction(new version())); map.SetValue("getEnvironmentVariable", script.CreateFunction(new getEnvironmentVariable())); map.SetValue("setEnvironmentVariable", script.CreateFunction(new setEnvironmentVariable())); map.SetValue("getFolderPath", script.CreateFunction(new getFolderPath())); map.SetValue("process", script.CreateFunction(new process(script))); script.SetGlobal("os", new ScriptValue(map)); }
private void AddScriptMapToSite(ManagementScope scope, string siteId, ScriptMap scriptMap) { var site = new ManagementObject(scope, new ManagementPath(String.Format(@"IIsWebVirtualDirSetting.Name=""W3SVC/{0}/root""", siteId)), null); var scriptMaps = (ManagementBaseObject[])site["ScriptMaps"]; var newScriptMaps = new ManagementBaseObject[scriptMaps.Length + 1]; scriptMaps.CopyTo(newScriptMaps, 0); ManagementObject newScriptMap = new ManagementClass(scope, new ManagementPath("ScriptMap"), null).CreateInstance(); newScriptMap["Extensions"] = scriptMap.Extension; newScriptMap["Flags"] = scriptMap.Flags; newScriptMap["IncludedVerbs"] = scriptMap.IncludedVerbs; newScriptMap["ScriptProcessor"] = scriptMap.Executable; newScriptMaps[newScriptMaps.Length - 1] = newScriptMap; site["ScriptMaps"] = newScriptMaps; site.Put(); }
void ParseConst(string name, ScriptMap table) { var consts = new PackageConst(); foreach (var pair in table) { var fieldName = pair.Key as string; if (string.IsNullOrEmpty(fieldName)) { throw new Exception($"Const:{name} Field:{fieldName} 参数出错"); } var value = pair.Value; var field = new FieldConst() { Name = fieldName }; switch (value.valueType) { case ScriptValue.longValueType: field.Type = BasicEnum.INT64; field.Value = value.longValue.ToString() + "L"; break; case ScriptValue.stringValueType: field.Type = BasicEnum.STRING; field.Value = "\"" + value.stringValue + "\""; break; case ScriptValue.doubleValueType: case ScriptValue.objectValueType: field.Type = BasicEnum.INT32; field.Value = value.ToString(); break; default: throw new Exception("不支持此常量类型 " + value.ValueTypeName); } consts.Fields.Add(field); } name = name.Substring(CONST_KEYWORD.Length); consts.Name = name; Consts[name] = consts; }
public static readonly long BaseTime = 621355968000000000; //1970, 1, 1, 0, 0, 0, DateTimeKind.Utc public static void Load(Script script) { var map = new ScriptMap(script); map.SetValue("unixNow", script.CreateFunction(new unixNow())); map.SetValue("toString", script.CreateFunction(new toString())); map.SetValue("toBytes", script.CreateFunction(new toBytes())); map.SetValue("readAll", script.CreateFunction(new readAll())); map.SetValue("writeAll", script.CreateFunction(new writeAll())); map.SetValue("readAllString", script.CreateFunction(new readAllString())); map.SetValue("writeAllString", script.CreateFunction(new writeAllString())); map.SetValue("fileExist", script.CreateFunction(new fileExist())); map.SetValue("pathExist", script.CreateFunction(new pathExist())); map.SetValue("createPath", script.CreateFunction(new createPath())); map.SetValue("deleteFile", script.CreateFunction(new deleteFile())); map.SetValue("deletePath", script.CreateFunction(new deletePath())); map.SetValue("getFiles", script.CreateFunction(new getFiles())); map.SetValue("getPaths", script.CreateFunction(new getPaths())); map.SetValue("workPath", script.CreateFunction(new workPath())); map.SetValue("lineArgs", script.CreateFunction(new lineArgs())); script.SetGlobal("io", new ScriptValue(map)); }
void ParseEnum(string name, ScriptMap table) { var enums = new PackageEnum(); foreach (var pair in table) { var fieldName = pair.Key as string; if (string.IsNullOrEmpty(fieldName)) { throw new Exception($"Enum:{name} Field:{fieldName} 参数出错"); } enums.Fields.Add(new FieldEnum() { Name = fieldName, Index = pair.Value.ToInt32(), }); } enums.Fields.Sort((m1, m2) => { return(m1.Index.CompareTo(m2.Index)); }); name = name.Substring(ENUM_KEYWORD.Length); enums.Name = name; Enums[name] = enums; }
public static void Load(Script script) { var map = new ScriptMap(script); map.SetValue("count", script.CreateFunction(new count())); map.SetValue("insert", script.CreateFunction(new insert())); map.SetValue("add", script.CreateFunction(new add())); map.SetValue("remove", script.CreateFunction(new remove())); map.SetValue("removeat", script.CreateFunction(new removeat())); map.SetValue("clear", script.CreateFunction(new clear())); map.SetValue("contains", script.CreateFunction(new contains())); map.SetValue("sort", script.CreateFunction(new sort())); map.SetValue("indexof", script.CreateFunction(new indexof())); map.SetValue("lastindexof", script.CreateFunction(new lastindexof())); map.SetValue("first", script.CreateFunction(new first())); map.SetValue("last", script.CreateFunction(new last())); map.SetValue("pop", script.CreateFunction(new popfirst())); map.SetValue("safepop", script.CreateFunction(new safepopfirst())); map.SetValue("popfirst", script.CreateFunction(new popfirst())); map.SetValue("safepopfirst", script.CreateFunction(new safepopfirst())); map.SetValue("poplast", script.CreateFunction(new poplast())); map.SetValue("safepoplast", script.CreateFunction(new safepoplast())); script.SetGlobal("array", new ScriptValue(map)); }
private void AddScriptMapToSite(ManagementScope scope, string siteId, ScriptMap scriptMap) { var site = new ManagementObject(scope, new ManagementPath(String.Format(@"IIsWebVirtualDirSetting.Name=""W3SVC/{0}/root""", siteId)), null); var scriptMaps = (ManagementBaseObject[]) site["ScriptMaps"]; var newScriptMaps = new ManagementBaseObject[scriptMaps.Length + 1]; scriptMaps.CopyTo(newScriptMaps, 0); ManagementObject newScriptMap = new ManagementClass(scope, new ManagementPath("ScriptMap"), null).CreateInstance(); newScriptMap["Extensions"] = scriptMap.Extension; newScriptMap["Flags"] = scriptMap.Flags; newScriptMap["IncludedVerbs"] = scriptMap.IncludedVerbs; newScriptMap["ScriptProcessor"] = scriptMap.Executable; newScriptMaps[newScriptMaps.Length - 1] = newScriptMap; site["ScriptMaps"] = newScriptMaps; site.Put(); }
public GlobalPairs(ScriptGlobal global, ScriptMap itorResult) { m_Enumerator = global.GetEnumerator(); m_ItorResult = itorResult; }
public ArrayPairs(ScriptArray array, ScriptMap itorResult) { m_Index = 0; m_Enumerator = array.GetEnumerator(); m_ItorResult = itorResult; }
public InstancePairs(ScriptInstance map, ScriptMap itorResult) { m_Enumerator = map.GetEnumerator(); m_ItorResult = itorResult; }
public TypePairs(ScriptType map, ScriptMap itorResult) { m_Enumerator = map.GetEnumerator(); m_ItorResult = itorResult; }