コード例 #1
0
        /// <summary>
        /// Applies localization to a static class containing language-specific strings.
        /// </summary>
        /// <param name="t">Type of the static class containing the desired strings.</param>
        /// <param name="lines">Lines containing the localized strings</param>
        private static void SetLocalization(Type t, IReadOnlyList <string> lines)
        {
            if (lines.Count == 0)
            {
                return;
            }
            foreach (var line in lines.Where(l => l != null))
            {
                var index = line.IndexOf(TranslationSplitter, StringComparison.Ordinal);
                if (index < 0)
                {
                    continue;
                }
                var prop  = line.Substring(0, index);
                var value = line.Substring(index + TranslationSplitter.Length);

                try
                {
                    ReflectUtil.SetValue(t, prop, value);
                }
                catch (Exception e)
                {
                    Debug.WriteLine($"Property not present: {prop} || Value written: {value}");
                    Debug.WriteLine(e.Message);
                }
            }
        }
コード例 #2
0
ファイル: BatchEditing.cs プロジェクト: shimakiui/PKHeX
        /// <summary>
        /// Sets the if the <see cref="PKMInfo"/> should be filtered due to the <see cref="StringInstruction"/> provided.
        /// </summary>
        /// <param name="cmd">Command Filter</param>
        /// <param name="info">Pokémon to check.</param>
        /// <param name="props">PropertyInfo cache (optional)</param>
        /// <returns>True if filtered, else false.</returns>
        private static ModifyResult SetPKMProperty(StringInstruction cmd, PKMInfo info, IReadOnlyDictionary <string, PropertyInfo> props)
        {
            var pkm = info.pkm;

            if (cmd.PropertyValue.StartsWith(CONST_BYTES))
            {
                return(SetByteArrayProperty(pkm, cmd));
            }

            if (cmd.PropertyValue == CONST_SUGGEST)
            {
                return(SetSuggestedPKMProperty(cmd.PropertyName, info));
            }
            if (cmd.PropertyValue == CONST_RAND && cmd.PropertyName == nameof(PKM.Moves))
            {
                return(SetMoves(pkm, pkm.GetMoveSet(true, info.Legality)));
            }

            if (SetComplexProperty(pkm, cmd))
            {
                return(ModifyResult.Modified);
            }

            if (!props.TryGetValue(cmd.PropertyName, out var pi))
            {
                return(ModifyResult.Error);
            }

            object val = cmd.Random ? (object)cmd.RandomValue : cmd.PropertyValue;

            ReflectUtil.SetValue(pi, pkm, val);
            return(ModifyResult.Modified);
        }
コード例 #3
0
ファイル: LocalizationUtil.cs プロジェクト: XiaoChenYi0/PKHeX
        /// <summary>
        /// Applies localization to a static class containing language-specific strings.
        /// </summary>
        /// <param name="t">Type of the static class containing the desired strings.</param>
        /// <param name="lines">Lines containing the localized strings</param>
        private static void SetLocalization(Type t, IReadOnlyCollection <string> lines)
        {
            if (lines.Count == 0)
            {
                return;
            }
            foreach (var line in lines)
            {
                var index = line.IndexOf(TranslationSplitter, StringComparison.Ordinal);
                if (index < 0)
                {
                    continue;
                }
                var prop  = line.Substring(0, index);
                var value = line.Substring(index + TranslationSplitter.Length);

                try
                {
                    ReflectUtil.SetValue(t, prop, value);
                }
#pragma warning disable CA1031 // Do not catch general exception types
                // Malformed translation files, log
                catch (Exception e)
#pragma warning restore CA1031 // Do not catch general exception types
                {
                    Debug.WriteLine($"Property not present: {prop} || Value written: {value}");
                    Debug.WriteLine(e.Message);
                }
            }
        }
コード例 #4
0
ファイル: DataUtil.cs プロジェクト: smileynation/PKHeX
        /// <summary>
        /// Applies localization to a static class containing language-specific strings.
        /// </summary>
        /// <param name="t">Type of the static class containing the desired strings.</param>
        /// <param name="lines">Lines containing the localized strings</param>
        private static void SetLocalization(Type t, IEnumerable <string> lines)
        {
            if (lines == null)
            {
                return;
            }
            foreach (var line in lines.Where(l => l != null))
            {
                var index = line.IndexOf(TranslationSplitter, StringComparison.Ordinal);
                if (index < 0)
                {
                    continue;
                }
                var prop  = line.Substring(0, index);
                var value = line.Substring(index + TranslationSplitter.Length);

                try
                {
                    ReflectUtil.SetValue(t, prop.ToUpper(), value);
                }
                catch
                {
                    Debug.WriteLine($"Property not present: {prop} || Value written: {value}");
                }
            }
        }
