Ejemplo n.º 1
0
        public override void Entry(IModHelper helper)
        {
            instance = this;

            helper.Events.Player.Warped += onWarped;

            // load content packs
            Log.info("Loading critter content packs...");
            foreach (IContentPack contentPack in this.GetContentPacks())
            {
                CritterEntry data = contentPack.ReadJsonFile <CritterEntry>("critter.json");
                if (data == null)
                {
                    Log.warn($"   {contentPack.Manifest.Name}: ignored (no critter.json file).");
                    continue;
                }
                if (!File.Exists(Path.Combine(contentPack.DirectoryPath, "critter.png")))
                {
                    Log.warn($"   {contentPack.Manifest.Name}: ignored (no critter.png file).");
                    continue;
                }
                Log.info(contentPack.Manifest.Name == data.Id ? contentPack.Manifest.Name : $"   {contentPack.Manifest.Name} (id: {data.Id})");
                CritterEntry.Register(data);
            }
        }
Ejemplo n.º 2
0
        public CustomCritter(Vector2 pos, CritterEntry data)
        {
            this.position = this.startingPosition = pos;
            this.data     = data;
            this.rand     = new Random(((int)startingPosition.X) << 32 | ((int)startingPosition.Y));

            var tex    = Mod.instance.Helper.Content.Load <Texture2D>("Critters/" + data.Id + "/critter.png");
            var texStr = Mod.instance.Helper.Content.GetActualAssetKey($"Critters/{data.Id}/critter.png");

            this.baseFrame = Game1.random.Next(data.SpriteData.Variations) * (tex.Width / data.SpriteData.FrameWidth);

            List <FarmerSprite.AnimationFrame> frames = new List <FarmerSprite.AnimationFrame>();

            foreach (var frame in data.Animations["default"].Frames)
            {
                frames.Add(new FarmerSprite.AnimationFrame(baseFrame + frame.Frame, frame.Duration));
            }
            this.sprite = new AnimatedSprite(texStr, baseFrame, data.SpriteData.FrameWidth, data.SpriteData.FrameHeight);
            sprite.setCurrentAnimation(frames);

            if (data.Light != null)
            {
                var col = new Color(255 - data.Light.Color.R, 255 - data.Light.Color.G, 255 - data.Light.Color.B);
                light = this.validLightIds.Contains(data.Light.VanillaLightId)
                    ? new LightSource(data.Light.VanillaLightId, position, data.Light.Radius, col)
                    : new LightSource(LightSource.sconceLight, position, data.Light.Radius, col);
                Game1.currentLightSources.Add(light);
            }
        }
Ejemplo n.º 3
0
        public override void Entry(IModHelper helper)
        {
            instance = this;

            PlayerEvents.Warped += onLocationChanged;

            /*
             * var ce = new Critters.CritterEntry();
             * ce.Id = "eemie.bee";
             * var a = new Critters.CritterEntry.Animation_();
             * a.Frames.Add(new Critters.CritterEntry.Animation_.AnimationFrame_());
             * ce.Animations.Add("test",a);
             * ce.SpawnConditions.Add(new Critters.CritterEntry.SpawnCondition_());
             * var sl = new Critters.CritterEntry.SpawnLocation_();
             * sl.Conditions.Add(new Critters.CritterEntry.SpawnLocation_.ConditionEntry_());
             * ce.SpawnLocations.Add(sl);
             * helper.WriteJsonFile("test.json", ce);
             */

            Log.info("Creating critter types...");
            foreach (var file in Directory.EnumerateDirectories(Path.Combine(helper.DirectoryPath, "Critters")))
            {
                var ce = helper.ReadJsonFile <CritterEntry>(Path.Combine(file, "critter.json"));
                if (ce == null)
                {
                    Log.warn("\tFailed to load critter data for " + file);
                    continue;
                }
                else if (!File.Exists(Path.Combine(file, "critter.png")))
                {
                    Log.warn("\tCritter " + file + " has no image, skipping");
                    continue;
                }
                Log.info("\tCritter type: " + ce.Id);
                CritterEntry.Register(ce);
            }
        }
Ejemplo n.º 4
0
 public static void Register(CritterEntry entry)
 {
     critters.Add(entry.Id, entry);
 }