private void SetupMapObjects() { var mapObjects = _tiledMap.getObjectGroup(TiledObjects.ObjectGroup); SetupCollisions(mapObjects); SetupPits(mapObjects); SetupItemSpawners(mapObjects); SetupPlayerSpawns(mapObjects); SetupMapEvents(mapObjects); foreach (var lightSource in mapObjects.objectsWithName("light_source")) { var entity = scene.createEntity("world-light", lightSource.position + new Vector2(8, 8)); entity.setScale(0.5f); var sprite = entity.addComponent(new Sprite(AssetLoader.GetTexture("effects/lightmask_xs"))); sprite.material = Material.blendLinearDodge(); sprite.color = ColorExt.hexToColor("#" + lightSource.properties["color"].Substring(2)); sprite.renderLayer = Layers.Lights; var props = lightSource.properties; if (props.ContainsKey("toggle_key") && !string.IsNullOrWhiteSpace(props["toggle_key"])) { var listener = entity.addComponent(new MapEventListener(props["toggle_key"]) { EventTriggered = _ => { entity.setEnabled(!entity.enabled); } }); MapEventListeners.Add(listener); } } }
Dictionary <string, Color> parseColors(JObject colors) { if (colors.Count == 0) { return(null); } var result = new Dictionary <string, Color>(colors.Count); foreach (JProperty key in colors.Children()) { var obj = colors[key.Name]; UISkinImporter.logger.LogMessage("adding color: {0}", key.Name); if (obj is JValue) { var jVal = obj as JValue; var val = jVal.Value as string; // we could have hex or hex if (val.StartsWith("#")) { result.Add(key.Name, ColorExt.hexToColor(val.Substring(1))); } else if (val.StartsWith("0x")) { result.Add(key.Name, ColorExt.hexToColor(val.Substring(2))); } else { UISkinImporter.logger.LogMessage("unsupported color definition {0}: {1}", key.Name, val); } } else if (obj is JArray) { var jArr = obj as JArray; var arr = jArr.ToObject <int[]>(); result.Add(key.Name, new Color(arr[0], arr[1], arr[2], arr[3])); } } UISkinImporter.logger.LogMessage(""); return(result); }
Dictionary <string, Color> parseColors(Dictionary <string, object> colors) { if (colors.Count == 0) { return(null); } var result = new Dictionary <string, Color>(colors.Count); foreach (var key in colors.Keys) { var obj = colors[key]; UISkinImporter.logger.LogMessage("adding color: {0}", key); Color color; // Allow the passing of strings (hex), arrays and objects (r:, g:, b:) to // represent colors. Also detect the usage of integers or normalized floats if (obj is string) { var val = obj as string; // we could have hex or hex if (val.StartsWith("#")) { color = ColorExt.hexToColor(val.Substring(1)); } else if (val.StartsWith("0x")) { color = ColorExt.hexToColor(val.Substring(2)); } else { UISkinImporter.logger.LogMessage("unsupported color definition {0}: {1}", key, val); continue; } } else if (obj is JArray) { var jArr = obj as JArray; if (jArr.Count < 3) { UISkinImporter.logger.LogMessage("unsupported color definition {0}: color array requires at least 3 members", key); continue; } if (jArr[0].Type == JTokenType.Integer) { var arr = jArr.ToObject <int[]>(); color = new Color(arr[0], arr[1], arr[2]); if (arr.Length == 4) { color = new Color(color, arr[3]); } } else if (jArr[0].Type == JTokenType.Float) { var arr = jArr.ToObject <float[]>(); color = new Color(arr[0], arr[1], arr[2]); if (arr.Length == 4) { color = new Color(color, arr[3]); } } else { UISkinImporter.logger.LogMessage("unsupported color definition {0}: unknown type", key); continue; } } else if (obj is Dictionary <string, object> ) { var dict = obj as Dictionary <string, object>; if (dict.Count < 3) { UISkinImporter.logger.LogMessage("unsupported color definition {0}: color object requires at least 3 members", key); continue; } if (dict["r"] is long) { color = new Color(Convert.ToInt32(dict["r"]), Convert.ToInt32(dict["g"]), Convert.ToInt32(dict["b"])); if (dict.Count == 4) { color = new Color(color, Convert.ToInt32(dict["a"])); } } else if (dict["r"] is double) { color = new Color(Convert.ToSingle(dict["r"]), Convert.ToSingle(dict["g"]), Convert.ToSingle(dict["b"])); if (dict.Count == 4) { color = new Color(color, Convert.ToSingle(dict["a"])); } } } result.Add(key, color); } UISkinImporter.logger.LogMessage(""); return(result); }