1
0
mirror of https://github.com/IkarusHD/ICF-3.git synced 2025-03-04 03:03:12 -05:00

Craftian reviews

This commit is contained in:
march 2024-12-23 17:50:37 -08:00
parent 39b2f850b2
commit bc08c99704
4 changed files with 47 additions and 21 deletions

View File

@ -12,22 +12,43 @@ function RecursiveEntityRemove(ent, track)
end
end
local bpConvertibleModelPaths = {
{
startWith = "models/sprops/rectangles",
addAngles = Angle(0, 0, 0)
}
}
function ACF.ConvertEntityToBaseplate(Player, Target)
if not IsValid(Target) then return end
if not AdvDupe2 then return false, "Advanced Duplicator 2 is not installed" end
if not IsValid(Target) then return false, "Invalid target" end
local Owner = Target:CPPIGetOwner()
if not IsValid(Owner) or Owner ~= Player then return end
if not IsValid(Owner) or Owner ~= Player then return false, "You do not own this entity" end
local PhysObj = Target:GetPhysicsObject()
if not IsValid(PhysObj) then return end
if not IsValid(PhysObj) then return false, "Entity is not physical" end
if Target:GetClass() ~= "prop_physics" then return end
if Target:GetClass() ~= "prop_physics" then return false, "Entity must be typeof 'prop_physics'" end
local foundTranslation
local targetModel = Target:GetModel()
for _, v in ipairs(bpConvertibleModelPaths) do
if string.StartsWith(targetModel, v.startWith) then
foundTranslation = v
break
end
end
if not foundTranslation then return false, "Incompatible model '" .. targetModel .. "'" end
local AMi, AMa = PhysObj:GetAABB()
local BoxSize = AMa - AMi
-- Duplicate the entire thing
local Entities, Constraints = AdvDupe2.duplicator.Copy(Player, Target, {}, {}, Vector(0, 0, 0))
local Entities, Constraints = AdvDupe2.duplicator.Copy(Player, Target, {}, {}, vector_origin)
-- Find the baseplate
local Baseplate = Entities[Target:EntIndex()]
@ -38,6 +59,7 @@ function ACF.ConvertEntityToBaseplate(Player, Target)
Baseplate.Length = w
Baseplate.Width = l
Baseplate.Thickness = t
Baseplate.PhysicsObjects[0].Angle = Baseplate.PhysicsObjects[0].Angle + foundTranslation.addAngles
-- Delete everything now
for k, _ in pairs(Entities) do
@ -46,7 +68,7 @@ function ACF.ConvertEntityToBaseplate(Player, Target)
end
-- Paste the stuff back to the dupe
local Ents = AdvDupe2.duplicator.Paste(Owner, Entities, Constraints, Vector(0, 0, 0), Angle(0, 0, 0), Vector(0, 0, 0), true)
local Ents = AdvDupe2.duplicator.Paste(Owner, Entities, Constraints, vector_origin, angle_zero, vector_origin, true)
-- Try to find the baseplate
local NewBaseplate
for _, v in pairs(Ents) do
@ -61,5 +83,5 @@ function ACF.ConvertEntityToBaseplate(Player, Target)
undo.SetPlayer(Player)
undo.Finish()
return NewBaseplate
return true, NewBaseplate
end

View File

