Module:ScriptItem: Difference between revisions

no edit summary
No edit summary
No edit summary
Line 90: Line 90:
function p.showPage(frame, parts)
function p.showPage(frame, parts)
local args = p.getArgs(frame)
local args = p.getArgs(frame)
if args.type ~= 'event' then
table.insert(parts, "Types")
end
table.insert(parts, "Symbols")
local lines = p.getPageTopLines(frame)
local lines = p.getPageTopLines(frame)
table.insert(parts, 1, "Usage")
for i,part in ipairs({"Notes", "Examples", "Compatibility", "Related"}) do
for i,part in ipairs({"Notes", "Examples", "Compatibility", "Related"}) do
table.insert(parts, part)
table.insert(parts, part)
Line 616: Line 619:
end
end


function p.usage(frame)
function p.types(frame)
local args = p.getArgs(frame)
return p.getTypesText(frame, args.class)
end
 
function p.symbols(frame)
local args = p.getArgs(frame)
local args = p.getArgs(frame)
return p.getDerivedClassesText(frame, args.class)
return p.getSymbolsText(frame, args.class)
end
end


Line 864: Line 872:
end
end


function p.getDerivedClassesText(frame, baseType)
function p.getTypesText(frame, baseType)
local args = p.getArgs(frame)
local args = p.getArgs(frame)
Line 882: Line 890:
'Element', 'Transformable', 'Blip', 'Pickup', 'Entity', 'Physical','Vehicle'
'Element', 'Transformable', 'Blip', 'Pickup', 'Entity', 'Physical','Vehicle'
}
}
local out = {}
local line1 = "The <span style=\"font-family: 'Source Code Pro', monospace;\">"..p.getDisplayedNameColoured(frame).."</span> "..args.type.." is used "
if args.type == 'variable' or args.type == 'function' then
line1 = line1.."globally."
elseif args.type == 'property' or args.type == 'method' then
line1 = line1.."via OOP, on types:"
elseif args.type == 'event' then
line1 = line1.."via the observer pattern. [https://wiki.gtaconnected.com/HowTo/Events Read more.]"
end
table.insert(out, line1)
local getTypeSide = function(type)
local getTypeSide = function(type)
Line 911: Line 907:
end
end
if args.type ~= 'event' then
if baseType then
if baseType then
local baseTypeLower = baseType:lower()
local baseTypeLower = baseType:lower()
local allTypes
local allTypes
if derivedTypes[baseTypeLower] then
if derivedTypes[baseTypeLower] then
allTypes = p.copyTable(derivedTypes[baseTypeLower])
allTypes = p.copyTable(derivedTypes[baseTypeLower])
table.insert(allTypes, 1, baseType)
table.insert(allTypes, 1, baseType)
else
else
allTypes = { baseType }
allTypes = { baseType }
end
end
local types = {}
local types = {}
for i,type in ipairs(allTypes) do
for i,type in ipairs(allTypes) do
types[i] = type
types[i] = type
end
end
p.sortTable(types)
p.sortTable(types)
for i,type in ipairs(types) do
for i,type in ipairs(types) do
types[i] = p.loadTemplate(frame, 'Side', {[getTypeSide(type)]='1'}).." ".."<span style=\"font-family: 'Source Code Pro', monospace;\">"..type.."</span>"
types[i] = p.loadTemplate(frame, 'Side', {[getTypeSide(type)]='1'}).." ".."<span style=\"font-family: 'Source Code Pro', monospace;\">"..type.."</span>"
end
end
--table.insert(out, "<div style='margin-top: 20px;'></div>")
table.insert(out, "<div style='margin-top: 20px;'></div>")
table.insert(out, "\n"..table.concat(types, "<br>"))
table.insert(out, "\n"..table.concat(types, "<br>"))
end
return table.concat(out, "")
end
 
