1 local registerFeature
= function()
3 feature
.Name
= "TextManager"
5 feature
.Description
= "A little texts manager"
12 {Name
="InstanceId",Type
="String"},
13 {Name
="Texts",Type
="Table"},
17 Name
="TextManagerEntry",
20 {Name
="InstanceId", Type
="String" },
21 {Name
="Text",Type
="String"},
22 {Name
="Count",Type
="Number"}
29 --returns nil if the text is still in the textManager
30 --else, return a new entry, not inserted in the TextManager
31 feature
.checkText
= function(textManager
,text
)
32 local texts
= r2
.Scenario
.Texts
.Texts
33 k
,entry
= next(texts
,nil)
35 local textEntry
= entry
.Text
40 k
,entry
= next(texts
,k
)
42 entry
= r2
.newComponent("TextManagerEntry")
48 feature
.getText
= function (textManager
, entry
)
50 debugInfo("feature.getText")
52 for i
=0, textManager
.Texts
.Size
-1 do
54 local text
= textManager
.Texts
[i
]
56 if text
.InstanceId
== entry
64 --add a text to the text manager.
65 --if the text exist, increment its counter
66 feature
.addText
= function(textManager
,text
)
67 local max = table.getn(textManager
.Texts
)
71 entry
= textManager
.Texts
[i
]
74 entry
.Count
= entry
.Count
+1
79 entry
= r2
.newComponent("TextManagerEntry")
82 table.insert(textManager
.Texts
,entry
)
86 --decrement the counter of a text.
87 --if this counter==0, remove the text from the TextManager
88 feature
.removeText
= function(textManager
, text
)
90 for i
=0,textManager
.Texts
.Size
-1 do
91 local entry
= textManager
.Texts
[i
]
92 if entry
.Text
==text
then
94 local newCount
= entry
.Count
-1
97 r2
.requestEraseNode(entry
.InstanceId
, "", -1)
99 r2
.requestSetNode(entry
.InstanceId
, "Count", newCount
)
107 feature
.Translator
= function(context
)
108 local comp
= context
.Feature
109 local texts
= context
.Feature
.Texts
111 local rtTextMgr
= context
.RtScenario
.Texts
113 local k
,v
= next(texts
,nil)
117 --create and fill a RT entry
118 entry
= r2
.newComponent("RtEntryText")
120 --insert it in the RT text manager
121 table.insert(rtTextMgr
.Texts
,entry
)
123 table.insert(tmp
,v
.InstanceId
)
124 table.insert(tmp
,entry
.Id
)
125 table.insert(context
.TextTranslateId
,tmp
)
129 if table.getn(context
.TextTranslateId
)==0
131 debugInfo("translator:: pas d'entrees dans la table!!!")
136 feature
.getRtId
= function(context
, instanceId
)
137 local tab
= context
.TextTranslateId
139 for k
,v
in pairs(tab
)
141 if instanceId
== v
[1]
146 local max = table.getn(tab
)
149 debugInfo(colorTag(255, 255, 0).."WAR: The text table is empty.")
154 if instanceId
== tab
[i
][1]
164 r2
.Features
["TextManager"] = registerFeature()