コード例 #1
0
        public override void HandleFile(FileLoader loader)
        {
            if (!Path.GetExtension(loader.Source.AbsolutePath)
                .Equals(".png", StringComparison.InvariantCultureIgnoreCase))
            {
                return;
            }

            var fileInfo = loader.Entity.GetComponent(FileInfo.TypeCode);

            ChaFile chaFile;

            try
            {
                using (var stream = fileInfo.OpenRead())
                {
                    chaFile = new ChaFile(stream);
                }
            }
            catch (Exception)
            {
                return;
            }

            var card = loader.Entity.AddComponent(KoikatuCharacterCard.TypeCode);

            card.Initialize(chaFile);
        }
コード例 #2
0
        internal void Initialize(ChaFile chaFile)
        {
            if (chaFile == null)
            {
                throw new ArgumentNullException(nameof(chaFile));
            }

            if (chaFile.parameter != null)
            {
                LastName  = chaFile.parameter.lastname ?? string.Empty;
                FirstName = chaFile.parameter.firstname ?? string.Empty;
                Nickname  = chaFile.parameter.nickname ?? string.Empty;

                Sex       = (Sex)chaFile.parameter.sex;
                BloodType = (BloodType)chaFile.parameter.bloodType;

                Personality  = (Personality)chaFile.parameter.personality;
                ClubActivity = (ClubActivity)chaFile.parameter.clubActivities;
            }

            var face = chaFile.custom?.face;

            if (face != null)
            {
                TeethType = face.doubleTooth ? TeethType.Fangs : TeethType.Normal;
            }

            var body = chaFile.custom?.body;

            if (body != null)
            {
                var shapeValueBody = body.shapeValueBody;
                if (shapeValueBody != null)
                {
                    if (shapeValueBody.Length > (int)ChaFileDefine.BodyShapeIdx.Height)
                    {
                        Height = shapeValueBody[(int)ChaFileDefine.BodyShapeIdx.Height];
                    }
                    if (shapeValueBody.Length > (int)ChaFileDefine.BodyShapeIdx.BustSize)
                    {
                        BustSize = shapeValueBody[(int)ChaFileDefine.BodyShapeIdx.BustSize];
                    }
                }

                SkinColor = KoikatuColorConversion.KoikatuColorToColor(body.skinMainColor);
                if (body.detailId >= (int)SkinType.Normal && body.detailId <= (int)SkinType.Slender)
                {
                    SkinType = (SkinType)body.detailId;
                }
                else
                {
                    SkinType = SkinType.Other;
                }
            }

            var hair = chaFile.custom?.hair;

            if (hair != null)
            {
                HairStyle  = (HairStyle)hair.kind;
                HairColors = hair.parts
                             .Select((item, index) => new { item, index })
                             // Skip hair slots set to "none" (usually ID 0). Note that back hair has no such option.
                             .Where(i => i.item.id != 0 || i.index == (int)ChaFileDefine.HairKind.back)
                             // Ignore option hair because it doesn't usually contribute much to the overall color.
                             .Where(i => i.index != (int)ChaFileDefine.HairKind.option)
                             .Select(i => i.item.baseColor)
                             .Select(KoikatuColorConversion.KoikatuColorToColor)
                             .Distinct()
                             .ToList()
                             .AsReadOnly();
            }
        }