altering a single layer of animation

Place to get help with not working mods / modding interface.
Post Reply
User avatar
adamwong246
Fast Inserter
Fast Inserter
Posts: 148
Joined: Tue Dec 01, 2020 5:01 am
Contact:

altering a single layer of animation

Post by adamwong246 »

I am attempting to create a suite of labs, and each are visually distinct by their active "glow". I'm using the white mask provided by DiscoScience, which will at build-time be used to generate a the of colored variants, so my nuclear lab gets a green glow, heat powered lab gets a red glow, etc. My strategy is to copy the definition for the vanilla lab, find the layer that defines the light and replace that filename with my new custom file. Finally, save the animation to my new lab entity. While my logging shows the updated animation as I expect, the labs still glow vanilla blue rather than updated white.

I am still clumsy in lua so maybe I have made a noob mistake?

Code: Select all

local labLevel = _ + 1;
    local labName = "lab-" .. tostring(_);
    local newLabEntity = table.deepcopy(data.raw.lab.lab);
    newLabEntity.name = labName;

    local newLayers= {};    
    for _, animationLayer in pairs(newLabEntity.on_animation.layers) do
        if animationLayer.draw_as_light then
            animationLayer.filename = "__hard_science__/graphics/lab-storm.png" -- https://github.com/danielbrauer/DiscoScience/blob/master/src/graphics/hr-lab-storm.png
            animationLayer.hr_version.filename = "__hard_science__/graphics/hr-lab-storm.png"
        end
        table.insert(newLayers, animationLayer)
    end
    newLabEntity.on_animation = {layers = newLayers};
    log(serpent.block(newLabEntity.on_animation.layers))
    data:extend({newLabEntity});

Code: Select all

   1.830 Script @__hard_science__/data.lua:154: {
  {
    animation_speed = 0.3333333333333333,
    filename = "__base__/graphics/entity/lab/lab.png",
    frame_count = 33,
    height = 87,
    hr_version = {
      animation_speed = 0.3333333333333333,
      filename = "__base__/graphics/entity/lab/hr-lab.png",
      frame_count = 33,
      height = 174,
      line_length = 11,
      scale = 0.5,
      shift = {
        0,
        0.046875
      },
      width = 194
    },
    line_length = 11,
    shift = {
      0,
      0.046875
    },
    width = 98
  },
  {
    animation_speed = 0.3333333333333333,
    filename = "__base__/graphics/entity/lab/lab-integration.png",
    frame_count = 1,
    height = 81,
    hr_version = {
      animation_speed = 0.3333333333333333,
      filename = "__base__/graphics/entity/lab/hr-lab-integration.png",
      frame_count = 1,
      height = 162,
      line_length = 1,
      repeat_count = 33,
      scale = 0.5,
      shift = {
        0,
        0.484375
      },
      width = 242
    },
    line_length = 1,
    repeat_count = 33,
    shift = {
      0,
      0.484375
    },
    width = 122
  },
  {
    animation_speed = 0.3333333333333333,
    blend_mode = "additive",
    draw_as_light = true,
    filename = "__hard_science__/graphics/lab-storm.png",
    frame_count = 33,
    height = 100,
    hr_version = {
      animation_speed = 0.3333333333333333,
      blend_mode = "additive",
      draw_as_light = true,
      filename = "__hard_science__/graphics/hr-lab-storm.png",
      frame_count = 33,
      height = 194,
      line_length = 11,
      scale = 0.5,
      shift = {
        0,
        0
      },
      width = 216
    },
    line_length = 11,
    shift = {
      -0.03125,
      0.03125
    },
    width = 106
  },
  {
    animation_speed = 0.3333333333333333,
    draw_as_shadow = true,
    filename = "__base__/graphics/entity/lab/lab-shadow.png",
    frame_count = 1,
    height = 68,
    hr_version = {
      animation_speed = 0.3333333333333333,
      draw_as_shadow = true,
      filename = "__base__/graphics/entity/lab/hr-lab-shadow.png",
      frame_count = 1,
      height = 136,
      line_length = 1,
      repeat_count = 33,
      scale = 0.5,
      shift = {
        0.40625,
        0.34375
      },
      width = 242
    },
    line_length = 1,
    repeat_count = 33,
    shift = {
      0.40625,
      0.34375
    },
    width = 122
  }
}
   1.832 Script @__hard_science__/data.lua:154: {
  {
    animation_speed = 0.3333333333333333,
    filename = "__base__/graphics/entity/lab/lab.png",
    frame_count = 33,
    height = 87,
    hr_version = {
      animation_speed = 0.3333333333333333,
      filename = "__base__/graphics/entity/lab/hr-lab.png",
      frame_count = 33,
      height = 174,
      line_length = 11,
      scale = 0.5,
      shift = {
        0,
        0.046875
      },
      width = 194
    },
    line_length = 11,
    shift = {
      0,
      0.046875
    },
    width = 98
  },
  {
    animation_speed = 0.3333333333333333,
    filename = "__base__/graphics/entity/lab/lab-integration.png",
    frame_count = 1,
    height = 81,
    hr_version = {
      animation_speed = 0.3333333333333333,
      filename = "__base__/graphics/entity/lab/hr-lab-integration.png",
      frame_count = 1,
      height = 162,
      line_length = 1,
      repeat_count = 33,
      scale = 0.5,
      shift = {
        0,
        0.484375
      },
      width = 242
    },
    line_length = 1,
    repeat_count = 33,
    shift = {
      0,
      0.484375
    },
    width = 122
  },
  {
    animation_speed = 0.3333333333333333,
    blend_mode = "additive",
    draw_as_light = true,
    filename = "__hard_science__/graphics/lab-storm.png",
    frame_count = 33,
    height = 100,
    hr_version = {
      animation_speed = 0.3333333333333333,
      blend_mode = "additive",
      draw_as_light = true,
      filename = "__hard_science__/graphics/hr-lab-storm.png",
      frame_count = 33,
      height = 194,
      line_length = 11,
      scale = 0.5,
      shift = {
        0,
        0
      },
      width = 216
    },
    line_length = 11,
    shift = {
      -0.03125,
      0.03125
    },
    width = 106
  },
  {
    animation_speed = 0.3333333333333333,
    draw_as_shadow = true,
    filename = "__base__/graphics/entity/lab/lab-shadow.png",
    frame_count = 1,
    height = 68,
    hr_version = {
      animation_speed = 0.3333333333333333,
      draw_as_shadow = true,
      filename = "__base__/graphics/entity/lab/hr-lab-shadow.png",
      frame_count = 1,
      height = 136,
      line_length = 1,
      repeat_count = 33,
      scale = 0.5,
      shift = {
        0.40625,
        0.34375
      },
      width = 242
    },
    line_length = 1,
    repeat_count = 33,
    shift = {
      0.40625,
      0.34375
    },
    width = 122
  }
}

