Module:ScriptItem: Difference between revisions

no edit summary
No edit summary
No edit summary
 
(41 intermediate revisions by 3 users not shown)
Line 37: Line 37:
p.categoryWords = {
p.categoryWords = {
-- Category Names. (String(s) to look for in an item name, case-INsensitive.)
-- Category Names. (String(s) to look for in an item name, case-INsensitive.)
'Blip', 'Building', 'Camera', 'Chatbox', 'Civilian', 'Cheat', 'Client', 'Command', 'Cursor', 'Debug', 'Dodo',
'Blip', 'Building', 'Camera', 'Chatbox', 'Cheat', 'Client', 'Command', 'Cursor', 'Debug', 'Dodo',
'Element', 'Entity', 'Event', 'File', 'Font', 'Garage', 'HTTP', 'HUD', 'Key', 'Mission', 'Mouse', 'Network', 'Object',
'Element', 'Entity', 'Event', 'File', 'Font', 'Garage', 'HTTP', 'HUD', 'Key', 'Mission', 'Mouse', 'NetFlags', 'Network', 'Object',
'Pause', 'Ped', 'Pickup', 'Player', 'Process', 'Render', 'Resource', 'Screen', 'Socket', 'Sphere', 'Time', 'Transformable', 'Vehicle', 'Weather', 'World'
'Pause', 'Ped', 'Pickup', 'Player', 'Process', 'Render', 'Resource', 'Screen', 'Socket', 'Sphere', 'Time', 'Vehicle', 'Weather', 'World'
}
}


Line 63: Line 63:
-- item page types
-- item page types
function p.showVariablePage(frame)
function p.showVariablePage(frame)
local parts = { "Value", "Settable" }
return p.showPage(frame, { "Value" })
return p.showPage(frame, parts)
end
end


function p.showFunctionPage(frame)
function p.showFunctionPage(frame)
local parts = { "Parameters", "Return", "Callbacks" }
return p.showPage(frame, { "Parameters", "Return", "Callbacks" })
return p.showPage(frame, parts)
end
end


function p.showPropertyPage(frame)
function p.showPropertyPage(frame)
local parts = { "Value", "Settable" }
return p.showPage(frame, { "Value" })
return p.showPage(frame, parts)
end
end


function p.showMethodPage(frame)
function p.showMethodPage(frame)
local parts = { "Parameters", "Return", "Callbacks" }
return p.showPage(frame, { "Parameters", "Return", "Callbacks" })
return p.showPage(frame, parts)
end
end


function p.showEventPage(frame)
function p.showEventPage(frame)
local parts = { "Parameters", "Cancellable" }
return p.showPage(frame, { "Parameters", "Attributes" })
return p.showPage(frame, parts)
end
end


Line 90: Line 85:
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 111: Line 109:
local lines = {}
local lines = {}
table.insert(lines, frame:preprocess("{{DISPLAYTITLE:"..p.getDisplayedName(frame).."}}"))
table.insert(lines, frame:preprocess("{{DISPLAYTITLE:"..p.getDisplayedName(frame).."}}"))
    -- Added for discord embed styling
