示例#1
0
    private static PKM?ConvertPKM(PKM pk, Type destType, Type srcType, out EntityConverterResult result)
    {
        result = CheckTransfer(pk);
        if (result != Success)
        {
            return(null);
        }

        Debug.WriteLine($"Trying to convert {srcType.Name} to {destType.Name}.");

        // All types that inherit PKM have the generation specifier as the last char in their class name.
        return(ConvertPKM(pk, destType, ref result));
    }
示例#2
0
    /// <summary>
    /// Converts a PKM from one Generation format to another. If it matches the destination format, the conversion will automatically return.
    /// </summary>
    /// <param name="pk">PKM to convert</param>
    /// <param name="destType">Format/Type to convert to</param>
    /// <param name="result">Comments regarding the transfer's success/failure</param>
    /// <returns>Converted PKM</returns>
    public static PKM?ConvertToType(PKM pk, Type destType, out EntityConverterResult result)
    {
        Type fromType = pk.GetType();

        if (fromType == destType)
        {
            result = None;
            return(pk);
        }

        var entity = ConvertPKM(pk, destType, fromType, out result);

        if (entity is not null)
        {
            if (RejuvenateHOME != EntityRejuvenationSetting.None)
            {
                RejuvenatorHOME.Rejuvenate(entity, pk);
            }
            return(entity);
        }

        if (AllowIncompatibleConversion != EntityCompatibilitySetting.AllowIncompatibleAll)
        {
            if (result is not NoTransferRoute)
            {
                return(null);
            }
            if (AllowIncompatibleConversion != EntityCompatibilitySetting.AllowIncompatibleSane)
            {
                return(null);
            }
        }

        // Try Incompatible Conversion
        entity = EntityBlank.GetBlank(destType);
        pk.TransferPropertiesWithReflection(entity);
        if (!IsCompatibleWithModifications(entity))
        {
            return(null); // NoTransferRoute
        }
        result = SuccessIncompatibleReflection;
        return(entity);
    }
示例#3
0
    private static PKM?ConvertPKM(PKM pk, Type destType, ref EntityConverterResult result)
    {
        PKM?entity = pk.Clone();

        if (entity.IsEgg)
        {
            entity.ForceHatchPKM();
        }
        while (true)
        {
            entity = IntermediaryConvert(entity, destType, ref result);
            if (entity == null) // fail convert
            {
                return(null);
            }
            if (entity.GetType() == destType) // finish convert
            {
                return(entity);
            }
        }
    }
    public static string GetDisplayString(this EntityConverterResult result, PKM src, Type dest)
    {
        if (result == None)
        {
            return("No need to convert, current format matches requested format.");
        }

        var msg       = result.IsSuccess() ? MessageStrings.MsgPKMConvertSuccess : MessageStrings.MsgPKMConvertFailFormat;
        var srcName   = src.GetType().Name;
        var destName  = dest.Name;
        var formatted = string.Format(msg, srcName, destName);

        if (result is Success)
        {
            return(formatted);
        }

        var comment = GetMessage(result, src, dest);

        return(string.Concat(formatted, Environment.NewLine, comment));
    }
示例#5
0
    /// <summary>
    /// Converts a PKM from one Generation format to another. If it matches the destination format, the conversion will automatically return.
    /// </summary>
    /// <param name="pk">PKM to convert</param>
    /// <param name="destType">Format/Type to convert to</param>
    /// <param name="result">Comments regarding the transfer's success/failure</param>
    /// <returns>Converted PKM</returns>
    public static PKM?ConvertToType(PKM pk, Type destType, out EntityConverterResult result)
    {
        Type fromType = pk.GetType();

        if (fromType == destType)
        {
            result = None;
            return(pk);
        }

        var pkm = ConvertPKM(pk, destType, fromType, out result);

        if (!AllowIncompatibleConversion || pkm != null)
        {
            return(pkm);
        }

        if (pk is PK8 && destType == typeof(PB8))
        {
            result = SuccessIncompatibleManual;
            return(new PB8((byte[])pk.Data.Clone()));
        }

        if (pk is PB8 && destType == typeof(PK8))
        {
            result = SuccessIncompatibleManual;
            return(new PK8((byte[])pk.Data.Clone()));
        }

        // Try Incompatible Conversion
        pkm = EntityBlank.GetBlank(destType);
        pk.TransferPropertiesWithReflection(pkm);
        if (!IsCompatibleWithModifications(pkm))
        {
            return(null); // NoTransferRoute
        }
        result = SuccessIncompatibleReflection;
        return(pkm);
    }
示例#6
0
 private static PKM?IntermediaryConvert(PKM pk, Type destType, ref EntityConverterResult result) => pk switch
 {
 public static bool IsSuccess(this EntityConverterResult result) => result is Success or SuccessIncompatibleManual or SuccessIncompatibleReflection;
 public static bool IsSilent(this EntityConverterResult result) => result is None or Success;
 private static string GetMessage(this EntityConverterResult result, PKM src, Type dest) => result switch
 {