Add initial glualint setup

This commit is contained in:
James Ross 2019-01-26 23:53:58 +00:00
parent 3567788bfa
commit c78b523d77
8 changed files with 137 additions and 59 deletions

40
.gitignore vendored Normal file
View File

@ -0,0 +1,40 @@
# Compiled Lua sources
luac.out
# luarocks build files
*.src.rock
*.zip
*.tar.gz
# Object files
*.o
*.os
*.ko
*.obj
*.elf
# Precompiled Headers
*.gch
*.pch
# Libraries
*.lib
*.a
*.la
*.lo
*.def
*.exp
# Shared objects (inc. Windows DLLs)
*.dll
*.so
*.so.*
*.dylib
# Executables
*.exe
*.out
*.app
*.i*86
*.x86_64
*.hex

25
.glualint.json Normal file
View File

@ -0,0 +1,25 @@
{
"lint_maxScopeDepth": 7,
"lint_syntaxErrors": true,
"lint_syntaxInconsistencies": true,
"lint_deprecated": true,
"lint_whitespaceStyle": true,
"lint_beginnerMistakes": true,
"lint_emptyBlocks": true,
"lint_shadowing": true,
"lint_gotos": true,
"lint_doubleNegations": true,
"lint_duplicateTableKeys": true,
"lint_profanity": true,
"lint_unusedVars": true,
"lint_unusedParameters": false,
"lint_unusedLoopVars": false,
"prettyprint_spaceAfterParens": false,
"prettyprint_spaceAfterBrackets": false,
"prettyprint_spaceAfterBraces": false,
"prettyprint_spaceBeforeComma": false,
"prettyprint_spaceAfterComma": true,
"prettyprint_semicolons": false,
"prettyprint_cStyle": false,
"prettyprint_indentation": " "
}

8
.travis.yml Normal file
View File

@ -0,0 +1,8 @@
language: minimal
install:
- curl -o glualint.zip -L https://github.com/FPtje/GLuaFixer/releases/download/1.10.0/glualint-1.10.0-linux.zip
- unzip glualint.zip
script:
- ./glualint lua

View File

@ -1,8 +1,14 @@
{
"title" : "3D2D Textscreens",
"type" : "tool",
"tags" : [ "fun", "roleplay" ],
"ignore" :
[
"title": "3D2D Textscreens",
"type": "tool",
"tags": [
"fun",
"roleplay"
],
"ignore": [
".glualint.json",
"LICENSE",
"*.exe",
"*.md"
]
}

View File

@ -45,7 +45,7 @@ if SERVER then
end)
cvars.AddChangeCallback("ss_call_to_home", function(convar_name, value_old, value_new)
if(value_new == "1") then
if value_new == "1" then
submitAnalytics()
end
end)
@ -88,8 +88,8 @@ if SERVER then
textScreen:Activate()
textScreen:SetMoveType(MOVETYPE_NONE)
for k, v in pairs(v.lines or {}) do
textScreen:SetLine(k, v.text, Color(v.color.r, v.color.g, v.color.b, v.color.a), v.size, v.font)
for lineNum, lineData in pairs(v.lines or {}) do
textScreen:SetLine(lineNum, lineData.text, Color(lineData.color.r, lineData.color.g, lineData.color.b, lineData.color.a), lineData.size, lineData.font)
end
textScreen:SetIsPersisted(true)

View File

