Racelogic, Mustang, Porsche, etc.
This commit is contained in:
@@ -9,7 +9,7 @@
|
||||
-- @include /koptilnya/gui/elements/shape.txt
|
||||
-- @include /koptilnya/gui/elements/button.txt
|
||||
-- @include /koptilnya/gui/segoe_mdl2_assets_icons.txt
|
||||
local points = {Vector(0, 0)}
|
||||
local points = {Vector(0, 0), Vector(100, 0)}
|
||||
local zoom = 1
|
||||
local zoomBase = 100
|
||||
local scroll = 0
|
||||
@@ -254,7 +254,7 @@ local function removePoint()
|
||||
end
|
||||
end
|
||||
|
||||
local function getTorqueAt(t)
|
||||
local function getYAt(t)
|
||||
if #points == 0 then
|
||||
return 0
|
||||
end
|
||||
@@ -281,23 +281,27 @@ local function getTorqueAt(t)
|
||||
end
|
||||
end
|
||||
|
||||
local function exportPoints()
|
||||
local function exportPoints(asE2Array)
|
||||
if not hasPermission("file.write") then
|
||||
return
|
||||
end
|
||||
|
||||
asE2Array = asE2Array or false
|
||||
|
||||
local result = ""
|
||||
local prefix = asE2Array and "array(" or "{"
|
||||
local suffix = asE2Array and ")" or "}"
|
||||
local vecSyntax = asE2Array and "vec2" or "Vector"
|
||||
|
||||
for k, v in pairs(points) do
|
||||
result = result .. "\tVector(" .. (v.x / 100) .. ", " .. v.y .. ")"
|
||||
result = result .. "\t" .. vecSyntax .. "(" .. (v.x / 100) .. ", " .. v.y .. ")"
|
||||
|
||||
if k ~= #points then
|
||||
result = result .. ",\n"
|
||||
end
|
||||
end
|
||||
|
||||
result = "array(\n" .. result
|
||||
result = result .. "\n)"
|
||||
|
||||
result = string.format("%s\n%s\n%s", prefix, result, suffix)
|
||||
|
||||
file.write("torque_export_result.txt", result)
|
||||
end
|
||||
@@ -310,7 +314,7 @@ local function exportTorqueMap()
|
||||
local result = ""
|
||||
|
||||
for i = 0, 100 do
|
||||
result = result .. "\t" .. getTorqueAt(i)
|
||||
result = result .. "\t" .. getYAt(i)
|
||||
|
||||
if i ~= 100 then
|
||||
result = result .. ",\n"
|
||||
@@ -323,74 +327,85 @@ local function exportTorqueMap()
|
||||
file.write("torque_export_result.txt", result)
|
||||
end
|
||||
|
||||
net.receive("setUser", function()
|
||||
net.readEntity(function(ent)
|
||||
user = ent
|
||||
end)
|
||||
end)
|
||||
local renderDevice = RenderDeviceHUD:new()
|
||||
local scrW, scrH = 1920, 1080
|
||||
|
||||
net.receive("resetUser", function()
|
||||
user = nil
|
||||
end)
|
||||
local gui = GUI:new(renderDevice)
|
||||
local w, h = 190, 226
|
||||
local panel = EPanel:new()
|
||||
panel:setTitle("Torque Editor")
|
||||
panel:setDraggable(false)
|
||||
panel:setMinimizable(false)
|
||||
panel:setCloseable(false)
|
||||
panel:setPos(scrW - w - 20, scrH - h - 20)
|
||||
panel:setSize(w, h)
|
||||
gui:add(panel)
|
||||
|
||||
net.receive("init", function()
|
||||
zoom = net.readFloat()
|
||||
scroll = net.readFloat()
|
||||
points = net.readTable()
|
||||
end)
|
||||
|
||||
net.receive("settings", function()
|
||||
zoom = net.readFloat()
|
||||
scroll = net.readFloat()
|
||||
end)
|
||||
|
||||
net.receive("points", function()
|
||||
points = net.readTable()
|
||||
end)
|
||||
|
||||
hook.add("hudconnected", "_hudconnected", function()
|
||||
-- renderDevice:setPlayer()
|
||||
if not hasPermission("file.write") or not hasPermission("file.read") then
|
||||
sendPermissionRequest()
|
||||
local importButton = EButton:new()
|
||||
importButton:setPos(11, 43)
|
||||
importButton:setSize(w - 22, 24)
|
||||
importButton:setText("Import")
|
||||
importButton.onMousePressed = function(_, x, y, key, keyName)
|
||||
if keyName == "MOUSE1" then
|
||||
end
|
||||
end)
|
||||
end
|
||||
panel:addChild(importButton)
|
||||
|
||||
hook.add("huddisconnected", "_huddisconnected", function()
|
||||
end)
|
||||
local dividerShape = EShape:new()
|
||||
dividerShape:setPos(11, 82)
|
||||
dividerShape:setSize(w - 22, 1)
|
||||
dividerShape:setColor(Color(60, 60, 60))
|
||||
panel:addChild(dividerShape)
|
||||
|
||||
hook.add("inputPressed", "_inputPressed", function(button)
|
||||
if not hasPermission("input") then
|
||||
return
|
||||
local exportLabel = ELabel:new()
|
||||
exportLabel:setPos(11, 97)
|
||||
exportLabel:setFont(GUI.fonts.mainBold)
|
||||
exportLabel:setText("Export as")
|
||||
panel:addChild(exportLabel)
|
||||
|
||||
local pointsArrayLabel = ELabel:new()
|
||||
pointsArrayLabel:setPos(11, 126)
|
||||
pointsArrayLabel:setText("Points array")
|
||||
pointsArrayLabel:setColorScheme(Color(200, 200, 200))
|
||||
panel:addChild(pointsArrayLabel)
|
||||
|
||||
local exportE2ArrayButton = EButton:new()
|
||||
exportE2ArrayButton:setPos(w - 91, 123)
|
||||
exportE2ArrayButton:setText("E2")
|
||||
exportE2ArrayButton:setSize(35, 24)
|
||||
exportE2ArrayButton.onMousePressed = function(_, x, y, key, keyName)
|
||||
if keyName == "MOUSE1" then
|
||||
exportPoints(true)
|
||||
end
|
||||
end
|
||||
panel:addChild(exportE2ArrayButton)
|
||||
|
||||
if player() == user then
|
||||
local keyName = input.getKeyName(button)
|
||||
|
||||
if keyName == "t" then
|
||||
input.enableCursor(input.getCursorVisible())
|
||||
elseif keyName == "MOUSE1" then
|
||||
if not input.getCursorVisible() then
|
||||
addPoint()
|
||||
end
|
||||
elseif keyName == "MOUSE2" then
|
||||
if not input.getCursorVisible() then
|
||||
removePoint()
|
||||
end
|
||||
elseif keyName == "MWHEELUP" then
|
||||
if input.isShiftDown() then
|
||||
zoomIn()
|
||||
else
|
||||
scrollUp()
|
||||
end
|
||||
elseif keyName == "MWHEELDOWN" then
|
||||
if input.isShiftDown() then
|
||||
zoomOut()
|
||||
else
|
||||
scrollDown()
|
||||
end
|
||||
end
|
||||
local exportSFArrayButton = EButton:new()
|
||||
exportSFArrayButton:setPos(w - 46, 123)
|
||||
exportSFArrayButton:setText("SF")
|
||||
exportSFArrayButton:setSize(35, 24)
|
||||
exportSFArrayButton.onMousePressed = function(_, x, y, key, keyName)
|
||||
if keyName == "MOUSE1" then
|
||||
exportPoints()
|
||||
end
|
||||
end)
|
||||
end
|
||||
panel:addChild(exportSFArrayButton)
|
||||
|
||||
local exportMapButton = EButton:new()
|
||||
exportMapButton:setPos(11, 157)
|
||||
exportMapButton:setText("Torque map")
|
||||
exportMapButton:setSize(w - 22, 24)
|
||||
exportMapButton.onMousePressed = function(_, x, y, key, keyName)
|
||||
if keyName == "MOUSE1" then
|
||||
exportTorqueMap()
|
||||
end
|
||||
end
|
||||
panel:addChild(exportMapButton)
|
||||
|
||||
local pointsCountLabel = ELabel:new()
|
||||
pointsCountLabel:setPos(11, 200)
|
||||
pointsCountLabel:setText("Points count: " .. #points)
|
||||
panel:addChild(pointsCountLabel)
|
||||
|
||||
hook.add("render", "_render", function()
|
||||
local cursorX, cursorY
|
||||
@@ -497,84 +512,90 @@ hook.add("render", "_render", function()
|
||||
|
||||
prevPointData = {point = point, x = x, y = y}
|
||||
end
|
||||
--[[
|
||||
|
||||
local t = (math.cos(timer.curtime() * 0.5) + 1) / 2 * 100
|
||||
|
||||
x, y = fromWorkspacePos(cellSize.x * t, (workspace.h - 1) / (zoomBase / zoom) * getTorqueAt(t) - ((workspace.h - 1) / 10 * scroll))
|
||||
x, y = fromWorkspacePos(cellSize.x * t, (workspace.h - 1) / (zoomBase / zoom) * getYAt(t) - ((workspace.h - 1) / 10 * scroll))
|
||||
|
||||
render.setColor(Color(0, 0, 255, 180))
|
||||
render.drawRect(x - 3, y - 3, 7, 7)
|
||||
|
||||
render.drawRect(x, workspace.y, 1, workspace.h)
|
||||
]]
|
||||
end)
|
||||
|
||||
local renderDevice = RenderDeviceHUD:new()
|
||||
local scrW, scrH = 1920, 1080
|
||||
net.receive("setUser", function()
|
||||
net.readEntity(function(ent)
|
||||
user = ent
|
||||
end)
|
||||
end)
|
||||
|
||||
local gui = GUI:new(renderDevice)
|
||||
net.receive("resetUser", function()
|
||||
user = nil
|
||||
end)
|
||||
|
||||
local panel = EPanel:new()
|
||||
panel:setTitle("Torque Editor")
|
||||
panel:setDraggable(false)
|
||||
panel:setMinimizable(false)
|
||||
panel:setCloseable(false)
|
||||
panel:setPos(scrW - 180 - 20, scrH - 226 - 20)
|
||||
panel:setSize(180, 226)
|
||||
gui:add(panel)
|
||||
net.receive("init", function()
|
||||
zoom = net.readFloat()
|
||||
scroll = net.readFloat()
|
||||
points = net.readTable()
|
||||
end)
|
||||
|
||||
local importButton = EButton:new()
|
||||
importButton:setPos(11, 43)
|
||||
importButton:setSize(158, 24)
|
||||
importButton:setText("Import")
|
||||
importButton.onMousePressed = function(_, x, y, key, keyName)
|
||||
if keyName == "MOUSE1" then
|
||||
net.receive("settings", function()
|
||||
zoom = math.round(net.readFloat() * 100) / 100
|
||||
scroll = math.round(net.readFloat() * 100) / 100
|
||||
|
||||
|
||||
end)
|
||||
|
||||
net.receive("points", function()
|
||||
points = net.readTable()
|
||||
|
||||
pointsCountLabel:setText("Points count: " .. #points)
|
||||
end)
|
||||
|
||||
hook.add("hudconnected", "_hudconnected", function()
|
||||
-- renderDevice:setPlayer()
|
||||
if not hasPermission("file.write") or not hasPermission("file.read") then
|
||||
sendPermissionRequest()
|
||||
end
|
||||
end
|
||||
panel:addChild(importButton)
|
||||
end)
|
||||
|
||||
local dividerShape = EShape:new()
|
||||
dividerShape:setPos(11, 82)
|
||||
dividerShape:setSize(158, 1)
|
||||
dividerShape:setColor(Color(60, 60, 60))
|
||||
panel:addChild(dividerShape)
|
||||
hook.add("huddisconnected", "_huddisconnected", function()
|
||||
end)
|
||||
|
||||
local exportLabel = ELabel:new()
|
||||
exportLabel:setPos(11, 97)
|
||||
exportLabel:setText("Export as")
|
||||
panel:addChild(exportLabel)
|
||||
|
||||
--[[
|
||||
local exportCurveButton = EButton:new()
|
||||
exportCurveButton:setPos(11, 123)
|
||||
exportCurveButton:setText("Points array")
|
||||
exportCurveButton:setSize(158, 24)
|
||||
exportCurveButton.onMousePressed = function(_, x, y, key, keyName)
|
||||
if keyName == "MOUSE1" then
|
||||
exportPoints()
|
||||
hook.add("inputPressed", "_inputPressed", function(button)
|
||||
if not hasPermission("input") then
|
||||
return
|
||||
end
|
||||
end
|
||||
panel:addChild(exportCurveButton)
|
||||
]]
|
||||
|
||||
local pointsArrayLabel = ELabel:new()
|
||||
pointsArrayLabel:setPos(11, 123)
|
||||
pointsArrayLabel:setText("Points array")
|
||||
pointsArrayLabel:setColorScheme(Color(200, 200, 200))
|
||||
panel:addChild(pointsArrayLabel)
|
||||
if player() == user then
|
||||
local keyName = input.getKeyName(button)
|
||||
|
||||
local exportMapButton = EButton:new()
|
||||
exportMapButton:setPos(11, 157)
|
||||
exportMapButton:setText("Torque map")
|
||||
exportMapButton:setSize(158, 24)
|
||||
exportMapButton.onMousePressed = function(_, x, y, key, keyName)
|
||||
if keyName == "MOUSE1" then
|
||||
exportTorqueMap()
|
||||
if keyName == "t" then
|
||||
input.enableCursor(!input.getCursorVisible())
|
||||
elseif keyName == "MOUSE1" then
|
||||
if not input.getCursorVisible() then
|
||||
addPoint()
|
||||
|
||||
pointsCountLabel:setText("Points count: " .. #points)
|
||||
end
|
||||
elseif keyName == "MOUSE2" then
|
||||
if not input.getCursorVisible() then
|
||||
removePoint()
|
||||
|
||||
pointsCountLabel:setText("Points count: " .. #points)
|
||||
end
|
||||
elseif keyName == "MWHEELUP" then
|
||||
if input.isShiftDown() then
|
||||
zoomIn()
|
||||
else
|
||||
scrollUp()
|
||||
end
|
||||
elseif keyName == "MWHEELDOWN" then
|
||||
if input.isShiftDown() then
|
||||
zoomOut()
|
||||
else
|
||||
scrollDown()
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
panel:addChild(exportMapButton)
|
||||
|
||||
local pointsCountLabel = ELabel:new()
|
||||
pointsCountLabel:setPos(11, 200)
|
||||
pointsCountLabel:setText("Points count: " .. #points)
|
||||
panel:addChild(pointsCountLabel)
|
||||
end)
|
||||
|
||||
Reference in New Issue
Block a user