Module:ScriptItem: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
No edit summary |
||
Line 89: | Line 89: | ||
-- item page | -- item page | ||
function p.showPage(frame, parts) | function p.showPage(frame, parts) | ||
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. | function p.usage(frame) | ||
local args = p.getArgs(frame) | local args = p.getArgs(frame) | ||
return p. | return p.getDerivedClassesText(frame, args.class) | ||
end | end | ||
Line 872: | Line 864: | ||
end | end | ||
function p. | 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 | ||
if baseType then | |||
local baseTypeLower = baseType:lower() | |||
local allTypes | |||
if derivedTypes[baseTypeLower] then | |||
allTypes = p.copyTable(derivedTypes[baseTypeLower]) | |||
table.insert(allTypes, 1, baseType) | |||
allTypes = { | 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 parts = p.split(p.getDisplayedName(frame), ".") | local parts = p.split(p.getDisplayedName(frame), ".") | ||
for i=1,(#parts)-1,1 do | if #parts >= 2 then | ||
local rows = {} | |||
if args.type == 'variable' or args.type == 'function' then | |||
for i=1,(#parts)-1,1 do | |||
rows[i] = { "<span style=\"font-family: 'Source Code Pro', monospace; color: "..p.getNameRgb()..";\">"..parts[i].."</span>", "Namespace"..(i == 1 and " (Global)" or " (Nested)") } | |||
end | |||
rows[#parts] = { "<span style=\"font-family: 'Source Code Pro', monospace; color: "..p.getNameRgb()..";\">"..parts[#parts].."</span>", p.properCase(args.type) } | |||
elseif args.type == 'property' or args.type == 'method' then | |||
local text1 | |||
if args.type == 'property' then | |||
text1 = 'Properties use the dot "." operator in JS, Lua, and Squirrel.' | |||
else | |||
text1 = 'Methods use the dot "." operator in JS and Squirrel, or the colon operator ":" in Lua.' | |||
end | |||
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 } | |||
end | |||
if #rows > 0 then | |||
table.insert(out, "<div style='margin-top: 20px;'></div>") | |||
table.insert(out, "\n"..p.table(false, rows, { 120, 120, 400 }, false)) | |||
end | end | ||
end | end | ||
end | end |