@ -24,7 +24,7 @@ hook.Add("Think", "ss_should_draw_both_sides", function()
end)
local function ValidFont(f)
if textscreenFonts[f] != nil then
if textscreenFonts[f] ~= nil then
return textscreenFonts[f]
elseif table.HasValue(textscreenFonts, f) then
return f
@ -47,19 +47,19 @@ end
local product
local function IsInFront(entPos, plyShootPos, direction)
product = (entPos.x - plyShootPos.x) * direction.x +
(entPos.y - plyShootPos.y) * direction.y +
(entPos.z - plyShootPos.z) * direction.z
return (product < 0)
product = (entPos.x - plyShootPos.x) * direction.x +
(entPos.y - plyShootPos.y) * direction.y +
(entPos.z - plyShootPos.z) * direction.z
return product < 0
end
-- Draws the 3D2D text with the given positions, angles and data(text/font/col)
local function Draw3D2D(ang, pos, camangle, data)
cam.Start3D2D(pos, camangle, .25)
render.PushFilterMin(TEXFILTER.ANISOTROPIC)
-render.PushFilterMin(TEXFILTER.ANISOTROPIC)
-- Loop through each line
for i=1, data[LEN] do
for i = 1, data[LEN] do
if not data[i] or not data[i][TEXT] then continue end
-- Font
surface.SetFont(data[i][FONT])
@ -80,7 +80,7 @@ function ENT:DrawTranslucent()
-- Cache the shoot pos for this frame
plyShootPos = LocalPlayer():GetShootPos()
if screenInfo[self] != nil and self:GetPos():DistToSqr(plyShootPos) < render_range then
if screenInfo[self] ~= nil and self:GetPos():DistToSqr(plyShootPos) < render_range then
ang = self:GetAngles()
pos = self:GetPos() + ang:Up()
camangle = Angle(ang.p, ang.y, ang.r)
@ -108,48 +108,48 @@ function ENT:DrawTranslucent()
end
local function AddDrawingInfo(ent, rawData)
local data = {}
local drawData = {}
local textSize = {}
local totalHeight = 0
local maxWidth = 0
local currentHeight = 0
for i=1, #rawData do
for i = 1, #rawData do
-- Setup tables
if not rawData[i] or not rawData[i].text then continue end
data[i] = {}
drawData[i] = {}
textSize[i] = {}
-- Text
data[i][TEXT] = rawData[i].text
drawData[i][TEXT] = rawData[i].text
-- Font
data[i][FONT] = (ValidFont(rawData[i].font) or textscreenFonts[1]) .. rawData[i].size
drawData[i][FONT] = (ValidFont(rawData[i].font) or textscreenFonts[1]) .. rawData[i].size
-- Text size
surface.SetFont(data[i][FONT])
textSize[i][1], textSize[i][2] = surface.GetTextSize(data[i][TEXT])
surface.SetFont(drawData[i][FONT])
textSize[i][1], textSize[i][2] = surface.GetTextSize(drawData[i][TEXT])
-- Workout max width for render bounds
maxWidth = maxWidth > textSize[i][1] and maxWidth or textSize[i][1]
-- Position
totalHeight = totalHeight + textSize[i][2]
-- Colour
data[i][COL] = Color(rawData[i].color.r, rawData[i].color.g, rawData[i].color.b, 255)
drawData[i][COL] = Color(rawData[i].color.r, rawData[i].color.g, rawData[i].color.b, 255)
end
-- Sort out heights
for i=1, #rawData do
for i = 1, #rawData do
if not rawData[i] then continue end
-- The x position at which to draw the text relative to the text screen entity
data[i][POSX] = math.ceil(-textSize[i][1] / 2)
drawData[i][POSX] = math.ceil(-textSize[i][1] / 2)
-- The y position at which to draw the text relative to the text screen entity
data[i][POSY] = math.ceil(-(totalHeight / 2) + currentHeight)
drawData[i][POSY] = math.ceil(-(totalHeight / 2) + currentHeight)
-- Highest line to lowest, so that everything is central
currentHeight = currentHeight + textSize[i][2]
end
-- Cache the number of lines/length
data[LEN] = #data
drawData[LEN] = #drawData
-- Add the new data to our text screen list
screenInfo[ent] = data
screenInfo[ent] = drawData
-- Calculate the render bounds
local x = maxWidth / widthBoundsDivider
@ -176,7 +176,7 @@ end)
if IsValid(LocalPlayer()) then
local screens = ents.FindByClass("sammyservers_textscreen")
for k, v in ipairs(screens) do
if screenInfo[v] == nil and v.lines != nil then
if screenInfo[v] == nil and v.lines ~= nil then
AddDrawingInfo(v, v.lines)
end
end

View File