function p.getSymbolsText(frame, baseType)
local args = p.getArgs(frame)
local out = {}
local rows = {}
if args.type == 'function' or args.type == 'variable' then
local parts = p.split(p.getDisplayedName(frame), ".")
for i=1,(#parts)-1,1 do
rows[i] = {}
rows[i][1] = "<span style=\"font-family: 'Source Code Pro', monospace; color: "..p.getNameRgb()..";\">"..parts[i].."</span>"
rows[i][2] = 'Namespace'
rows[i][3] = i == 1 and 'Global' or 'Namespace: '..parts[i-1]
rows[i][4] = i == 1 and parts[i]..' is a namespace, which exists in the global namespace.' or parts[i]..' is a namespace, which exists in the '..parts[i-1]..' namespace.'
end
end
rows[#parts] = {}
rows[#parts][1] = "<span style=\"font-family: 'Source Code Pro', monospace; color: "..p.getNameRgb()..";\">"..parts[#parts].."</span>"
rows[#parts][2] = p.properCase(args.type)
rows[#parts][3] = #parts == 1 and 'Global' or 'Namespace: '..parts[#parts-1]
rows[#parts][4] = #parts == 1 and parts[#parts]..' is a '..p.properCase(args.type)..', which exists in the global namespace.' or parts[i]..' is a '..p.properCase(args.type)..', which exists in the '..parts[#parts-1]..' namespace.'
elseif args.type == 'method' or args.type == 'property' then
rows[1] = {}
rows[1][1] = "<span style=\"font-family: 'Source Code Pro', monospace; color: "..p.getNameRgb()..";\">"..parts[1].."</span>"
rows[1][2] = 'Object'
rows[1][3] = 'n/a'
rows[1][4] = "<span style=\"font-family: 'Source Code Pro', monospace; color: "..p.getNameRgb()..";\">"..parts[1].."</span>"..' is an object.'
local parts = p.split(p.getDisplayedName(frame), ".")
rows[2] = {}
if #parts >= 2 then
rows[2][1] = "<span style=\"font-family: 'Source Code Pro', monospace; color: "..p.getNameRgb()..";\">"..parts[2].."</span>"
local rows = {}
rows[2][2] = p.properCase(args.type)
if args.type == 'variable' or args.type == 'function' then
rows[2][3] = #parts == 1 and 'Global' or 'Namespace: '..parts[#parts-1]
for i=1,(#parts)-1,1 do
rows[2][4] = "<span style=\"font-family: 'Source Code Pro', monospace; color: "..p.getNameRgb()..";\">"..parts[2].."</span>"..' is a '..p.properCase(args.type)..', which is used on objects of type '..parts[1]
rows[i] = { "<span style=\"font-family: 'Source Code Pro', monospace; color: "..p.getNameRgb()..";\">"..parts[i].."</span>", "Namespace"..(i == 1 and " (Global)" or " (Nested)") }
elseif args.type == 'event' then
end
rows[1] = {}
rows[#parts] = { "<span style=\"font-family: 'Source Code Pro', monospace; color: "..p.getNameRgb()..";\">"..parts[#parts].."</span>", p.properCase(args.type) }
rows[1][1] = "<span style=\"font-family: 'Source Code Pro', monospace; color: "..p.getNameRgb()..";\">"..p.getDisplayedName(frame).."</span>"
elseif args.type == 'property' or args.type == 'method' then
rows[1][2] = 'String'
local text1
rows[1][3] = 'n/a'
if args.type == 'property' then
rows[1][4] = 'Events are referenced by name. Event names use data type String.'
text1 = 'Properties use the dot "." operator in JS, Lua, and Squirrel.'
end
else
text1 = 'Methods use the dot "." operator in JS and Squirrel, or the colon operator ":" in Lua.'
--table.insert(out, "<div style='margin-top: 20px;'></div>")
end
table.insert(out, "\n"..p.table(false, rows, { 120, 120, 400 }, false))
rows[1] = { "<span style=\"font-family: 'Source Code Pro', monospace; color: "..p.getTypeRgb()..";\">"..parts[1].."</span>", "Object", "Userdata type in Lua and Squirrel, or Object type in JS." }
rows[2] = { "<span style=\"font-family: 'Source Code Pro', monospace; color: "..p.getNameRgb()..";\">"..parts[2].."</span>", p.properCase(args.type), text1 }
if args.type ~= 'event' then
end
local languages = { 'JS', 'Lua', 'Squirrel' }
if #rows > 0 then
local languageSymbols = {
table.insert(out, "<div style='margin-top: 20px;'></div>")
['JS'] = { ['function'] = 'dot', ['variable'] = 'dot', ['method'] = 'dot', ['property'] = 'dot' },
table.insert(out, "\n"..p.table(false, rows, { 120, 120, 400 }, false))
['Lua'] = { ['function'] = 'dot', ['variable'] = 'dot', ['method'] = 'colon', ['property'] = 'dot' },
['Squirrel'] = { ['function'] = 'dot', ['variable'] = 'dot', ['method'] = 'dot', ['property'] = 'dot' }
}
for i,language in ipairs(languages) do
local line
if args.type == 'function' then
line = language..' uses the '..languageSymbols[language][args.type]..' symbol to call a function.'
elseif args.type == 'variable' then
line = language..' uses the '..languageSymbols[language][args.type]..' symbol to get or set a variable.'
elseif args.type == 'method' then
line = language..' uses the '..languageSymbols[language][args.type]..' symbol to call a method.'
elseif args.type == 'property' then
line = language..' uses the '..languageSymbols[language][args.type]..' symbol to get or set a property.'
end
end
table.insert(out, "\n"..line)
end
end
end
end
6,833

edits