Example #1
0
        public void HandleTileAction(string[] commands, Farmer who, GameLocation location, string layer, Point position, Action <bool> callback)
        {
            var e = new CallingTileActionEventArgs(commands, who, location, layer, position, callback);


            if (e.Tile != null &&
                e.Tile.Properties.TryGetValue("@Action_Conditions", out PropertyValue conditions) &&
                !Plato.CheckConditions(conditions.ToString(), commands[0]))
            {
                return;
            }

            CallingTileAction?.Invoke(this, e);
        }
Example #2
0
        public AssetInjection(
            IPlatoHelper helper,
            string assetName,
            InjectionMethod method,
            string conditions = "")
        {
            Method            = method;
            Helper            = helper;
            AssetName         = assetName;
            Conditions        = conditions;
            MatchesConditions = true;

            if (HasConditions)
            {
                MatchesConditions = Helper.CheckConditions(Conditions, this);
            }
        }
        public void Edit <T>(IAssetData asset)
        {
            var mapAsset = asset.AsMap();
            var map      = mapAsset.Data;

            Func <Layer, bool> layerPredicate = (l) => l.Properties.TryGetValue(MapExtrasHandler.UseProperty, out PropertyValue value) &&
                                                value.ToString().Split(' ') is string[] p &&
                                                p.Length >= 2 &&
                                                (p[0] == "Merge" || p[0] == "Replace") &&
                                                (!l.Properties.TryGetValue(MapExtrasHandler.UseConditionProperty, out PropertyValue conditions) || Plato.CheckConditions(conditions.ToString(), l));


            if (!map.Layers.Any(layerPredicate))
            {
                return;
            }

            List <OrderedAction> actions = new List <OrderedAction>();

            map.Layers.Where(layerPredicate).ToList().ForEach((layer) =>
            {
                string[] p = layer.Properties[MapExtrasHandler.UseProperty].ToString().Split(' ');

                int order = layer.Properties.TryGetValue(UseOrderProperty, out PropertyValue value) && int.TryParse(value.ToString(), out int o) ? o : (p[0] == "Replace" && p.Length < 6) ? 0 : 1;

                Layer original = map.GetLayer(p[1]);

                if (p[0] == "Replace" && p.Length < 6)
                {
                    actions.Add(new OrderedAction(order, () => ReplaceLayer(map, layer, original)));
                }
                else
                {
                    actions.Add(new OrderedAction(order, () => MergeLayer(map, layer, original,
                                                                          p.Length > 5 &&
                                                                          int.TryParse(p[2], out int x) &&
                                                                          int.TryParse(p[3], out int y) &&
                                                                          int.TryParse(p[4], out int w) &&
                                                                          int.TryParse(p[5], out int h)
                        ? new Rectangle?(new Rectangle(x, y, w, h)) : null, p[0] == "Merge")));
                }
            });

            actions.OrderBy(a => a.Order).ToList().ForEach(a => a.Call());

            mapAsset.ReplaceWith(map);
        }