Code: Select all

   ?   tree                                                                                                                                                  ~/Code/FactorioModLab/mods/hard_science master -!+
.
├── README.md
├── data.lua
├── graphics
│   ├── hr-lab-storm.png
│   └── lab-storm.png
├── hard_science_0.0.1.zip
├── info.json
└── locale
    └── en
        └── locale.cfg

Code: Select all

{
  "name": "hard_science",
  "version": "0.0.1",
  "title": "Hard Science",
  "description": "Science is hard.",
  "factorio_version": "1.1",
  "dependencies": [
    "base >= 1.1.21",
    "recursive-science >= 2020.11.29"
  ],
  "author": "adamwong246",
  "contact": "adamwong246@gmail.com",
  "homepage": "https://github.com/adamwong246"
}

User avatar
Deadlock989
Smart Inserter
Smart Inserter
Posts: 2528
Joined: Fri Nov 06, 2015 7:41 pm

Re: altering a single layer of animation

Post by Deadlock989 »

You are using the full 33 frames of the original lab animation, in which the glowing effects are "baked in" and coloured blue (see Factorio/data/base/graphics/entity/lab/hr-lab.png).

On top of that you are using a white draw_as_light layer. Draw_as_light is multiplicative, and blue multiplied by white is blue.

You need to use only the "off" frame of the lab, then an additive (non draw_as_light) layer of tinted monochrome "glow" on top of that, and then the same thing not tinted as a draw_as_light layer so that it glows in the dark. Alternatively you can use just one glow effect layer with draw_as_glow instead of draw_as_light.

You can see past-me puzzling through this stuff in this thread.
Image

User avatar
adamwong246
Fast Inserter
Fast Inserter
Posts: 148
Joined: Tue Dec 01, 2020 5:01 am
Contact:

Re: altering a single layer of animation

Post by adamwong246 »

I don't want to alter the idle lab animation, so I'm not sure why I'd alter the `off_animation`? I only want to change the lights when it's researching.

User avatar
Deadlock989
Smart Inserter
Smart Inserter
Posts: 2528
Joined: Fri Nov 06, 2015 7:41 pm

Re: altering a single layer of animation

Post by Deadlock989 »

adamwong246 wrote:
Mon Sep 19, 2022 12:05 am
I don't want to alter the idle lab animation, so I'm not sure why I'd alter the `off_animation`? I only want to change the lights when it's researching.
You have misunderstood / I wasn't clear. You don't want to use the full on_animation sheet because those have the blue glow effects built in. You only want to use one frame that is "dark" (I suggest the first frame, top left, which from memory is what the off_animation uses) with a repeat_count set if you need it to match the frame counts of the other layers. Your variously coloured effects are then layered on top of that base using additive blending and the light layer.
Image

Post Reply

Return to “Modding help”