mirror of
https://github.com/APercy/automobiles_pck
synced 2025-09-28 22:06:22 +02:00
made the mod own painter
This commit is contained in:
parent
bc55c94470
commit
fc66c5ee9b
10
automobiles_lib/README.md
Executable file
10
automobiles_lib/README.md
Executable file
@ -0,0 +1,10 @@
|
||||
Coupe
|
||||
|
||||
This mod adds library for automobiles
|
||||
|
||||
licence of code
|
||||
LGPL3
|
||||
except painter.lua, licenced as MIT
|
||||
|
||||
licence of the media:
|
||||
licence CC0
|
@ -47,57 +47,6 @@ function automobiles_lib.minmax(v,m)
|
||||
return math.min(math.abs(v),m)*minekart.sign(v)
|
||||
end
|
||||
|
||||
function automobiles_lib.set_paint(self, puncher, itmstck)
|
||||
local item_name = ""
|
||||
if itmstck then item_name = itmstck:get_name() end
|
||||
|
||||
if item_name == "bike:painter" then
|
||||
--painting with bike painter
|
||||
local meta = itmstck:get_meta()
|
||||
local colstr = meta:get_string("paint_color")
|
||||
automobiles_lib.paint(self, colstr)
|
||||
return true
|
||||
else
|
||||
--painting with dyes
|
||||
local split = string.split(item_name, ":")
|
||||
local color, indx, _
|
||||
if split[1] then _,indx = split[1]:find('dye') end
|
||||
if indx then
|
||||
for clr,_ in pairs(automobiles_lib.colors) do
|
||||
local _,x = split[2]:find(clr)
|
||||
if x then color = clr end
|
||||
end
|
||||
--lets paint!!!!
|
||||
--local color = item_name:sub(indx+1)
|
||||
local colstr = automobiles_lib.colors[color]
|
||||
--minetest.chat_send_all(color ..' '.. dump(colstr))
|
||||
if colstr then
|
||||
automobiles_lib.paint(self, colstr)
|
||||
itmstck:set_count(itmstck:get_count()-1)
|
||||
puncher:set_wielded_item(itmstck)
|
||||
return true
|
||||
end
|
||||
-- end painting
|
||||
end
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
--painting
|
||||
function automobiles_lib.paint(self, colstr)
|
||||
if colstr then
|
||||
self._color = colstr
|
||||
local l_textures = self.initial_properties.textures
|
||||
for _, texture in ipairs(l_textures) do
|
||||
local indx = texture:find('automobiles_painting.png')
|
||||
if indx then
|
||||
l_textures[_] = "automobiles_painting.png^[multiply:".. colstr
|
||||
end
|
||||
end
|
||||
self.object:set_properties({textures=l_textures})
|
||||
end
|
||||
end
|
||||
|
||||
--returns 0 for old, 1 for new
|
||||
function automobiles_lib.detect_player_api(player)
|
||||
local player_proterties = player:get_properties()
|
||||
@ -390,10 +339,62 @@ minetest.register_node("automobiles_lib:light", {
|
||||
},
|
||||
})
|
||||
|
||||
function automobiles_lib.set_paint(self, puncher, itmstck)
|
||||
local item_name = ""
|
||||
if itmstck then item_name = itmstck:get_name() end
|
||||
|
||||
if item_name == "automobiles_lib:painter" or item_name == "bike:painter" then
|
||||
--painting with bike painter
|
||||
local meta = itmstck:get_meta()
|
||||
local colstr = meta:get_string("paint_color")
|
||||
automobiles_lib.paint(self, colstr)
|
||||
return true
|
||||
else
|
||||
--painting with dyes
|
||||
local split = string.split(item_name, ":")
|
||||
local color, indx, _
|
||||
if split[1] then _,indx = split[1]:find('dye') end
|
||||
if indx then
|
||||
for clr,_ in pairs(automobiles_lib.colors) do
|
||||
local _,x = split[2]:find(clr)
|
||||
if x then color = clr end
|
||||
end
|
||||
--lets paint!!!!
|
||||
--local color = item_name:sub(indx+1)
|
||||
local colstr = automobiles_lib.colors[color]
|
||||
--minetest.chat_send_all(color ..' '.. dump(colstr))
|
||||
if colstr then
|
||||
automobiles_lib.paint(self, colstr)
|
||||
itmstck:set_count(itmstck:get_count()-1)
|
||||
puncher:set_wielded_item(itmstck)
|
||||
return true
|
||||
end
|
||||
-- end painting
|
||||
end
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
--painting
|
||||
function automobiles_lib.paint(self, colstr)
|
||||
if colstr then
|
||||
self._color = colstr
|
||||
local l_textures = self.initial_properties.textures
|
||||
for _, texture in ipairs(l_textures) do
|
||||
local indx = texture:find('automobiles_painting.png')
|
||||
if indx then
|
||||
l_textures[_] = "automobiles_painting.png^[multiply:".. colstr
|
||||
end
|
||||
end
|
||||
self.object:set_properties({textures=l_textures})
|
||||
end
|
||||
end
|
||||
|
||||
dofile(minetest.get_modpath("automobiles_lib") .. DIR_DELIM .. "custom_physics.lua")
|
||||
dofile(minetest.get_modpath("automobiles_lib") .. DIR_DELIM .. "control.lua")
|
||||
dofile(minetest.get_modpath("automobiles_lib") .. DIR_DELIM .. "fuel_management.lua")
|
||||
dofile(minetest.get_modpath("automobiles_lib") .. DIR_DELIM .. "ground_detection.lua")
|
||||
dofile(minetest.get_modpath("automobiles_lib") .. DIR_DELIM .. "painter.lua")
|
||||
|
||||
-- engine
|
||||
minetest.register_craftitem("automobiles_lib:engine",{
|
||||
|
145
automobiles_lib/painter.lua
Normal file
145
automobiles_lib/painter.lua
Normal file
@ -0,0 +1,145 @@
|
||||
--[[
|
||||
Copyright (C) 2022 Alexsandro Percy
|
||||
Copyright (C) 2018 Hume2
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
]]--
|
||||
|
||||
--[[painting functions adapted from bike mod]]--
|
||||
|
||||
local function is_hex(color)
|
||||
if color:len() ~= 7 then return nil end
|
||||
return color:match("#%x%x%x%x%x%x")
|
||||
end
|
||||
|
||||
-- hex translation
|
||||
local function hex_to_rgb(hex_value)
|
||||
hex_value = hex_value:gsub("#","")
|
||||
local rgb = {
|
||||
r = tonumber("0x"..hex_value:sub(1,2)),
|
||||
g = tonumber("0x"..hex_value:sub(3,4)),
|
||||
b = tonumber("0x"..hex_value:sub(5,6)),
|
||||
}
|
||||
return rgb
|
||||
end
|
||||
|
||||
local function rgb_to_hex(r, g, b)
|
||||
return string.format("#%02X%02X%02X", r, g, b)
|
||||
end
|
||||
|
||||
-- Need to convert between 1000 units and 256
|
||||
local function from_slider_rgb(value)
|
||||
value = tonumber(value)
|
||||
return math.floor((255/1000*value)+0.5)
|
||||
end
|
||||
|
||||
-- ...and back
|
||||
local function to_slider_rgb(value)
|
||||
if value then
|
||||
return 1000/255*value
|
||||
end
|
||||
return 1000/255*255
|
||||
end
|
||||
|
||||
-- Painter formspec
|
||||
local function painter_form(itemstack, player)
|
||||
local meta = itemstack:get_meta()
|
||||
local color = meta:get_string("paint_color")
|
||||
if color == nil or color == "" then
|
||||
color = "#FFFFFF"
|
||||
meta:set_string("paint_color", color)
|
||||
meta:set_string("description", "Automobiles Painter ("..color:upper()..")")
|
||||
end
|
||||
local rgb = hex_to_rgb(color)
|
||||
minetest.show_formspec(player:get_player_name(), "automobiles_lib:painter",
|
||||
-- Init formspec
|
||||
"size[6,4.7;true]"..
|
||||
"position[0.5, 0.45]"..
|
||||
-- Preview
|
||||
"label[0,0;Preview:]"..
|
||||
"image[1.2,0;2,2;automobiles_painting.png^[colorize:"..color..":255]"..
|
||||
-- RGB sliders
|
||||
"scrollbar[0,2;5,0.3;horizontal;r;"..tostring(to_slider_rgb(rgb.r)).."]"..
|
||||
"label[5.1,1.9;R: "..tostring(rgb.r).."]"..
|
||||
"scrollbar[0,2.6;5,0.3;horizontal;g;"..tostring(to_slider_rgb(rgb.g)).."]"..
|
||||
"label[5.1,2.5;G: "..tostring(rgb.g).."]"..
|
||||
"scrollbar[0,3.2;5,0.3;horizontal;b;"..tostring(to_slider_rgb(rgb.b)).."]"..
|
||||
"label[5.1,3.1;B: "..tostring(rgb.b).."]"..
|
||||
-- Hex field
|
||||
"field[0.3,4.5;2,0.8;hex;Hex Color;"..color.."]"..
|
||||
"button[4.05,4.1;2,1;set;Set color]"
|
||||
)
|
||||
end
|
||||
|
||||
minetest.register_on_player_receive_fields(function(player, formname, fields)
|
||||
if formname == "automobiles_lib:painter" then
|
||||
local itemstack = player:get_wielded_item()
|
||||
if fields.set then
|
||||
if itemstack:get_name() == "automobiles_lib:painter" then
|
||||
local meta = itemstack:get_meta()
|
||||
local hex = fields.hex
|
||||
if hex then
|
||||
if is_hex(hex) == nil then
|
||||
hex = "#FFFFFF"
|
||||
end
|
||||
-- Save color data to painter (rgba sliders will adjust to hex/alpha too!)
|
||||
meta:set_string("paint_color", hex)
|
||||
meta:set_string("description", "Automobiles Painter ("..hex:upper()..")")
|
||||
player:set_wielded_item(itemstack)
|
||||
painter_form(itemstack, player)
|
||||
return
|
||||
end
|
||||
end
|
||||
end
|
||||
if fields.r or fields.g or fields.b then
|
||||
if itemstack:get_name() == "automobiles_lib:painter" then
|
||||
-- Save on slider adjustment (hex/alpha will adjust to match the rgba!)
|
||||
local meta = itemstack:get_meta()
|
||||
local function sval(value)
|
||||
return from_slider_rgb(value:gsub(".*:", ""))
|
||||
end
|
||||
meta:set_string("paint_color", rgb_to_hex(sval(fields.r),sval(fields.g),sval(fields.b)))
|
||||
-- Keep track of what this painter is painting
|
||||
meta:set_string("description", "Automobiles Painter ("..meta:get_string("paint_color"):upper()..")")
|
||||
player:set_wielded_item(itemstack)
|
||||
painter_form(itemstack, player)
|
||||
end
|
||||
end
|
||||
end
|
||||
end)
|
||||
--[[end of adaptations]]--
|
||||
|
||||
|
||||
-- Make the actual thingy
|
||||
minetest.register_tool("automobiles_lib:painter", {
|
||||
description = "Automobiles Painter",
|
||||
inventory_image = "automobiles_painter.png",
|
||||
wield_scale = {x = 2, y = 2, z = 1},
|
||||
on_place = painter_form,
|
||||
on_secondary_use = painter_form,
|
||||
})
|
||||
|
||||
minetest.register_craft({
|
||||
output = "automobiles_lib:painter",
|
||||
recipe = {
|
||||
{"", "default:steel_ingot", ""},
|
||||
{"dye:red", "dye:green", "dye:blue"},
|
||||
{"", "default:steel_ingot", ""},
|
||||
},
|
||||
})
|
BIN
automobiles_lib/textures/automobiles_painter.png
Normal file
BIN
automobiles_lib/textures/automobiles_painter.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 5.5 KiB |
Loading…
Reference in New Issue
Block a user