@ -46,10 +46,9 @@ end
hook.Add("PhysgunDrop", "textScreensPreventTravelDrop", textScreenDrop)
local function textScreenCanTool(ply, trace, tool)
if IsValid(trace.Entity) and trace.Entity:GetClass() == "sammyservers_textscreen" then
if !(tool == "textscreen" or tool == "remover") then
return false
end
-- only allow textscreen and remover tool
if IsValid(trace.Entity) and trace.Entity:GetClass() == "sammyservers_textscreen" and tool ~= "textscreen" and tool ~= "remover" then
return false
end
end
hook.Add("CanTool", "textScreensPreventTools", textScreenCanTool)
@ -68,7 +67,7 @@ function ENT:SetLine(line, text, color, size, font)
size = math.Clamp(size, 1, 100)
font = textscreenFonts[font] != nil and font or 1
font = textscreenFonts[font] ~= nil and font or 1
self.lines = self.lines or {}
self.lines[tonumber(line)] = {

View File

@ -66,16 +66,16 @@ function TOOL:LeftClick(tr)
for i = 1, 5 do
textScreen:SetLine(
i, -- Line
self:GetClientInfo("text"..i) or "", -- text
self:GetClientInfo("text" .. i) or "", -- text
Color( -- Color
tonumber(self:GetClientInfo("r"..i)) or 255,
tonumber(self:GetClientInfo("g"..i)) or 255,
tonumber(self:GetClientInfo("b"..i)) or 255,
tonumber(self:GetClientInfo("a"..i)) or 255
tonumber(self:GetClientInfo("r" .. i)) or 255,
tonumber(self:GetClientInfo("g" .. i)) or 255,
tonumber(self:GetClientInfo("b" .. i)) or 255,
tonumber(self:GetClientInfo("a" .. i)) or 255
),
tonumber(self:GetClientInfo("size"..i)) or 20,
tonumber(self:GetClientInfo("size" .. i)) or 20,
-- font
tonumber(self:GetClientInfo("font"..i)) or 1
tonumber(self:GetClientInfo("font" .. i)) or 1
)
end
@ -91,16 +91,16 @@ function TOOL:RightClick(tr)
for i = 1, 5 do
TraceEnt:SetLine(
i, -- Line
tostring(self:GetClientInfo("text"..i)), -- text
tostring(self:GetClientInfo("text" .. i)), -- text
Color( -- Color
tonumber(self:GetClientInfo("r"..i)) or 255,
tonumber(self:GetClientInfo("g"..i)) or 255,
tonumber(self:GetClientInfo("b"..i)) or 255,
tonumber(self:GetClientInfo("a"..i)) or 255
tonumber(self:GetClientInfo("r" .. i)) or 255,
tonumber(self:GetClientInfo("g" .. i)) or 255,
tonumber(self:GetClientInfo("b" .. i)) or 255,
tonumber(self:GetClientInfo("a" .. i)) or 255
),
tonumber(self:GetClientInfo("size"..i)) or 20,
tonumber(self:GetClientInfo("size" .. i)) or 20,
-- font
tonumber(self:GetClientInfo("font"..i)) or 1
tonumber(self:GetClientInfo("font" .. i)) or 1
)
end
@ -130,22 +130,22 @@ end
local function MakePresetControl(panel, mode, folder)
if not mode or not panel then return end
local TOOL = LocalPlayer():GetTool(mode)
if not TOOL then return end
local tool = LocalPlayer():GetTool(mode)
if not tool then return end
local ctrl = vgui.Create( "ControlPresets", panel )
ctrl:SetPreset(folder or mode)
if TOOL.ClientConVar then
if tool.ClientConVar then
local options = {}
for k, v in pairs(TOOL.ClientConVar) do
for k, v in pairs(tool.ClientConVar) do
if k ~= "id" then
k = mode.."_"..k
k = mode .. "_" .. k
options[k] = v
ctrl:AddConVar(k)
end
end
ctrl:AddOption("#Default", options)
end
panel:AddPanel( ctrl )
panel:AddPanel(ctrl)
end
function TOOL.BuildCPanel(CPanel)
@ -171,11 +171,11 @@ function TOOL.BuildCPanel(CPanel)
end
local changefont
local fontnum = textscreenFonts[GetConVar("textscreen_font1"):GetInt()] != nil and GetConVar("textscreen_font1"):GetInt() or 1
local fontnum = textscreenFonts[GetConVar("textscreen_font1"):GetInt()] ~= nil and GetConVar("textscreen_font1"):GetInt() or 1
local fontsize = {}
cvars.AddChangeCallback("textscreen_font1", function(convar_name, value_old, value_new)
fontnum = textscreenFonts[tonumber(value_new)] != nil and tonumber(value_new) or 1
fontnum = textscreenFonts[tonumber(value_new)] ~= nil and tonumber(value_new) or 1
local font = TrimFontName(fontnum)
changefont:SetText("Change font (" .. font .. ")")
end)
@ -183,7 +183,7 @@ function TOOL.BuildCPanel(CPanel)
local function ResetFont(lines, text)
if #lines >= 5 then
fontnum = 1
for i=1, 5 do
for i = 1, 5 do
RunConsoleCommand("textscreen_font" .. i, 1)
end
end
@ -307,7 +307,7 @@ function TOOL.BuildCPanel(CPanel)
local font = TrimFontName(i)
menu:AddOption(font, function()
fontnum = i
for o=1, 5 do
for o = 1, 5 do
RunConsoleCommand("textscreen_font" .. o, i)
labels[o]:SetFont(textscreenFonts[fontnum] .. fontsize[o])
end