Skip to content

Commit

Permalink
_
Browse files Browse the repository at this point in the history
  • Loading branch information
thisdp committed Jan 17, 2021
1 parent 6a89241 commit 00cf394
Show file tree
Hide file tree
Showing 4 changed files with 215 additions and 24 deletions.
15 changes: 4 additions & 11 deletions Core/3dinterface.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,11 @@ local type = type

local function LookRotation(x,y,z,rot)
local rx = deg(acos(((x^2+z^2)/(x^2+y^2+z^2))^0.5))
if (y > 0) then
rx = 360-rx
end
rx = y > 0 and 360-rx or rx
local ry = deg(atan2(x, z))
if (ry < 0) then
ry = ry+ 180
end
if (x < 0) then
ry = ry+ 180
end
rz = rot
return rz,ry,rz
ry = ry < 0 and ry+ 180 or ry
ry = x < 0 and ry+ 180 or ry
return rx,ry,rot
end

function dgsSetFilterShaderData(shader,x,y,z,fx,fy,fz,rotation,w,h,tex,r,g,b,a)
Expand Down
221 changes: 210 additions & 11 deletions G2DManager_s.lua
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ G2DHelp = {
{"-l"," ","List all selected resources"},
{"-e"," ","Start to convert"},
{"-q"," ","Stop converting process"},
{"-crawl","autocomplete type","Crawl and Generate DGS autocomplete"},
}

