Exemplo n.º 1
0
        /// <summary>Constructs a list tag from saved text input.</summary>
        /// <param name="list">The saved text input.</param>
        /// <param name="data">The tag data.</param>
        /// <returns>A valid list.</returns>
        public static ListTag CreateFromSaved(string list, TagData data)
        {
            string[] baselist = list.SplitFast('|');
            ListTag  tlist    = new();

            for (int i = 0; i < baselist.Length; i++)
            {
                if (i == baselist.Length - 1 && baselist[i].Length == 0)
                {
                    break;
                }
                string dat = UnescapeTagBase.Unescape(baselist[i]);
                tlist.Internal.Add(data.TagSystem.ParseFromSaved(dat, data));
            }
            return(tlist);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Converts saved text to a map tag.
        /// Never null. Will ignore invalid entries.
        /// </summary>
        /// <param name="input">The input saved text.</param>
        /// <param name="data">The tag data.</param>
        /// <returns>The map represented by the input text.</returns>
        public static MapTag CreateFromSaved(string input, TagData data)
        {
            string[] dat = input.SplitFast('|');
            MapTag   map = new();

            for (int i = 0; i < dat.Length; i++)
            {
                string[] kvp = dat[i].SplitFast(':');
                if (kvp.Length != 2)
                {
                    // TODO: Error?
                    continue;
                }
                map.Internal[UnescapeTagBase.Unescape(kvp[0]).ToLowerFast()] = data.TagSystem.ParseFromSaved(UnescapeTagBase.Unescape(kvp[1]), data);
            }
            return(map);
        }
Exemplo n.º 3
0
        /// <summary>Constructs a list tag from text input.</summary>
        /// <param name="list">The text input.</param>
        /// <returns>A valid list.</returns>
        public static ListTag For(string list)
        {
            string[] baselist = list.SplitFast('|');
            ListTag  tlist    = new();

            for (int i = 0; i < baselist.Length; i++)
            {
                if (i == baselist.Length - 1 && baselist[i].Length == 0)
                {
                    break;
                }
                string          dat = UnescapeTagBase.Unescape(baselist[i]);
                TextArgumentBit tab = new(dat, false, true, null);
                tlist.Internal.Add(tab.InputValue);
            }
            return(tlist);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Converts text to a map tag.
        /// Never null. Will ignore invalid entries.
        /// </summary>
        /// <param name="input">The input text.</param>
        /// <returns>The map represented by the input text.</returns>
        public static MapTag For(string input)
        {
            string[] dat = input.SplitFast('|');
            MapTag   map = new(dat.Length);

            for (int i = 0; i < dat.Length; i++)
            {
                string[] kvp = dat[i].SplitFast(':');
                if (kvp.Length != 2)
                {
                    // TODO: Error?
                    continue;
                }
                string key = UnescapeTagBase.Unescape(kvp[0]).ToLowerFast();
                map.Internal[key] = new TextArgumentBit(UnescapeTagBase.Unescape(kvp[1]), false, true, null).InputValue;
            }
            return(map);
        }
Exemplo n.º 5
0
        private ItemStack Load(string name)
        {
            string tname = name.ToLowerFast();
            string fname = "items/" + tname + ".itm";

            if (!TheServer.Files.Exists(fname))
            {
                SysConsole.Output(OutputType.WARNING, "Tried to load non-existent item: " + name);
                return(null);
            }
            try
            {
                string   fdata           = TheServer.Files.ReadText(fname);
                string[] split           = fdata.Replace('\r', '\n').SplitFast('\n');
                string   res_type        = "";
                string   res_icon        = "";
                string   res_display     = "";
                string   res_description = "";
                string   res_color       = "";
                string   res_model       = "";
                string   res_bound       = "";
                string   res_subtype     = null;
                string   res_datum       = "0";
                string   res_weight      = "1";
                string   res_volume      = "1";
                List <KeyValuePair <string, string> > attrs  = new List <KeyValuePair <string, string> >();
                List <KeyValuePair <string, string> > shared = new List <KeyValuePair <string, string> >();
                foreach (string line in split)
                {
                    if (line.Trim().Length < 3)
                    {
                        continue;
                    }
                    string[] dat      = line.SplitFast(':', 1);
                    string   dat_type = dat[0].Trim().ToLowerFast();
                    string   dat_val  = dat[1].Trim();
                    switch (dat_type)
                    {
                    case "type":
                        res_type = dat_val;
                        break;

                    case "subtype":
                        res_subtype = dat_val;
                        break;

                    case "icon":
                        res_icon = dat_val;
                        break;

                    case "display":
                        res_display = dat_val;
                        break;

                    case "description":
                        res_description = dat_val;
                        break;

                    case "color":
                        res_color = dat_val;
                        break;

                    case "model":
                        res_model = dat_val;
                        break;

                    case "bound":
                        res_bound = dat_val;
                        break;

                    case "datum":
                        res_datum = dat_val;
                        break;

                    case "weight":
                        res_weight = dat_val;
                        break;

                    case "volume":
                        res_volume = dat_val;
                        break;

                    default:
                        if (dat_type.StartsWith("shared."))
                        {
                            string opt = dat_type.Substring("shared.".Length).ToLower();
                            shared.Add(new KeyValuePair <string, string>(opt, dat_val));
                        }
                        else if (dat_type.StartsWith("attributes."))
                        {
                            string opt = dat_type.Substring("attributes.".Length).ToLower();
                            attrs.Add(new KeyValuePair <string, string>(opt, dat_val));
                        }
                        break;
                    }
                }
                if (string.IsNullOrEmpty(res_display))
                {
                    res_display = "^[lang=voxalia|items." + tname.Replace("/", ".") + ".display]";
                }
                if (string.IsNullOrEmpty(res_description))
                {
                    res_description = "^[lang=voxalia|items." + tname.Replace("/", ".") + ".description]";
                }
                // TODO: Fix color parsing
                ItemStack it = new ItemStack(res_type, res_subtype, TheServer, 1, res_icon, res_display, res_description,
                                             Color4F.White, res_model, res_bound.ToLower() == "true", ItemStack.IntDatumFor(res_datum))
                {
                    Weight = Utilities.StringToFloat(res_weight),
                    Volume = Utilities.StringToFloat(res_volume)
                };
                foreach (KeyValuePair <string, string> key in shared)
                {
                    string         dat     = UnescapeTagBase.Unescape(key.Value);
                    string         type    = dat.Substring(0, 4);
                    string         content = dat.Substring(5);
                    TemplateObject togive  = ItemStack.TOFor(TheServer, type, content);
                    it.SharedAttributes[key.Key] = togive;
                }
                foreach (KeyValuePair <string, string> key in attrs)
                {
                    string         dat     = UnescapeTagBase.Unescape(key.Value);
                    string         type    = dat.Substring(0, 4);
                    string         content = dat.Substring(5);
                    TemplateObject togive  = ItemStack.TOFor(TheServer, type, content);
                    it.Attributes[key.Key] = togive;
                }
                return(it);
            }
            catch (Exception ex)
            {
                Utilities.CheckException(ex);
                SysConsole.Output("Loading item '" + name + "'", ex);
                return(null);
            }
        }
Exemplo n.º 6
0
        public static ItemStack FromString(Server tserver, string input)
        {
            int    brack    = input.IndexOf('[');
            string name     = input.Substring(0, brack);
            string contents = input.Substring(brack + 1, input.Length - (brack + 1));
            List <KeyValuePair <string, string> > pairs = SplitUpPairs(contents);
            string secname     = "";
            int    count       = 1;
            string tex         = "";
            string display     = "";
            string descrip     = "";
            string model       = "";
            string components  = "";
            bool   bound       = false;
            string shared      = "";
            string local       = "";
            double weight      = 1;
            double volume      = 1;
            int    datum       = 0;
            double temperature = 0;

            System.Drawing.Color color = System.Drawing.Color.White;
            bool     renderComp        = true;
            Location renderCompOffs    = Location.Zero;

            foreach (KeyValuePair <string, string> pair in pairs)
            {
                string tkey = UnescapeTagBase.Unescape(pair.Key);
                string tval = UnescapeTagBase.Unescape(pair.Value);
                switch (tkey)
                {
                case "secondary":
                    secname = tval;
                    break;

                case "display":
                    display = tval;
                    break;

                case "count":
                    count = Utilities.StringToInt(tval);
                    break;

                case "description":
                    descrip = tval;
                    break;

                case "texture":
                    tex = tval;
                    break;

                case "model":
                    model = tval;
                    break;

                case "bound":
                    bound = tval == "true";
                    break;

                case "drawcolor":
                    color = (ColorTag.For(tval) ?? new ColorTag(color)).Internal;
                    break;

                case "datum":
                    datum = IntDatumFor(tval);
                    break;

                case "weight":
                    weight = Utilities.StringToFloat(tval);
                    break;

                case "volume":
                    volume = Utilities.StringToFloat(tval);
                    break;

                case "temperature":
                    temperature = Utilities.StringToFloat(tval);
                    break;

                case "shared":
                    shared = tval;
                    break;

                case "local":
                    local = tval;
                    break;

                case "components":
                    components = tval;
                    break;

                case "renderascomponent":
                    renderComp = tval.ToLowerFast() == "true";
                    break;

                case "componentrenderoffset":
                    renderCompOffs = Location.FromString(tval);
                    break;

                default:
                    break;     // Ignore errors as much as possible here.
                    // TODO: Maybe actually just error?
                }
            }
            ItemStack item = new ItemStack(name, secname, tserver, count, tex, display, descrip, color, model, bound, datum);

            item.Weight      = weight;
            item.Volume      = volume;
            item.Temperature = temperature;
            pairs            = SplitUpPairs(shared.Substring(1, shared.Length - 2));
            foreach (KeyValuePair <string, string> pair in pairs)
            {
                string         dat     = UnescapeTagBase.Unescape(pair.Value);
                string         type    = dat.Substring(0, 4);
                string         content = dat.Substring(5);
                TemplateObject togive  = TOFor(tserver, type, content);
                item.SharedAttributes.Add(UnescapeTagBase.Unescape(pair.Key), togive);
            }
            pairs = SplitUpPairs(local.Substring(1, local.Length - 2));
            foreach (KeyValuePair <string, string> pair in pairs)
            {
                string         dat     = UnescapeTagBase.Unescape(pair.Value);
                string         type    = dat.Substring(0, 4);
                string         content = dat.Substring(5);
                TemplateObject togive  = TOFor(tserver, type, content);
                item.Attributes.Add(UnescapeTagBase.Unescape(pair.Key), togive);
            }
            string[] npairs = components.Substring(1, local.Length - 2).SplitFast(';', 2);
            foreach (string pair in npairs)
            {
                string dat = UnescapeTagBase.Unescape(pair);
                if (dat.Length > 0)
                {
                    item.Components.Add(FromString(tserver, dat));
                }
            }
            item.RenderAsComponent     = renderComp;
            item.ComponentRenderOffset = renderCompOffs;
            return(item);
        }