]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Displacement Map Visualizer update (#35952)
authorEd <96445749+TheShuEd@users.noreply.github.com>
Sat, 5 Apr 2025 12:51:59 +0000 (15:51 +0300)
committerGitHub <noreply@github.com>
Sat, 5 Apr 2025 12:51:59 +0000 (15:51 +0300)
Update Displacement Map Visualizer.lua

Tools/SS14 Aseprite Plugins/Displacement Map Visualizer.lua

index 468636c07d813b016e2ddd7bc00ff4c152b3bd79..49824acbede64c261f567b0866f523b7fe49013a 100644 (file)
@@ -73,6 +73,33 @@ local findLayer = function(sprite, name)
     return nil
 end
 
+local applyOffset = function(dx, dy)
+    local cel = app.cel
+    local image = cel.image:clone()
+    local sprite = app.editor.sprite
+    local selection = sprite.selection
+    
+    for x = selection.bounds.x, selection.bounds.x + selection.bounds.width - 1 do
+        for y = selection.bounds.y, selection.bounds.y + selection.bounds.height - 1 do
+            local xImg = x - cel.position.x
+            local yImg = y - cel.position.y
+            if xImg >= 0 and xImg < image.width and yImg >= 0 and yImg < image.height then
+                local pixelValue = image:getPixel(xImg, yImg)
+                local color = Color(pixelValue)
+
+                -- Offset R and G channel
+                color.red = math.min(255, math.max(0, color.red + dx))
+                color.green = math.min(255, math.max(0, color.green + dy))
+
+                image:drawPixel(xImg, yImg, app.pixelColor.rgba(color.red, color.green, color.blue, color.alpha))
+            end
+        end
+    end
+    
+    cel.image = image
+    dialog:repaint()
+end
+
 dialog = Dialog{
     title = "Displacement map preview",
     onclose = function(ev)
@@ -160,7 +187,7 @@ dialog:combobox{
 dialog:slider{
     id = "size",
     label = "displacement size",
-    min = 1,
+    min = 127, --We dont support non 127 atm
     max = 127,
     value = 127,
     onchange = function(ev)
@@ -168,4 +195,36 @@ dialog:slider{
     end
 }
 
+dialog:button{
+    id = "moveDown",
+    text = "Down",
+    onclick = function(ev)
+        applyOffset(0, -1)
+    end
+}
+
+dialog:button{
+    id = "moveUp",
+    text = "Up",
+    onclick = function(ev)
+        applyOffset(0, 1)
+    end
+}
+
+dialog:button{
+    id = "moveLeft",
+    text = "Left",
+    onclick = function(ev)
+        applyOffset(1, 0)
+    end
+}
+
+dialog:button{
+    id = "moveRight",
+    text = "Right",
+    onclick = function(ev)
+        applyOffset(-1, 0)
+    end
+}
+
 dialog:show{wait = false}