Tree XRay


Adds a way to see through trees around you

Utilities
3 years ago
1.0 - 1.1
8.59K

i Transparent-ish trees?

2 years ago

I'm sort of intrigued by how it would look if the trees were to be made transparent, rather than turned into stumps.

I had a go at attempting to get the tree to be transparent; the leaves are do-able (by converting them into an overlay, which accepts transparency), but had no joy with attempting to make the trunk transparent.

local alpha = 0.25
local tint = { r = alpha, g = alpha, b = alpha, a = alpha }

local function tintAnimation2(animation, set_runtime_tint)
  local layers = animation.layers
  if layers then
    for _, layer in ipairs(layers) do
      tintAnimation2(layer, set_runtime_tint)
    end
    return
  end
  local hr_version = animation.hr_version
  if hr_version then
    tintAnimation2(hr_version, set_runtime_tint)
  end
  local animation_tint = animation.tint
  if animation_tint then
    animation.tint = util.mix_color(animation_tint, tint)
  else
    animation.tint = tint
  end
  if set_runtime_tint then
    animation.apply_runtime_tint = true
  end
end

local function tintAnimation(animation, set_runtime_tint)
  local layers = animation.layers
  if layers then
    for _, layer in ipairs(layers) do
      tintAnimation2(layer, set_runtime_tint)
    end
    return animation
  else
    tintAnimation2(animation, set_runtime_tint)
    return {
      layers = {
        animation
      }
    }
  end
end

local function createXrayTree(original)
  local newTree = table.deepcopy(original)

  newTree.name = newTree.name .. "-xray"
  newTree.autoplace = nil

  if changeSelectionBox then
    newTree.selection_box = {{-halfSelectionBox, -halfSelectionBox}, {halfSelectionBox, halfSelectionBox}}
  end

  local variations = newTree.variations
  if variations then
    for _, variation in ipairs(variations) do
      variation.trunk = trunkSprite

      local leaves = variation.leaves
      local leaves_frame_count = leaves.frame_count

      local new_overlay = tintAnimation(leaves)

      local overlay = variation.overlay
      if overlay then
        overlay = tintAnimation(overlay)
        local new_overlay_layers = new_overlay.layers
        for _, value in ipairs(overlay.layers) do
          new_overlay_layers[#new_overlay_layers+1] = value
        end
      end
      variation.overlay = new_overlay

      leaves = table.deepcopy(emptyAnim)
      leaves.frame_count = leaves_frame_count
      variation.leaves = leaves
    end
  else
    local pictures = newTree.pictures
    for i, picture in ipairs(pictures) do
      pictures[i] = tintAnimation(picture)
    end
  end

  data:extend{newTree}
end

New response