Skip to content

Commit

Permalink
Merge pull request #92 from SMTheGuild/fix-color-block-lights
Browse files Browse the repository at this point in the history
Re-enable Color Block turning on lights on white input
  • Loading branch information
QuestionableM authored Nov 19, 2024
2 parents f0dd695 + cc56537 commit a4bc13a
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 14 deletions.
2 changes: 1 addition & 1 deletion Gui/Language/English/inventoryDescriptions.json
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@
},
"921a2ace-b543-4ca3-8a9b-6f3dd3132fa9": {
"title": "Color Block",
"description": "A block that can change colors.\n\nUse 1 number input to display a color from black to white (-1 is a quick way to get to white).\nUse 3 number inputs (painted red, green, blue) to use this block in RGB mode. Set each color component from 0 to 255\n\nPainting the block also works.\nCan connect color blocks together as well.\nWhite, grey, and black for glow, shine, and reflection. Colored logic input to change from RGB to HSV mode.",
"description": "A block that can change colors. Use 1 number input to display a color from black to white (-1 is a quick way to get to white). Use 3 number inputs (painted red, green, blue) to use this block in RGB mode. Set each color component from 0 to 255\n\nPainting the block also works. Can connect color blocks together as well. White for turning connected lights on/off. Colored logic input to change from RGB to HSV mode.",
"keywords": [ "modpack", "smart", "logic", "number", "rgb", "colour", "screen", "display", "pixel", "dot", "glow", "shine", "reflect", "red", "green", "blue", "glow", "custom", "paint" ]
},
"9c47ec58-bdfc-43a4-b066-852156ad812a": {
Expand Down
36 changes: 28 additions & 8 deletions Scripts/interactable/NumberLogic/ColorBlock.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@ dofile "../../libs/load_libs.lua"

print("loading ColorBlock.lua")


---@class ColorBlock : ShapeClass
---@field power number
---@field color Color
---@field prev number
---@field prevcolor table<number, string>
ColorBlock = class( nil )
ColorBlock.maxParentCount = 7
ColorBlock.maxChildCount = -1
Expand All @@ -18,7 +22,7 @@ ColorBlock.poseWeightCount = 1

function ColorBlock.server_onCreate( self )
self.power = 0
self.glowinput = 0 -- glow of this block , turn connected lamps on/off based on this.
-- self.glowinput = 0 -- glow of this block
end
function ColorBlock.server_onProjectile(self, X, hits, four)
local red = math.random(0,255)
Expand All @@ -33,25 +37,41 @@ function ColorBlock.server_onFixedUpdate( self, dt )
local green = 0
local blue = 0
local HSVmode = false
local active = nil -- turn connected lamps on/off based on this.
local parentIndicesToRemove = {}
for k, parent in pairs(parents) do
if not sm.interactable.isNumberType(parent) and
parent:getType() ~= "steering" and
tostring(parent:getShape():getShapeUuid()) ~= "ccaa33b6-e5bb-4edc-9329-b40f6efe2c9e" --[[orienter]] then
-- logic: switch, logic gate, ...
table.remove(parents, k)
table.insert(parentIndicesToRemove, k) -- We cannot directly remove the parent from the table, as it would mess up the iteration
local parentcolor = parent:getShape().color
if not (parentcolor.r == parentcolor.g) or not (parentcolor.r == parentcolor.b) then
HSVmode = parent.active
elseif tostring(parentcolor) == "eeeeeeff" then
if active == nil then
active = parent.active
else
active = active or parent.active
end
end
end
end
for i = #parentIndicesToRemove, 1, -1 do
table.remove(parents, parentIndicesToRemove[i])
end

if #parents == 1 then
self.power = math.round(sm.interactable.getPower(parents[1]))%(256^3)
local red = (self.power/(256^2))% 256
local green = (self.power % (256^2)/256)%256
local blue = self.power % 256
self.shape.color = sm.color.new(red/255, green/255, blue/255, 1)
if active == nil then
active = parents[1].active
else
-- White logic overrides the active state, so do not change it
end

elseif #parents >= 3 then
if self.prev and self.prev < 3 then -- 2 -> 3 parents event trigger , colors parents rgb
Expand Down Expand Up @@ -257,13 +277,13 @@ function ColorBlock.server_onFixedUpdate( self, dt )


self.color = color
mp_updateOutputData(self, self.power, self.glowinput > 0)
mp_updateOutputData(self, self.power, active)
end

function ColorBlock.client_onCreate(self)
--self.interactable:setGlowMultiplier(0)
self.glowinput = 0 -- glow of this block , turn connected lamps on/off based on this.
end
-- function ColorBlock.client_onCreate(self)
-- --self.interactable:setGlowMultiplier(0)
-- self.glowinput = 0 -- glow of this block , turn connected lamps on/off based on this.
-- end


function ColorBlock.client_giveError(self, error)
Expand Down
10 changes: 5 additions & 5 deletions Scripts/libs/other.lua
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@ function mp_updateOutputData(self, power, active)
self.sv_saved_power = power
sInteractable:setPower(power)

if (active ~= self.sv_saved_active) or should_reset then
self.sv_saved_active = active
sInteractable:setActive(active)
end

sm.interactable.setValue(sInteractable, power)
end

if (active ~= self.sv_saved_active) or should_reset then
self.sv_saved_active = active
sInteractable:setActive(active)
end
end

0 comments on commit a4bc13a

Please sign in to comment.