Module:ScriptItem: Difference between revisions

Jump to navigation Jump to search
no edit summary
No edit summary
No edit summary
Line 89: Line 89:
-- item page
-- item page
function p.showPage(frame, parts)
function p.showPage(frame, parts)
if args.type ~= 'event' then
table.insert(parts, "Types")
end
table.insert(parts, "Symbols")
local args = p.getArgs(frame)
local args = p.getArgs(frame)
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 619: Line 616:
end
end


function p.types(frame)
function p.usage(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.getSymbolsText(frame, args.class)
return p.getDerivedClassesText(frame, args.class)
end
end


Line 872: Line 864:
end
end


function p.getTypesText(frame, baseType)
function p.getDerivedClassesText(frame, baseType)
local args = p.getArgs(frame)
local args = p.getArgs(frame)
Line 890: Line 882:
'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 907: Line 911:
end
end
if baseType then
if args.type ~= 'event' then
local baseTypeLower = baseType:lower()
if baseType then
local allTypes
local baseTypeLower = baseType:lower()
if derivedTypes[baseTypeLower] then
local allTypes
allTypes = p.copyTable(derivedTypes[baseTypeLower])
if derivedTypes[baseTypeLower] then
table.insert(allTypes, 1, baseType)
allTypes = p.copyTable(derivedTypes[baseTypeLower])
else
table.insert(allTypes, 1, baseType)
allTypes = { baseType }
else
allTypes = { baseType }
end
local types = {}
for i,type in ipairs(allTypes) do
types[i] = type
end
p.sortTable(types)
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>"
end
table.insert(out, "<div style='margin-top: 20px;'></div>")
table.insert(out, "\n"..table.concat(types, "<br>"))
end
end
local types = {}
for i,type in ipairs(allTypes) do
types[i] = type
end
p.sortTable(types)
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>"
end
--table.insert(out, "<div style='margin-top: 20px;'></div>")
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), ".")
local parts = p.split(p.getDisplayedName(frame), ".")
for i=1,(#parts)-1,1 do
if #parts >= 2 then
rows[i] = {}
local rows = {}
rows[i][1] = "<span style=\"font-family: 'Source Code Pro', monospace; color: "..p.getNameRgb()..";\">"..parts[i].."</span>"
if args.type == 'variable' or args.type == 'function' then
rows[i][2] = 'Namespace'
for i=1,(#parts)-1,1 do
rows[i][3] = i == 1 and 'Global' or 'Namespace: '..parts[i-1]
rows[i] = { "<span style=\"font-family: 'Source Code Pro', monospace; color: "..p.getNameRgb()..";\">"..parts[i].."</span>", "Namespace"..(i == 1 and " (Global)" or " (Nested)") }
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] = { "<span style=\"font-family: 'Source Code Pro', monospace; color: "..p.getNameRgb()..";\">"..parts[#parts].."</span>", p.properCase(args.type) }
rows[#parts] = {}
elseif args.type == 'property' or args.type == 'method' then
rows[#parts][1] = "<span style=\"font-family: 'Source Code Pro', monospace; color: "..p.getNameRgb()..";\">"..parts[#parts].."</span>"
local text1
rows[#parts][2] = p.properCase(args.type)
if args.type == 'property' then
rows[#parts][3] = #parts == 1 and 'Global' or 'Namespace: '..parts[#parts-1]
text1 = 'Properties use the dot "." operator in JS, Lua, and Squirrel.'
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.'
else
elseif args.type == 'method' or args.type == 'property' then
text1 = 'Methods use the dot "." operator in JS and Squirrel, or the colon operator ":" in Lua.'
rows[1] = {}
end
rows[1][1] = "<span style=\"font-family: 'Source Code Pro', monospace; color: "..p.getNameRgb()..";\">"..parts[1].."</span>"
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[1][2] = 'Object'
rows[2] = { "<span style=\"font-family: 'Source Code Pro', monospace; color: "..p.getNameRgb()..";\">"..parts[2].."</span>", p.properCase(args.type), text1 }
rows[1][3] = 'n/a'
end
rows[1][4] = "<span style=\"font-family: 'Source Code Pro', monospace; color: "..p.getNameRgb()..";\">"..parts[1].."</span>"..' is an object.'
if #rows > 0 then
table.insert(out, "<div style='margin-top: 20px;'></div>")
rows[2] = {}
table.insert(out, "\n"..p.table(false, rows, { 120, 120, 400 }, false))
rows[2][1] = "<span style=\"font-family: 'Source Code Pro', monospace; color: "..p.getNameRgb()..";\">"..parts[2].."</span>"
rows[2][2] = p.properCase(args.type)
rows[2][3] = #parts == 1 and 'Global' or 'Namespace: '..parts[#parts-1]
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]
elseif args.type == 'event' then
rows[1] = {}
rows[1][1] = "<span style=\"font-family: 'Source Code Pro', monospace; color: "..p.getNameRgb()..";\">"..p.getDisplayedName(frame).."</span>"
rows[1][2] = 'String'
rows[1][3] = 'n/a'
rows[1][4] = 'Events are referenced by name. Event names use data type String.'
end
--table.insert(out, "<div style='margin-top: 20px;'></div>")
table.insert(out, "\n"..p.table(false, rows, { 120, 120, 400 }, false))
if args.type ~= 'event' then
local languages = { 'JS', 'Lua', 'Squirrel' }
local languageSymbols = {
['JS'] = { ['function'] = 'dot', ['variable'] = 'dot', ['method'] = 'dot', ['property'] = 'dot' },
['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,834

edits

Navigation menu