--table.insert(lines, "<meta content='"..p.getDisplayedName(frame).."' property='og:title' />"))
--table.insert(lines, "<meta content='"..p.description(frame).."' property='og:description' />"))
--table.insert(lines, "<meta content='#04C765' data-react-helmet='true' name='theme-color' />"))
table.insert(lines, "__NOTOC__"..p.getPageTopBoxes(frame).."\n")
table.insert(lines, "__NOTOC__"..p.getPageTopBoxes(frame).."\n")
table.insert(lines, "<div style='margin-top: 20px;'>Available since "..p.since(frame).."</div>\n")
table.insert(lines, "<div style='margin-top: 20px;'>Available since "..p.since(frame).."</div>\n")
Line 124: Line 128:
if args.type == 'variable' or args.type == 'property' then
if args.type == 'variable' or args.type == 'property' then
table.insert(topBoxes, "settable")
table.insert(topBoxes, "settable")
elseif args.type == 'event' then
table.insert(topBoxes, "cancellable")
end
end
Line 276: Line 282:
local gamesText = p.getGames(args.games)
local gamesText = p.getGames(args.games)
if gamesText == "All Games" then
if gamesText == "All Games" then
return p.loadTemplate(frame, 'GreenInformationBox', {gamesText,id='games'});
return p.loadTemplate(frame, 'GreenInformationBox', {table.concat({
p.loadTemplate(frame, 'icon-iii'),
p.loadTemplate(frame, 'icon-vc'),
p.loadTemplate(frame, 'icon-sa'),
p.loadTemplate(frame, 'icon-iv')
}, ' '), id='games'})
else
else
return p.loadTemplate(frame, 'RedInformationBox', {gamesText..' Only',id='games'});
local games = { 'iii', 'vc', 'sa', 'iv' }
local out = {}
for i,game in ipairs(games) do
if gamesText:lower():find(game) then
table.insert(out, p.loadTemplate(frame, 'icon-'..game, {}))
end
end
return p.loadTemplate(frame, 'RedInformationBox', {table.concat(out, ' '), id='games'})
end
end
end
end
Line 284: Line 302:
function p.onlineBox(frame)
function p.onlineBox(frame)
local args = p.getArgs(frame)
local args = p.getArgs(frame)
if args.sp == 'true' then
if args.sp == 'true' or args.online == 'false' then
return p.loadTemplate(frame, 'RedInformationBox', {'Offline Only',id='online'});
return p.loadTemplate(frame, 'RedInformationBox', {'Offline Only',id='online'});
elseif args.sp == 'false' or args.offline == 'false' then
return p.loadTemplate(frame, 'RedInformationBox', {'Online Only',id='online'});
else
else
return p.loadTemplate(frame, 'GreenInformationBox', {'Online and Offline',id='online'});
return p.loadTemplate(frame, 'GreenInformationBox', {'Online and Offline',id='online'});
Line 297: Line 317:
else
else
return p.loadTemplate(frame, 'GreenInformationBox', {'Read and Set',id='settable'});
return p.loadTemplate(frame, 'GreenInformationBox', {'Read and Set',id='settable'});
end
end
function p.cancellableBox(frame)
local args = p.getArgs(frame)
if p.isCancellable(frame)then
return p.loadTemplate(frame, 'GreenInformationBox', {'Cancellable',id='cancellable'});
else
return p.loadTemplate(frame, 'RedInformationBox', {'Not Cancellable',id='cancellable'});
end
end
end
end
Line 342: Line 371:
local entries = p.getIndexedArgs(frame, 'description')
local entries = p.getIndexedArgs(frame, 'description')
local startTextFirstLine = "The <span style=\"font-family: 'Source Code Pro', monospace;\">"..p.getDisplayedNameColoured(frame).."</span> "..args.type.." is "..(args.type == "event" and "invoked when" or "used to").." "
local startTextFirstLine = "The <span style=\"font-family: 'Source Code Pro', monospace;\">"..p.getDisplayedNameColoured(frame).."</span> [[HowTo/Functions|"..args.type.."]] is "..(args.type == "event" and "invoked when" or "used to").." "
for i,entry in ipairs(entries) do
for i,entry in ipairs(entries) do
Line 377: Line 406:
if isEvent then
if isEvent then
rows[i] = { i..") ", p.formatType(tokens[1], frame), p.formatName(tokens[2], frame), description }
rows[i] = { (i + 1)..") ", p.formatType(tokens[1], frame), p.formatName(tokens[2], frame), description }
else
else
rows[i] = { i..") ", p.formatType(tokens[1], frame), p.formatName(tokens[2], frame), (isOptional and ("Optional, defaults to "..defaultValue..". ") or "")..description }
rows[i] = { i..") ", p.formatType(tokens[1], frame), p.formatName(tokens[2], frame), (isOptional and ("Optional, defaults to "..defaultValue..". ") or "")..description }
Line 411: Line 440:
entries = p.getIndexedArgs(frame, 'return')
entries = p.getIndexedArgs(frame, 'return')
if #entries == 0 then
if #entries == 0 then
text = text..p.documentationMissing(frame, "Success returns").."<br><br>"
text = text..p.documentationMissing(frame, "Returns").."<br><br>"
else
else
for i,arg in ipairs(entries) do
for i,arg in ipairs(entries) do
Line 422: Line 451:
if type:lower() == "void" then
if type:lower() == "void" then
isVoidReturn = true
isVoidReturn = true
description = "This "..args.type.." doesn't return any values on success."
description = "This "..args.type.." doesn't return a value."
elseif tokens[2] then
elseif tokens[2] then
description = p.formatDescription(table.concat(tokens, ' ', 2))
description = p.formatDescription(table.concat(tokens, ' ', 2))
else
else
description = p.documentationMissing(frame, "Description for success return value")
description = p.documentationMissing(frame, "Description for return value")
end
end
Line 547: Line 576:
end
end


function p.cancellable(frame)
function p.attributes(frame)
local args = p.getArgs(frame)
local args = p.getArgs(frame)
local headers = nil--{ "Type", "Description" }
local rows = {}
if p.isCancellable(frame) then
if p.isCancellable(frame) then
return "This "..args.type.." can be cancelled using [[event.preventDefault|event.preventDefault]]."
rows[1] = { 'cancellable', 'This '..args.type..' can be cancelled, by using [[event.preventDefault|event.preventDefault]].' }
else
else
return "This "..args.type.." can't be cancelled."
rows[1] = { p.formatType('const', frame), 'This '..args.type..' cannot be cancelled.' }
end
end
local widths = { 120, 400 }
return p.table(headers, rows, widths, 'wikitable-returns wikitable')
end
end


