Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic to the Top
- Bookmark
- Subscribe
- Printer Friendly Page
0
Re: Example of separation of the engine and data
Options
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
04-17-2012 06:03 AM
And if you prefer this format for the data :
fnt.fnt.used2={{--col 1
[1]={"alpha","f"},
[2]={"alpha","e"},
[3]={"mouse",3},
[6]={"gosub",2},
[7]={"goto",2},},
{--col 2
[1]={"alpha","a"},
[2]={"alpha","b"},
[3]={"alpha","c"},
[6]={"gosub",1},
[7]={"goto",1},},
}Just use :
fnt.fnt ={--another function
PRESSED=function(x) fnt[x[1]].PRESSED(x[2]) end,
RELEASED=function(x) fnt[x[1]].RELEASED(x[2]) end,
used1={{[10]={"alpha","a"},[11]={"alpha","b"},},},
used2={{--col 1
[1]={"alpha","f"},
[2]={"alpha","e"},
[3]={"mouse",3},
[6]={"gosub",2},
[7]={"goto",2},},
{--col 2
[1]={"alpha","a"},
[2]={"alpha","b"},
[3]={"alpha","c"},
[6]={"gosub",1},
[7]={"goto",1},},
},
} Attention : use "used2" (not "used1") for this test :
initialize_data("used2")
0
Re: Example of separation of the engine and data
Options
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
04-17-2012 06:28 AM
Variant :
fnt.fnt ={--another function
PRESSED=function(x) if type(x)=="table" then fnt[x[1]].PRESSED(x[2]) else fnt.alpha.PRESSED(x) end end,
RELEASED=function(x) if type(x)=="table" then fnt[x[1]].RELEASED(x[2]) else fnt.alpha.RELEASED(x) end end,
used1={{[10]={"alpha","a"},[11]={"alpha","b"},},},
used2={{--col 1
[1]="f",
[2]="e",
[3]={"mouse",3},
[6]={"gosub",2},
[7]={"goto",2},},
{--col 2
[1]="a",
[2]="b",
[3]="c",
[6]={"gosub",1},
[7]={"goto",1},},
},
}
0
Summary : data engine
Options
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
04-17-2012 05:55 PM
Summary : data engine (entire code)
function personalization()
actif="used1"
c1={} c2={}
c1[1]="e"
c1[2]="f"
c1[3]={"mouse",3} --rigth click
c1[4]="up"
c1[6]={"gosub",2} --temporaly move to col 2
c1[7]={"goto",2} --permanent move to col 2
c1[8]={"ansi",{"num0","num1","num6","num9"}} --ansi 169 -->© (todo {"ansi",169} who ? I'm lazy !)
c1[9]={"fntLib",{"actualizeTable"}} -- call actualizeTable in fntLib
c1[10]={"fntLib",{"onlyTest","Hello"}} -- call onlyTest in fntLib
c1[11]="down"
c2[1]="a"
c2[2]="b"
c2[3]="c"
c2[6]={"gosub",1} --temporaly move to col 1
c2[7]={"goto",1} --permanent move to col 1
fnt.fnt[actif]={c1,c2}
c1=nil c2=nil
end
function OnEvent(event, arg, family)
if (event == "PROFILE_ACTIVATED") then
OutputLogMessage("Test by Josick Croyal april 18 2012\n")
personalization()
initialize_data(actif)
end
if (event=="G_PRESSED" or event =="G_RELEASED" )then
data[clustera][arg][event]()
end
end
------------------------------------------------
------------------------------------------------
--by Josick Croyal april 18 2012
--Summary Data Engine
------------------------------------------------
fntLib = {
["actualizeTable"] = function ()
ClearLog()
--dofile(pathfile.."lili2.lua")
OutputLogMessage("Actualisation non active !\n")
end,
["onlyTest"] = function(x) OutputLogMessage(x.." from onlyTest\n") end,
}
fnt={
alpha= {
PRESSED=function(x) PressKey(x) end,
RELEASED=function(x) ReleaseKey(x) clustera=defaultCluster end,
},
mouse= {
PRESSED= function(x) PressMouseButton(x) ReleaseMouseButton(x) end,
RELEASED= function() end,
},
goto= {
PRESSED=function(x) defaultCluster=x end,
RELEASED=function(x) clustera=defaultCluster end,
},
gosub= {
PRESSED=function(x) clustera=x end,
RELEASED=function(x) end,
},
ansi = {
PRESSED=function(x) PressKey(0x38) PressAndReleaseKey(x[1],x[2],x[3],x[4]) ReleaseKey(0x38) end,--
RELEASED=function(x) clustera=defaultCluster end,
},
fntLib ={
PRESSED=function(x) fntLib[x[1]](x[2]) end,
RELEASED=function(x) clustera=defaultCluster end,
},
fnt = {
PRESSED=function(x) if type(x)=="table" then fnt[x[1]].PRESSED(x[2]) else fnt.alpha.PRESSED(x) end end,
RELEASED=function(x) if type(x)=="table" then fnt[x[1]].RELEASED(x[2]) else fnt.alpha.RELEASED(x) end end,
},
}
function initialize_data(choix)
defaultCluster=1
clustera=defaultCluster
local listes={}
local cmax=0
for x,value in pairs(fnt) do
if type(value[choix])=="table" then
if #value[choix]>cmax then cmax=#value[choix] end
table.insert(listes,{value,value[choix]})
end
end
if cmax==0 then OutputLogMessage("Data empty in "..choix.."\n") else
initialize_table(cmax)
populate(listes)
end
end
function initialize_table(numberColonn)
data={}
for y=1, numberColonn do
data[y]={}
for x=1, 29 do
data[y][x]={}
data[y][x].G_PRESSED= function() end
data[y][x].G_RELEASED= function() clustera=defaultCluster end
end
end
end
function populate(listes)
for p, r in ipairs(listes) do
for t,v in ipairs(listes[p][2]) do
for i, value in pairs(listes[p][2][t]) do
data[t][i].G_PRESSED= function() listes[p][1].PRESSED(value) end
data[t][i].G_RELEASED= function() listes[p][1].RELEASED(value) end
end
end
end
end
0
Re: Summary : data engine
Options
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
04-18-2012 09:11 PM
Small improvement:
Use this:
c1[9]={"fntLib",{"actualizeTable"}} Or this:
c1[9]={"fntLib","actualizeTable"} With this change:
fntLib ={
PRESSED=function (x) if type(x)=="table" then fntLib[x[1]](x[2]) else fntLib[x]() end end,
RELEASED=function(x) clustera=defaultCluster end,
},