コード例 #5
0
ファイル: BatchEditing.cs プロジェクト: shimakiui/PKHeX
        /// <summary>
        /// Sets the <see cref="PKM"/> IV(s) to a random value.
        /// </summary>
        /// <param name="pkm">Pokémon to modify.</param>
        /// <param name="cmd">Modification</param>
        private static void SetRandomIVs(PKM pkm, StringInstruction cmd)
        {
            if (cmd.PropertyName == nameof(pkm.IVs))
            {
                pkm.SetRandomIVs();
                return;
            }

            if (TryGetHasProperty(pkm, cmd.PropertyName, out var pi))
            {
                ReflectUtil.SetValue(pi, pkm, Util.Rand32() & pkm.MaxIV);
            }
        }
コード例 #6
0
ファイル: BatchEditing.cs プロジェクト: rboninsegna/PKHeX
        /// <summary>
        /// Sets the <see cref="PKM"/> IV(s) to a random value.
        /// </summary>
        /// <param name="pk">Pokémon to modify.</param>
        /// <param name="cmd">Modification</param>
        private static void SetRandomIVs(PKM pk, StringInstruction cmd)
        {
            if (cmd.PropertyName == nameof(PKM.IVs))
            {
                pk.SetRandomIVs();
                return;
            }

            if (TryGetHasProperty(pk, cmd.PropertyName, out var pi))
            {
                ReflectUtil.SetValue(pi, pk, Util.Rand.Next(pk.MaxIV + 1));
            }
        }
コード例 #7
0
        /// <summary>
        /// Applies all shared properties from <see cref="Source"/> to <see cref="Destination"/>.
        /// </summary>
        /// <param name="Source"><see cref="PKM"/> that supplies property values.</param>
        /// <param name="Destination"><see cref="PKM"/> that receives property values.</param>
        protected void TransferPropertiesWithReflection(PKM Source, PKM Destination)
        {
            // Only transfer declared properties not defined in PKM.cs but in the actual type
            var SourceProperties      = ReflectUtil.getPropertiesCanWritePublicDeclared(Source.GetType());
            var DestinationProperties = ReflectUtil.getPropertiesCanWritePublicDeclared(Destination.GetType());

            foreach (string property in SourceProperties.Intersect(DestinationProperties))
            {
                var prop = ReflectUtil.GetValue(this, property);
                if (prop != null)
                {
                    ReflectUtil.SetValue(Destination, property, prop);
                }
            }
        }
コード例 #8
0
ファイル: PKM.cs プロジェクト: tkfltkgk/PKHeX
        /// <summary>
        /// Applies all shared properties from <see cref="Source"/> to <see cref="Destination"/>.
        /// </summary>
        /// <param name="Source"><see cref="PKM"/> that supplies property values.</param>
        /// <param name="Destination"><see cref="PKM"/> that receives property values.</param>
        protected void TransferPropertiesWithReflection(PKM Source, PKM Destination)
        {
            var SourceProperties      = ReflectUtil.getPropertiesCanWritePublic(Source.GetType());
            var DestinationProperties = ReflectUtil.getPropertiesCanWritePublic(Destination.GetType());

            // Skip Data property when applying all individual properties. Let the setters do the updates for Data.
            foreach (string property in SourceProperties.Intersect(DestinationProperties).Where(prop => prop != nameof(Data)))
            {
                var prop = ReflectUtil.GetValue(this, property);
                if (prop != null)
                {
                    ReflectUtil.SetValue(Destination, property, prop);
                }
            }
        }
コード例 #9
0
ファイル: PKM.cs プロジェクト: muldos/ImportableToPKHeX
        protected void TransferPropertiesWithReflection(PKM Source, PKM Destination)
        {
            var SourceProperties      = ReflectUtil.getPropertiesCanWritePublic(Source.GetType());
            var DestinationProperties = ReflectUtil.getPropertiesCanWritePublic(Destination.GetType());

            foreach (string property in SourceProperties.Intersect(DestinationProperties).Where(prop => prop != nameof(Data)))
            {
                var prop = ReflectUtil.GetValue(this, property);
                if (prop == null)
                {
                    continue;
                }
                ReflectUtil.SetValue(Destination, property, prop);
            }
        }
コード例 #10
0
ファイル: RibbonApplicator.cs プロジェクト: vvcln/PKHeX
        private static void SetRibbonValue(PKM pk, string rib, int value)
        {
            switch (rib)
            {
            case nameof(PK7.RibbonCountMemoryBattle):
                ReflectUtil.SetValue(pk, rib, value * (pk.Gen4 ? 6 : 8));
                break;

            case nameof(PK7.RibbonCountMemoryContest):
                ReflectUtil.SetValue(pk, rib, value * (pk.Gen4 ? 20 : 40));
                break;

            default:
                ReflectUtil.SetValue(pk, rib, value != 0);
                break;
            }
        }