Line 569: Line 601:
local headers = nil--{ "Type", "Description" }
local headers = nil--{ "Type", "Description" }
local rows = { { p.formatType(tokens[1], frame), description } }
local rows = {}
rows[1] = { p.formatType(tokens[1], frame), description }
if args.readonly == 'true' then
rows[2] = { p.formatType('readonly', frame), 'This '..args.type..' cannot be changed.' }
else
rows[2] = { 'read/set', 'This '..args.type..' can be changed, as well as read.' }
end
local widths = { 120, 400 }
local widths = { 120, 400 }
return p.table(headers, rows, widths, 'wikitable-returns wikitable')
return p.table(headers, rows, widths, 'wikitable-returns wikitable')
Line 584: Line 622:
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 768: Line 811:
local args = p.getArgs(frame)
local args = p.getArgs(frame)
if p.isOOP(frame) then
if p.isOOP(frame) then
return args.class:lower().."."..args.name
return p.lowerFirstCharCase(args.class).."."..args.name
else
else
return args.name
return args.name
Line 787: Line 830:
local args = p.getArgs(frame)
local args = p.getArgs(frame)
if p.isOOP(frame) then
if p.isOOP(frame) then
return "<span style='color:"..typeRgb..";'>"..args.class:lower().."</span>.<span style='color:"..nameRgb.."';>"..args.name.."</span>"
return "<span style='color:"..typeRgb..";'>"..p.lowerFirstCharCase(args.class).."</span>.<span style='color:"..nameRgb.."';>"..args.name.."</span>"
else
else
return "<span style='color:"..nameRgb.."';>"..args.name.."</span>"
return "<span style='color:"..nameRgb.."';>"..args.name.."</span>"
Line 832: Line 875:
end
end


function p.getDerivedClassesText(frame, baseType)
function p.getTypesText(frame, baseType)
local args = p.getArgs(frame)
local args = p.getArgs(frame)
local derivedTypes = {
local derivedTypes = {
ped     = {'Civilian', 'Player'},
ped     = {'Player'},
physical = {'Object', 'Ped', 'Vehicle', 'Civilian', 'Player'},
physical = {'Object', 'Ped', 'Vehicle', 'Player'},
entity = {'Building', 'Physical', 'Object', 'Ped', 'Vehicle', 'Civilian', 'Player'},
entity = {'Building', 'Physical', 'Object', 'Ped', 'Vehicle', 'Player'},
transformable = {'Blip', 'Entity', 'Marker', 'Building', 'Physical', 'Object', 'Ped', 'Vehicle', 'Civilian', 'Player'},
element = {'Blip', 'Entity', 'Marker', 'Building', 'Physical', 'Object', 'Ped', 'Vehicle', 'Player'},
element = {'Transformable', 'Blip', 'Entity', 'Marker', 'Building', 'Physical', 'Object', 'Ped', 'Vehicle', 'Civilian', 'Player'}
vehicle = {'Train'},
event = {'CancellableEvent', 'KeyEvent'},
surface = {'RenderTarget', 'Texture'}
}
}
local serverTypes = {
local serverTypes = {}
'World', 'Train'
}
local sharedTypes = {
local sharedTypes = {
'Client', 'Effect', 'Event', 'Font', 'Timer', 'ReflectedFunction', 'Resource', 'Stream', 'Vec2', 'Vec3', 'Matrix4x4',
'Building', 'Client', 'Effect', 'Event', 'Timer', 'ReflectedFunction', 'Resource', 'Stream', 'Vec2', 'Vec3', 'Matrix4x4',
'Element', 'Transformable', 'Blip', 'Pickup', 'Entity', 'Physical','Vehicle'
'Element', 'Blip', 'Pickup', 'Entity', 'Physical','Vehicle', 'Train', 'XmlDocument', 'XmlElement',
'CancellableEvent', 'KeyEvent', 'Marker', 'Object', 'Ped', 'Player'
}
}
local out = {}
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 879: Line 913:
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[1]..' is a '..p.properCase(args.type)..', which exists in the global namespace.' or parts[#parts]..' is a '..p.properCase(args.type)..', which exists in the '..parts[#parts-1]..' namespace.'
elseif args.type == 'method' or args.type == 'property' then
local parts = p.split(p.getDisplayedName(frame), ".")
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
local headers = { 'Symbol Name', 'Symbol Type', 'Container', 'Description' }
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." }
table.insert(out, "\n"..p.table(headers, rows, { 120, 120, 400 }, false))
rows[2] = { "<span style=\"font-family: 'Source Code Pro', monospace; color: "..p.getNameRgb()..";\">"..parts[2].."</span>", p.properCase(args.type), text1 }
end
if args.type ~= 'event' then
if #rows > 0 then
local languages = { 'JS', 'Lua', 'Squirrel' }
table.insert(out, "<div style='margin-top: 20px;'></div>")
local languageSymbols = {
table.insert(out, "\n"..p.table(false, rows, { 120, 120, 400 }, false))
['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, "<br>"..line)
end
end
end
end
Line 943: Line 1,022:


function p.formatSource(type, frame)
function p.formatSource(type, frame)
return frame:preprocess('<source>'..type..'</source>')
return frame:preprocess('<syntaxhighlight>'..type..'</syntaxhighlight>')
end
end


Line 1,077: Line 1,156:
function p.properCase(text)
function p.properCase(text)
return text:sub(1,1):upper()..text:sub(2):lower()
return text:sub(1,1):upper()..text:sub(2):lower()
end
function p.lowerFirstCharCase(text)
return text:sub(1,1):lower()..text:sub(2)
end
end


2,591

edits