Exemplo n.º 1
0
        private static void ChangeTeleporterData(object rootObject, object[] arguments, Action <DataWrapper.TeleporterData> change)
        {
            var root        = rootObject as IScriptRootData;
            var structure   = arguments[0] as IStructureData;
            var namesSearch = arguments[1].ToString();

            if (!root.IsElevatedScript)
            {
                throw new HandlebarsException("only allowed in elevated scripts");
            }

            var uniqueNames = structure.AllCustomDeviceNames.GetUniqueNames(namesSearch);

            uniqueNames.ForEach(N => {
                var teleporter = structure.GetCurrent().GetDevice <ITeleporter>(N);
                if (teleporter == null)
                {
                    return;
                }

                var block = BlockHelpers.Devices(structure, N).FirstOrDefault();
                if (block != null)
                {
                    change(new DataWrapper.TeleporterData(structure.GetCurrent(), block.Position));
                }
            });
        }
Exemplo n.º 2
0
        public static void TeleporterHelper(TextWriter output, object rootObject, HelperOptions options, dynamic context, object[] arguments)
        {
            if (arguments.Length != 2)
            {
                throw new HandlebarsException("{{teleporters structure names}} helper must have exactly two argument: (structure) (names)");
            }

            var root        = rootObject as IScriptRootData;
            var structure   = arguments[0] as IStructureData;
            var namesSearch = arguments[1].ToString();

            try
            {
                var uniqueNames = structure.AllCustomDeviceNames.GetUniqueNames(namesSearch);

                var blocks = uniqueNames.Select(N => {
                    var teleporter = structure.GetCurrent().GetDevice <ITeleporter>(N);
                    if (teleporter == null)
                    {
                        return(null);
                    }

                    var block = BlockHelpers.Devices(structure, N).FirstOrDefault();
                    return(block != null ? new DataWrapper.TeleporterData(structure.GetCurrent(), block.Position) : null);
                })
                             .Where(T => T != null)
                             .ToArray();


                if (blocks != null && blocks.Length > 0)
                {
                    options.Template(output, blocks);
                }
                else
                {
                    options.Inverse(output, context as object);
                }
            }
            catch (Exception error)
            {
                if (!CsScriptFunctions.FunctionNeedsMainThread(error, root))
                {
                    output.Write("{{teleporters}} error " + EmpyrionScripting.ErrorFilter(error));
                }
            }
        }