@ -1,6 +1,6 @@
local ACF = ACF
local gridMaterial = CreateMaterial("acf_bp_vis_spropgrid1", "VertexLitGeneric", {
local gridMaterial = CreateMaterial("acf_bp_vis_grid1", "VertexLitGeneric", {
["$basetexture"] = "hunter/myplastic",
["$model"] = 1,
["$translucent"] = 1,
@ -16,9 +16,10 @@ local function CreateMenu(Menu)
Menu:AddTitle("Baseplate Settings")
Menu:AddLabel("The root entity of all ACF contraptions.")
local SizeX = Menu:AddSlider("Plate Width (gmu)", 36, 96, 2)
local SizeY = Menu:AddSlider("Plate Length (gmu)", 36, 420, 2)
local SizeZ = Menu:AddSlider("Plate Thickness (gmu)", 0.5, 3, 2)
local BaseplateBase = Menu:AddCollapsible("Baseplate Information")
local SizeX = BaseplateBase:AddSlider("Plate Width (gmu)", 36, 96, 2)
local SizeY = BaseplateBase:AddSlider("Plate Length (gmu)", 36, 420, 2)
local SizeZ = BaseplateBase:AddSlider("Plate Thickness (gmu)", 0.5, 3, 2)
Menu:AddLabel("Comparing the current dimensions with a 105mm Howitzer:")
local Vis = Menu:AddModelPreview("models/howitzer/howitzer_105mm.mdl", true)
@ -28,7 +29,7 @@ local function CreateMenu(Menu)
self.CamDistance = math.max(w, h, 60) * 1
render.SetMaterial(gridMaterial)
render.DrawBox(Vector(0, 0, 0), Angle(0, 0, 0), Vector(-h / 2, -w / 2, -t / 2), Vector(h / 2, w / 2, t / 2), color_white)
render.DrawBox(vector_origin, angle_zero, Vector(-h / 2, -w / 2, -t / 2), Vector(h / 2, w / 2, t / 2), color_white)
end
SizeX:SetClientData("Width", "OnValueChanged")

View File

@ -335,9 +335,12 @@ ACF.CreateMenuOperation("3-Gyro", "turret gyroscope")
ACF.CreateMenuOperation("4-Computer", "turret computer")
ACF.CreateMenuOperation("Baseplate", "baseplate", nil, {
Text = "Convert the target entity into a baseplate. Works best on SProps rectangles (either normal, thin, or superthin). Other models not supported.",
Text = "Attempts to convert the target entity into a baseplate.",
Func = function(Tool, Trace)
if CLIENT then return end
ACF.ConvertEntityToBaseplate(Tool.SWEP:GetOwner(), Trace.Entity)
local success, msg = ACF.ConvertEntityToBaseplate(Tool.SWEP:GetOwner(), Trace.Entity)
if not success then
ACF.SendNotify(Tool:GetOwner(), err, "[ACF] Could not convert baseplate: " .. msg)
end
end
})

View File

@ -4,9 +4,9 @@ function ENT:Update() end
local HideInfo = ACF.HideInfoBubble
local COLOR_Black = Color(0, 0, 0)
local COLOR_Red = Color(255, 50, 40)
local COLOR_Green = Color(40, 255, 50)
local ColorBlack = Color(0, 0, 0)
local ColorRed = Color(255, 50, 40)
local ColorGreen = Color(40, 255, 50)
function ENT:DrawGizmos()
cam.IgnoreZ(true)
@ -15,10 +15,10 @@ function ENT:DrawGizmos()
local Size = self.Size
render.SetColorMaterial()
render.DrawBeam(Pos, self:LocalToWorld(Vector(Size.x / 2, 0, 0)), 2, 0, 1, COLOR_Black)
render.DrawBeam(Pos, self:LocalToWorld(Vector(Size.x / 2, 0, 0)), 1, 0, 1, COLOR_Red)
render.DrawBeam(Pos, self:LocalToWorld(Vector(0, -Size.y / 2, 0)), 2, 0, 1, COLOR_Black)
render.DrawBeam(Pos, self:LocalToWorld(Vector(0, -Size.y / 2, 0)), 1, 0, 1, COLOR_Green)
render.DrawBeam(Pos, self:LocalToWorld(Vector(Size.x / 2, 0, 0)), 2, 0, 1, ColorBlack)
render.DrawBeam(Pos, self:LocalToWorld(Vector(Size.x / 2, 0, 0)), 1, 0, 1, ColorRed)
render.DrawBeam(Pos, self:LocalToWorld(Vector(0, -Size.y / 2, 0)), 2, 0, 1, ColorBlack)
render.DrawBeam(Pos, self:LocalToWorld(Vector(0, -Size.y / 2, 0)), 1, 0, 1, ColorGreen)
cam.IgnoreZ(false)
end