Example #1
0
        public void Load(string filePath)
        {
            LoadMeta(Path.Combine(filePath, "meta.xml"));
            string basedOnFilePath = null;

            if (Meta.BasedOn != null)
            {
                basedOnFilePath = Path.Combine(Path.GetDirectoryName(filePath), Meta.BasedOn);
                if (basedOnFilePath == filePath)
                {
                    throw new ArgumentException("Language cannot be based on itself.");
                }
            }
            if (basedOnFilePath != null)
            {
                Load(basedOnFilePath);
            }
            Messages            = Messages.MergeOrLoad(Messages, Path.Combine(filePath, "messages.xml"), MergeStrategy.Recursive);
            SimpleMessages      = SimpleMessages.MergeOrLoad(SimpleMessages, Path.Combine(filePath, "simpleMessages.xml"), MergeStrategy.Recursive);
            RoleMessages        = RoleMessages.MergeOrLoad(RoleMessages, Path.Combine(filePath, "roles.xml"), MergeStrategy.Recursive);
            ItemMessages        = ItemMessages.MergeOrLoad(ItemMessages, Path.Combine(filePath, "items.xml"), MergeStrategy.Recursive);
            PlaceMessages       = PlaceMessages.MergeOrLoad(PlaceMessages, Path.Combine(filePath, "places.xml"), MergeStrategy.Recursive);
            AchievementMessages = AchievementMessages.MergeOrLoad(AchievementMessages, Path.Combine(filePath, "achievements.xml"), MergeStrategy.Recursive);
            ModuleMessages      = ModuleMessages.MergeOrLoad(ModuleMessages, Path.Combine(filePath, "modules.xml"), MergeStrategy.Recursive);
            PointMessages       = PointMessages.MergeOrLoad(PointMessages, Path.Combine(filePath, "points.xml"), MergeStrategy.Recursive);
        }
Example #2
0
 public void Load(string filePath)
 {
     Messages            = Messages.GetInstance(Path.Combine(filePath, "messages.xml"));
     SimpleMessages      = SimpleMessages.GetInstance(Path.Combine(filePath, "simpleMessages.xml"));
     RoleMessages        = RoleMessages.GetInstance(Path.Combine(filePath, "roles.xml"));
     ItemMessages        = ItemMessages.GetInstance(Path.Combine(filePath, "items.xml"));
     PlaceMessages       = PlaceMessages.GetInstance(Path.Combine(filePath, "places.xml"));
     AchievementMessages = AchievementMessages.GetInstance(Path.Combine(filePath, "achievements.xml"));
     ModuleMessages      = ModuleMessages.GetInstance(Path.Combine(filePath, "modules.xml"));
 }
        private TypeInfo MakeDirt(ModuleMessages messages, ModuleBuilder mb, TypeInfo typeInfo)
        {
            var type = typeInfo.AsType();
            var tb   = GetTypeBuilder(mb, type.Name + "Proxy", type);

            messages.TryGetValue(type.Name, out var moduleLang);

            // copy and localize attributes
            {
                var attrs = PrepareAttributes(typeInfo.CustomAttributes, moduleLang);
                foreach (var attr in attrs)
                {
                    tb.SetCustomAttribute(attr);
                }
            }

            // create constructors with parent call
            foreach (var ctor in type.GetConstructors())
            {
                var paramTypes = ctor.GetParameters().Select(pi => pi.ParameterType).ToArray();
                var newCtor    = tb.DefineConstructor(ctor.Attributes, ctor.CallingConvention, paramTypes);
                var gen        = newCtor.GetILGenerator();
                GenerateInstanceCall(gen, ctor, paramTypes.Length);
            }

            // create command methods with attributes and parent call
            foreach (var method in typeInfo.DeclaredMethods.Where(m => IsValidCommandDefinition(m)))
            {
                CommandMessages.CommandInfo methodLang = null;
                var commandAttr = method.GetCustomAttribute <CommandAttribute>();
                moduleLang?.Commands?.TryGetValue(commandAttr?.Text ?? method.Name, out methodLang);

                // copy parameter definitions with attributes
                var parameters = method.GetParameters();
                var paramTypes = parameters.Select(pi => pi.ParameterType).ToArray();
                var newMethod  = tb.DefineMethod(
                    method.Name + "_Proxy", method.Attributes, method.CallingConvention, method.ReturnType, null, null, paramTypes, null, null
                    );
                for (int i = 0; i < parameters.Length; i++)
                {
                    var p = parameters[i];
                    // 1-based index, 0 - return value
                    var pb = newMethod.DefineParameter(i + 1, p.Attributes, p.Name);
                    if (p.HasDefaultValue)
                    {
                        pb.SetConstant(p.DefaultValue);
                    }

                    ParameterMessages.ParameterInfo paramLang = null;
                    methodLang?.Parameters?.TryGetValue(p.Name, out paramLang);

                    // copy and localize attributes
                    {
                        var attrs = PrepareAttributes(p.CustomAttributes, paramLang);
                        foreach (var attr in attrs)
                        {
                            pb.SetCustomAttribute(attr);
                        }
                    }
                }
                var gen = newMethod.GetILGenerator();
                GenerateInstanceCall(gen, method, paramTypes.Length);

                // copy and localize attributes
                {
                    var attrs = PrepareAttributes(method.CustomAttributes, methodLang);
                    foreach (var attr in attrs)
                    {
                        newMethod.SetCustomAttribute(attr);
                    }
                }
            }
            TypeInfo objectTypeInfo = tb.CreateTypeInfo();

            return(objectTypeInfo);
        }