ConfigInfo.lua
2.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
cc.exports.ConfigInfo = {}
local configMap = {};
local function str_split(str,split_char)
str = tostring(str);
local sub_str_tab = {};
while (true) do
local pos = nil
for i = 1, #str do
if string.sub(str, i, i) == split_char then
pos = i
break
end
end
if (not pos) then
sub_str_tab[#sub_str_tab + 1] = str;
break;
end
local sub_str = string.sub(str, 1, pos - 1);
sub_str_tab[#sub_str_tab + 1] = sub_str;
str = string.sub(str, pos + 1, #str);
end
return sub_str_tab;
end
--配置表信息
local function init()
local itemStr = cc.FileUtils:getInstance():getStringFromFile("config.ini");
local function readLineFun(lineStr)
local contents = str_split(lineStr,'=');
if #contents > 1 then
configMap[contents[1]] = contents[2];
end
end
local index = 1;
local function readLine(str)
local a,b = string.find(str,"\r\n");
if a then
local lineStr = string.sub(str,1,a-1);
readLineFun(lineStr);
index = index + 1;
str = string.sub(str,b+1);
readLine(str);
else
readLineFun(str);
end
end
readLine(itemStr);
end
init();
--通过ID获取信息
function ConfigInfo.getConfigInfo(id)
return configMap[tostring(id)];
end
--读取txt配置
function ConfigInfo.readTxtLines(linesStr)
local lineMap = {};
local function readLineFun(lineStr)
local contents = str_split(lineStr,'=');
lineMap[contents[1]] = contents[2];
end
local index = 1;
local function readLine(str)
local a,b = string.find(str,"\r\n");
if a then
local lineStr = string.sub(str,1,a-1);
readLineFun(lineStr);
index = index + 1;
str = string.sub(str,b+1);
readLine(str);
else
readLineFun(str);
end
end
readLine(linesStr);
return lineMap;
end
return ConfigInfo