addCommandHandler("g2d",function(player,command,...)
Expand Down Expand Up @@ -80,7 +81,7 @@ addCommandHandler("g2d",function(player,command,...)
outputDebugString("[DGS-G2D] Selections cleared!")
elseif args[1] == "-e" or args[1] == "-exe" then
if not G2D.Process then
print("[DGS-G2D] Scanning files...")
print("[DGS-G2D]Scanning files...")
local process = {}
for resN,res in pairs(G2D.select) do
local xml = xmlLoadFile(":"..resN.."/meta.xml")
Expand All @@ -91,23 +92,35 @@ addCommandHandler("g2d",function(player,command,...)
end
end
end
print("[DGS-G2D] "..#process.." files to be converted")
print("[DGS-G2D]"..#process.." files to be converted")
G2D.Process = true
G2D.Running = {}
G2D.Files = process
G2DStart()
else
print("[DGS-G2D] G2D is running!")
print("[DGS-G2D]G2D is running!")
end
elseif args[1] == "-q" then
if G2D.Process then
print("[DGS-G2D] G2D process terminated!")
print("[DGS-G2D]G2D process terminated!")
G2D.Process = false
else
print("[DGS-G2D] G2D is not running!")
print("[DGS-G2D]G2D is not running!")
end
elseif args[1] == "-crawl" then
if args[2] and args[2] ~= "" then
if args[2] == "npp" or args[2] == "n++" then
CrawlWikiFromMTA("npp")
elseif args[2] == "vscode" or arg[2] == "vsc" then
CrawlWikiFromMTA("vsc")
else
print("[DGS]Current type is not supported!")
end
else
print("[DGS]Please select target type: g2d -g <npp/vsc>")
end
else
outputDebugString("[DGS-G2D] Command help")
outputDebugString("[DGS-G2D]Command help")
outputDebugString("Option Arguments Comment")
for i=1,#G2DHelp do
local items = G2DHelp[i]
Expand All @@ -118,6 +131,8 @@ addCommandHandler("g2d",function(player,command,...)
end
end)

----------------

local keyword = {
["and"] = 1,
["break"] = 2,
Expand Down Expand Up @@ -839,7 +854,7 @@ converEventTable = {


function showProgress(progress)
print("[G2D] Progress "..string.format("%.2f",progress).."%")
print("[G2D]Progress "..string.format("%.2f",progress).."%")
end

G2DRunningData = {
Expand All @@ -851,7 +866,7 @@ function G2DStart()
local k,filename = next(G2D.Files,(G2D.Running or {})[2])
if not filename then
G2D.Process = false
return print("[G2D] Process Done")
return print("[G2D]Process Done")
end
local cor = coroutine.create(processFile)
G2D.Running = {cor,k}
Expand All @@ -874,7 +889,7 @@ function processExpired(isEnd)
end

function processFile(filename)
print("[G2D] Start to process file '"..filename.."'")
print("[G2D]Start to process file '"..filename.."'")
local file = fileOpen(filename)
local str = fileRead(file,fileGetSize(file))
local utf8BOM = false
Expand All @@ -888,7 +903,7 @@ function processFile(filename)
DGSLLex(ls)
local az = AnalyzerState(ls.result)
local convTabCnt = #convertFunctionTable
print("[G2D] Replacing Functions")
print("[G2D]Replacing Functions")
for i=1,convTabCnt do
az:set(convertFunctionTable[i])
az:executeProcess()
Expand All @@ -899,7 +914,7 @@ function processFile(filename)
end
end
local convTabCnt = #converEventTable
print("[G2D] Replacing Events")
print("[G2D]Replacing Events")
for i=1,convTabCnt do
az:set(converEventTable[i],true)
az:executeProcess()
Expand All @@ -913,3 +928,187 @@ function processFile(filename)
az:generateFile(filename,utf8BOM)
return processExpired(true)
end


-------------------------------------

local mainWikiURL = "https://wiki.multitheftauto.com"
local threadPoolSize = 2
function CrawlWikiFromMTA(t)
local targetURL = mainWikiURL.."/wiki/Template:DGSFUNCTIONS"
print("[DGS]Crawling wiki...")
fetchRemote(targetURL,{},function(data,info,t)
if info.success then
local startPos = 0
print("[DGS]Wiki data is ready, Reading...")
local fncList = {type=t}
while(true) do
liStart_1,liStart_2 = string.find(data,"%<li%>",startPos)
liEnd_1,liEnd_2 = string.find(data,"%<%/li%>",startPos)
if not liStart_1 or not liEnd_1 then break end
local str = string.sub(data,liStart_2+1,liEnd_1-1)
local xmlNode = xmlLoadString(str)
local fncName = xmlNodeGetValue(xmlNode)
local nTable = {
href=xmlNodeGetAttribute(xmlNode,"href"),
title=xmlNodeGetAttribute(xmlNode,"title"),
isEmpty = xmlNodeGetAttribute(xmlNode,"class") == "new",
name = fncName,
}
table.insert(fncList,nTable)
startPos = liEnd_2
end
print("[DGS]Function list("..#fncList..") is ready, Crawling...")
local fRProg = {thread=0,index=0,valid=0,progress=0,total=#fncList}
local fncData = {}
setTimer(function()
if fRProg.progress < fRProg.total then
for i=1,threadPoolSize-fRProg.thread do
fRProg.index = fRProg.index+1
if fRProg.index <= fRProg.total then
item = fncList[fRProg.index]
if item then
if not item.isEmpty then
local poolID
for tableIndex=1,threadPoolSize do
if not fRProg[tableIndex] then
poolID = tableIndex
break
end
end
fRProg.thread = fRProg.thread+1
fRProg[poolID] = fetchRemote(mainWikiURL.."/index.php?title="..item.title.."&action=edit",{queueName=poolID},function(data,info,poolID,index)
fRProg.progress = fRProg.progress+1
fRProg.thread = fRProg.thread-1
fRProg[poolID] = false
if info.success then
print("[DGS]Recorded ("..fRProg.progress.."/"..fRProg.total..")["..fncList[index].name.."]")
local startPos = data:find("%<textarea")
local _,endPos = data:find("%<%/textarea>",startPos)
local line = data:sub(startPos,endPos)
local xmlNode = xmlLoadString(line)
local pageSource = xmlNodeGetValue(xmlNode)
local _,rangeStart = pageSource:find("==Syntax==")
local _,syntaxStart = pageSource:find("%<syntaxhighlight lang%=\"lua\"%>",rangeStart+1)
local syntaxEnd = pageSource:find("%<%/syntaxhighlight%>",syntaxStart+1)
local targetSyntax = pageSource:sub(syntaxStart+1,syntaxEnd-1)
local targetSyntax = targetSyntax:gsub("\r",""):gsub("\n","")
fncList[index].syntax = targetSyntax
else
print("[DGS]Failed to get remote wiki data ("..info.statusCode ..")")
end
end,{poolID,fRProg.index})
fRProg.valid = fRProg.valid+1
else
fRProg.progress = fRProg.progress+1
end
end
end
end
else
print("[DGS]Crawling stage complete [Total:"..fRProg.total.."/Valid:"..fRProg.valid.."]")
killTimer(sourceTimer)
fncList.valid = fRProg.valid
AnalyzeFunction(fncList)
end
end,50,0)
end
end,{t})
end

function AnalyzeFunction(tab)
print("[DGS]Start to analyze syntax")
local nTable = {}
local validCount = 0
for i=1,#tab do
local item = tab[i]
if item.syntax then
validCount = validCount+1
print("[DGS]Analyzing syntax ("..validCount.."/"..tab.valid..")["..item.name.."]")
local startPos,endPos = string.find(item.syntax,item.name)
local rets = split(item.syntax:sub(1,startPos-1)," ")
local argStr = item.syntax:sub(endPos+1):gsub("%(",""):gsub("%)","")
local argSplited = split(argStr,"%[")
local reqArgStr = argSplited[1] or ""
local optArgStr = (argSplited[2] or ""):gsub("%]","")

local reqArgs = split(reqArgStr,",")
local optArgs = split(optArgStr,",")
local emptyArgCheck = {req={},opt={}}
for _i=1,#reqArgs do
reqArgs[_i] = reqArgs[_i]:match("^[%s]*(.-)[%s]*$") or reqArgs[_i]
if reqArgs[_i] == "" then
table.insert(emptyArgCheck.req,_i)
end
end
for _i=1,#optArgs do
optArgs[_i] = optArgs[_i]:match("^[%s]*(.-)[%s]*$") or optArgs[_i]
if optArgs[_i] == "" then
table.insert(emptyArgCheck.opt,_i)
end
end
for _i=1,#rets do
rets[_i] = rets[_i]:gsub(",",""):gsub(" ","")
end

for i=1,#emptyArgCheck.req do
table.remove(reqArgs,emptyArgCheck.req[i])
end
for i=1,#emptyArgCheck.opt do
table.remove(optArgs,emptyArgCheck.opt[i])
end
local resultTable = {returns=rets,fncName=item.name,requiredArguments=reqArgs,optionalArguments=optArgs}
table.insert(nTable,resultTable)
end
end
print("[DGS]Syntax analyzing stage done")
if tab.type == "npp" then
GenerateNPPAutoComplete(nTable)
elseif tab.type == "vsc" then
GenerateVSCodeAutoComplete(nTable)
end
end

function GenerateNPPAutoComplete(tab)
if fileExists("nppAC4DGS.xml") then fileDelete("nppAC4DGS.xml") end
print("[DGS]Generating NPP autocomplete file...")
local xml = xmlCreateFile("nppAC4DGS.xml","NotepadPlus")
local envNode = xmlCreateChild(xml,"Environment")
local acNode = xmlCreateChild(xml,"AutoComplete")
xmlNodeSetAttribute(envNode,"ignoreCase","no")
xmlNodeSetAttribute(envNode,"startFunc","(")
xmlNodeSetAttribute(envNode,"stopFunc",")")
xmlNodeSetAttribute(envNode,"paramSeparator",",")
xmlNodeSetAttribute(envNode,"terminal",";")
xmlNodeSetAttribute(envNode,"additionalWordChar",".:")
xmlNodeSetAttribute(acNode,"language","lua")
for i=1,#tab do
local item = tab[i]
local kwNode = xmlCreateChild(acNode,"KeyWord")
xmlNodeSetAttribute(kwNode,"name",item.fncName)
xmlNodeSetAttribute(kwNode,"func","yes")
local olNode = xmlCreateChild(kwNode,"Overload")
xmlNodeSetAttribute(olNode,"retVal",table.concat(item.returns,", "))
for argid=1,#item.requiredArguments do
local paramNode = xmlCreateChild(olNode,"Param")
xmlNodeSetAttribute(paramNode,"name",item.requiredArguments[argid])
end
for argid=1,#item.optionalArguments do
local paramNode = xmlCreateChild(olNode,"Param")
xmlNodeSetAttribute(paramNode,"name",item.optionalArguments[argid])
end
end
xmlSaveFile(xml)
xmlUnloadFile(xml)
local f = fileOpen("nppAC4DGS.xml")
local str = "<?xml version=\"1.0\" encoding=\"Windows-1252\" ?>\r\n"..fileRead(f,fileGetSize(f))
fileSetPos(f,0)
fileWrite(f,str)
fileClose(f)
print("[DGS]NPP autocomplete file is saved as nppAC4DGS.xml -> Done")
end


function GenerateVSCodeAutoComplete(tab)

end
2 changes: 1 addition & 1 deletion meta.xml
Original file line number Diff line number Diff line change
Expand Up @@ -667,7 +667,7 @@
<export function="dgsImportOOPClass" type="client" />
<export function="dgsG2DLoadHooker" type="client" />

<min_mta_version server="1.5.4-9.11342" client="1.5.7-9.20157" />
<min_mta_version server="1.5.7-9.19626" client="1.5.7-9.20157" />
<aclrequest>
<right name="function.fetchRemote" access="true" />
<right name="general.ModifyOtherObjects" access="true" />
Expand Down
1 change: 0 additions & 1 deletion test.lua
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,6 @@ function AnimTest()
local label = dgsCreateLabel(500,500,400,20,"Testttttttttttttttttttt",false)
dgsAnimTo(label,"shadow",{100,100,tocolor(0,0,0,255)},"shadowOffset",10000)
end

function GridListSortingTest()
for x=1,10 do
local sortfnc = [[
Expand Down

0 comments on commit 00cf394

Please sign in to comment.