Go で書き直した Ikemen
Révision | cdaa551a8b80624009c382ab5c52ed9fde84cf1a (tree) |
---|---|
l'heure | 2019-11-05 21:19:43 |
Auteur | neatunsou <sisiy4excite@gmai...> |
Commiter | neatunsou |
Windblade氏の更新に対応
@@ -1,8 +0,0 @@ | ||
1 | --- Screenpack Localcoord | |
2 | -main.SP_Localcoord[0] = 320 | |
3 | -main.SP_Localcoord[1] = 240 | |
4 | -main.SP_Center = 0 | |
5 | - | |
6 | --- Lifebar Localcoord | |
7 | -main.LB_Localcoord[0] = 320 | |
8 | -main.LB_Localcoord[1] = 240 | |
\ No newline at end of file |
@@ -1,3 +1,4 @@ | ||
1 | +------------------------------------------------------------- | |
1 | 2 | -- Disable GC during the initial load so it does not crash. |
2 | 3 | SetGCPercent(-1) |
3 | 4 | ------------------------------------------------------------- |
@@ -18,18 +19,11 @@ local file = io.open("save/config.json","r") | ||
18 | 19 | config = json.decode(file:read("*all")) |
19 | 20 | file:close() |
20 | 21 | |
21 | --- Int localcoord | |
22 | -require "script/screenpack" | |
23 | -main.IntLocalcoordValues() | |
24 | -require "script/localcoord" | |
25 | -main.CalculateLocalcoordValues() | |
26 | -main.IntLifebarScale() | |
27 | -main.SetScaleValues() | |
28 | - | |
29 | 22 | main.p1In = 1 |
30 | 23 | main.p2In = 2 |
31 | 24 | --main.inputDialog = inputDialogNew() |
32 | 25 | |
26 | +------------------------------------------------------------- | |
33 | 27 | function main.f_setCommand(c) |
34 | 28 | commandAdd(c, 'u', '$U') |
35 | 29 | commandAdd(c, 'd', '$D') |
@@ -75,6 +69,96 @@ function main.f_btnPalNo(cmd) | ||
75 | 69 | return 0 |
76 | 70 | end |
77 | 71 | |
72 | +-- Check if files exists. | |
73 | +function main.file_exists(name) | |
74 | + local f=io.open(name,"r") | |
75 | + if f~=nil then io.close(f) return true else return false end | |
76 | +end | |
77 | + | |
78 | +--prints "t" table content into "toFile" file | |
79 | +function main.f_printTable(t, toFile) | |
80 | + local toFile = toFile or 'debug/table_print.txt' | |
81 | + local txt = '' | |
82 | + local print_t_cache = {} | |
83 | + local function sub_print_t(t, indent) | |
84 | + if print_t_cache[tostring(t)] then | |
85 | + txt = txt .. indent .. '*' .. tostring(t) .. '\n' | |
86 | + else | |
87 | + print_t_cache[tostring(t)] = true | |
88 | + if type(t) == 'table' then | |
89 | + for pos, val in pairs(t) do | |
90 | + if type(val) == 'table' then | |
91 | + txt = txt .. indent .. '[' .. pos .. '] => ' .. tostring(t) .. ' {' .. '\n' | |
92 | + sub_print_t(val, indent .. string.rep(' ', string.len(tostring(pos)) + 8)) | |
93 | + txt = txt .. indent .. string.rep(' ', string.len(tostring(pos)) + 6) .. '}' .. '\n' | |
94 | + elseif type(val) == 'string' then | |
95 | + txt = txt .. indent .. '[' .. pos .. '] => "' .. val .. '"' .. '\n' | |
96 | + else | |
97 | + txt = txt .. indent .. '[' .. pos .. '] => ' .. tostring(val) ..'\n' | |
98 | + end | |
99 | + end | |
100 | + else | |
101 | + txt = txt .. indent .. tostring(t) .. '\n' | |
102 | + end | |
103 | + end | |
104 | + end | |
105 | + if type(t) == 'table' then | |
106 | + txt = txt .. tostring(t) .. ' {' .. '\n' | |
107 | + sub_print_t(t, ' ') | |
108 | + txt = txt .. '}' .. '\n' | |
109 | + else | |
110 | + sub_print_t(t, ' ') | |
111 | + end | |
112 | + local file = io.open(toFile,"w+") | |
113 | + if file == nil then return end | |
114 | + file:write(txt) | |
115 | + file:close() | |
116 | +end | |
117 | + | |
118 | +-- Prints "v" variable into "toFile" file | |
119 | +function main.f_printVar(v, toFile) | |
120 | + local toFile = toFile or 'debug/var_print.txt' | |
121 | + local file = io.open(toFile,"w+") | |
122 | + file:write(v) | |
123 | + file:close() | |
124 | +end | |
125 | + | |
126 | +-- Split strings. | |
127 | +function main.f_strsplit(delimiter, text) | |
128 | + local list = {} | |
129 | + local pos = 1 | |
130 | + if string.find('', delimiter, 1) then | |
131 | + if string.len(text) == 0 then | |
132 | + table.insert(list, text) | |
133 | + else | |
134 | + for i = 1, string.len(text) do | |
135 | + table.insert(list, string.sub(text, i, i)) | |
136 | + end | |
137 | + end | |
138 | + else | |
139 | + while true do | |
140 | + local first, last = string.find(text, delimiter, pos) | |
141 | + if first then | |
142 | + table.insert(list, string.sub(text, pos, first - 1)) | |
143 | + pos = last + 1 | |
144 | + else | |
145 | + table.insert(list, string.sub(text, pos)) | |
146 | + break | |
147 | + end | |
148 | + end | |
149 | + end | |
150 | + return list | |
151 | +end | |
152 | + | |
153 | +------------------------------------------------------------- | |
154 | +-- Int localcoord | |
155 | +require "script/screenpack" | |
156 | +main.IntLocalcoordValues() | |
157 | +main.CalculateLocalcoordValues() | |
158 | +main.IntLifebarScale() | |
159 | +main.SetScaleValues() | |
160 | +------------------------------------------------------------- | |
161 | + | |
78 | 162 | --animDraw at specified coordinates |
79 | 163 | function main.f_animPosDraw(a, x, y) |
80 | 164 | animSetPos(a, x, y) |
@@ -82,12 +166,6 @@ function main.f_animPosDraw(a, x, y) | ||
82 | 166 | animDraw(a) |
83 | 167 | end |
84 | 168 | |
85 | --- Check if files exists. | |
86 | -function main.file_exists(name) | |
87 | - local f=io.open(name,"r") | |
88 | - if f~=nil then io.close(f) return true else return false end | |
89 | -end | |
90 | - | |
91 | 169 | --textImgDraw at specified coordinates |
92 | 170 | function main.f_textImgPosDraw(ti, x, y, align) |
93 | 171 | align = align or 0 |
@@ -266,7 +344,7 @@ function main.f_getName(cell) | ||
266 | 344 | tmp = tmp:gsub('^["%s]*(.-)["%s]*$', '%1') --needed for s-size ikemen |
267 | 345 | if main.t_selChars[cell + 1].hidden == 3 then |
268 | 346 | tmp = 'Random' |
269 | - elseif main.t_selChars[cell + 1].hidden == 2 then | |
347 | + elseif main.t_selChars[cell + 1].hidden == 2 or main.t_selChars[cell + 1].hidden == 1 then | |
270 | 348 | tmp = '' |
271 | 349 | end |
272 | 350 | return tmp |
@@ -314,54 +392,6 @@ function main.f_sortKeys(t, order) | ||
314 | 392 | end |
315 | 393 | end |
316 | 394 | |
317 | ---prints "t" table content into "toFile" file | |
318 | -function main.f_printTable(t, toFile) | |
319 | - local toFile = toFile or 'debug/table_print.txt' | |
320 | - local txt = '' | |
321 | - local print_t_cache = {} | |
322 | - local function sub_print_t(t, indent) | |
323 | - if print_t_cache[tostring(t)] then | |
324 | - txt = txt .. indent .. '*' .. tostring(t) .. '\n' | |
325 | - else | |
326 | - print_t_cache[tostring(t)] = true | |
327 | - if type(t) == 'table' then | |
328 | - for pos, val in pairs(t) do | |
329 | - if type(val) == 'table' then | |
330 | - txt = txt .. indent .. '[' .. pos .. '] => ' .. tostring(t) .. ' {' .. '\n' | |
331 | - sub_print_t(val, indent .. string.rep(' ', string.len(tostring(pos)) + 8)) | |
332 | - txt = txt .. indent .. string.rep(' ', string.len(tostring(pos)) + 6) .. '}' .. '\n' | |
333 | - elseif type(val) == 'string' then | |
334 | - txt = txt .. indent .. '[' .. pos .. '] => "' .. val .. '"' .. '\n' | |
335 | - else | |
336 | - txt = txt .. indent .. '[' .. pos .. '] => ' .. tostring(val) ..'\n' | |
337 | - end | |
338 | - end | |
339 | - else | |
340 | - txt = txt .. indent .. tostring(t) .. '\n' | |
341 | - end | |
342 | - end | |
343 | - end | |
344 | - if type(t) == 'table' then | |
345 | - txt = txt .. tostring(t) .. ' {' .. '\n' | |
346 | - sub_print_t(t, ' ') | |
347 | - txt = txt .. '}' .. '\n' | |
348 | - else | |
349 | - sub_print_t(t, ' ') | |
350 | - end | |
351 | - local file = io.open(toFile,"w+") | |
352 | - if file == nil then return end | |
353 | - file:write(txt) | |
354 | - file:close() | |
355 | -end | |
356 | - | |
357 | ---prints "v" variable into "toFile" file | |
358 | -function main.f_printVar(v, toFile) | |
359 | - local toFile = toFile or 'debug/var_print.txt' | |
360 | - local file = io.open(toFile,"w+") | |
361 | - file:write(v) | |
362 | - file:close() | |
363 | -end | |
364 | - | |
365 | 395 | --remove duplicated string pattern |
366 | 396 | function main.f_uniq(str, pattern, subpattern) |
367 | 397 | local out = {} |
@@ -1087,9 +1117,12 @@ function main.f_addChar(line, row) | ||
1087 | 1117 | end |
1088 | 1118 | end |
1089 | 1119 | end |
1090 | - if main.t_selChars[row].exclude == nil then | |
1120 | + if main.t_selChars[row].hidden == nil then | |
1091 | 1121 | main.t_selChars[row].hidden = hidden |
1092 | 1122 | end |
1123 | + if main.t_selChars[row].exclude == nil then | |
1124 | + main.t_selChars[row].exclude = 0 | |
1125 | + end | |
1093 | 1126 | if order then |
1094 | 1127 | if main.t_orderChars[main.t_selChars[row].order] == nil then |
1095 | 1128 | main.t_orderChars[main.t_selChars[row].order] = {} |
@@ -1222,7 +1255,7 @@ end | ||
1222 | 1255 | --add Training by stupa if not included in select.def |
1223 | 1256 | if main.t_charDef.training == nil and main.f_fileExists('chars/training/training.def') then |
1224 | 1257 | chars = chars + 1 |
1225 | - main.f_addChar('training, exclude = 1', chars) | |
1258 | + main.f_addChar('training, exclude = 1, order = 0', chars) | |
1226 | 1259 | end |
1227 | 1260 | |
1228 | 1261 | --add remaining character parameters |
@@ -1,65 +1,104 @@ | ||
1 | 1 | -- Screenpack config file |
2 | 2 | |
3 | 3 | function main.IntLocalcoordValues() |
4 | + main.SP_Localcoord = {} | |
5 | + main.LB_Localcoord = {} | |
6 | + main.SP_Localcoord43 = {} | |
7 | + main.LB_Localcoord43 = {} | |
4 | 8 | |
5 | -main.SP_Localcoord = {} | |
6 | -main.LB_Localcoord = {} | |
7 | -main.SP_Localcoord43 = {} | |
8 | -main.LB_Localcoord43 = {} | |
9 | + main.SP_Localcoord[1] = 320 | |
10 | + main.SP_Localcoord[2] = 240 | |
11 | + main.LB_Localcoord[1] = 320 | |
12 | + main.LB_Localcoord[2] = 240 | |
9 | 13 | |
10 | -main.SP_Localcoord[0] = 320 | |
11 | -main.SP_Localcoord[1] = 240 | |
12 | -main.LB_Localcoord[0] = 320 | |
13 | -main.LB_Localcoord[1] = 240 | |
14 | + main.LB_ScreenWidth = 320 | |
15 | + main.LB_ScreenDiference = 0 | |
14 | 16 | |
15 | -main.LB_ScreenWidth = 320 | |
16 | -main.LB_ScreenDiference = 0 | |
17 | - | |
18 | -main.screenOverscan = 0 | |
19 | -main.normalSpriteCenter = 0 | |
20 | - | |
21 | -main.SP_Localcoord43[0] = 320 | |
22 | -main.LB_Localcoord43[0] = 240 | |
17 | + main.screenOverscan = 0 | |
18 | + main.normalSpriteCenter = 0 | |
23 | 19 | |
24 | -main.SP_Center = 0 | |
20 | + main.SP_Localcoord43[1] = 320 | |
21 | + main.LB_Localcoord43[1] = 240 | |
25 | 22 | |
23 | + main.SP_Center = 0 | |
26 | 24 | end |
27 | 25 | |
28 | 26 | function main.CalculateLocalcoordValues() |
29 | - if main.SP_Localcoord[0] >= main.SP_Localcoord[1] then | |
30 | - main.SP_Localcoord43[0] = (main.SP_Localcoord[1] / 3) * 4 | |
27 | + -- We load the libar localcoord from the motif file | |
28 | + main.SP_Localcoord = main.ParseDefFileValue(config.Motif, "info", "localcoord", true) | |
29 | + | |
30 | + -- We check if what we got is valid | |
31 | + if main.SP_Localcoord == nil then | |
32 | + main.SP_Localcoord = {320, 240} | |
33 | + end | |
34 | + | |
35 | + -- We now have to search for the config file. | |
36 | + local motifFileFolder = "" | |
37 | + local lbFileName = main.ParseDefFileValue(config.Motif, "files", "fight", false) | |
38 | + -- Get the morif file folder. | |
39 | + local tempMFF = main.f_strsplit("/",config.Motif) | |
40 | + local i = 1 | |
41 | + -- We skip the last object on the table (The file iteself) to get only the directory. | |
42 | + while i < table.getn(tempMFF) do | |
43 | + motifFileFolder = motifFileFolder .. tempMFF[i] .. "/" | |
44 | + i = i + 1 | |
45 | + end | |
46 | + tempMFF = nil | |
47 | + | |
48 | + -- We seach for the file | |
49 | + if main.file_exists(motifFileFolder .. lbFileName) then | |
50 | + main.LB_Localcoord = main.ParseDefFileValue(motifFileFolder .. lbFileName, "info", "localcoord", true) | |
51 | + elseif main.file_exists("data/" .. lbFileName) then | |
52 | + main.LB_Localcoord = main.ParseDefFileValue("data/" .. lbFileName, "info", "localcoord", true) | |
53 | + elseif main.file_exists(lbFileName) then | |
54 | + main.LB_Localcoord = main.ParseDefFileValue(lbFileName, "info", "localcoord", true) | |
55 | + else | |
56 | + main.LB_Localcoord = main.SP_Localcoord | |
57 | + end | |
58 | + | |
59 | + -- We check if what we got is valid | |
60 | + if main.LB_Localcoord == nil then | |
61 | + main.LB_Localcoord = main.SP_Localcoord | |
62 | + end | |
63 | + | |
64 | + -- And we calculate some extra stuff. | |
65 | + if main.SP_Localcoord[1] >= main.SP_Localcoord[2] then | |
66 | + main.SP_Localcoord43[1] = (main.SP_Localcoord[2] / 3) * 4 | |
31 | 67 | else |
32 | - main.SP_Localcoord43[0] = (main.SP_Localcoord[0] / 4) * 3 | |
68 | + main.SP_Localcoord43[1] = (main.SP_Localcoord[1] / 4) * 3 | |
33 | 69 | end |
34 | 70 | |
35 | - if main.LB_Localcoord[0] >= main.LB_Localcoord[1] then | |
36 | - main.LB_Localcoord43[0] = (main.LB_Localcoord[1] / 3) * 4 | |
71 | + if main.LB_Localcoord[1] >= main.LB_Localcoord[2] then | |
72 | + main.LB_Localcoord43[1] = (main.LB_Localcoord[2] / 3) * 4 | |
37 | 73 | else |
38 | - main.LB_Localcoord43[0] = (main.LB_Localcoord[0] / 4) * 3 | |
74 | + main.LB_Localcoord43[1] = (main.LB_Localcoord[1] / 4) * 3 | |
39 | 75 | end |
40 | 76 | |
41 | - main.SP_Localcoord_X_Dif = -math.floor( (( main.SP_Localcoord[0] / (main.SP_Localcoord43[0] / 320) ) - 320) / 2 ) | |
77 | + main.SP_Localcoord_X_Dif = -math.floor( (( main.SP_Localcoord[1] / (main.SP_Localcoord43[1] / 320) ) - 320) / 2 ) | |
42 | 78 | |
43 | 79 | main.LB_ScreenWidth = config.Width / (config.Height / 240) |
44 | 80 | main.LB_ScreenDiference = (main.LB_ScreenWidth - 320) / (main.LB_ScreenWidth / 320) |
81 | + --setLifebarPortaitScale(main.SP_Localcoord[1] / main.SP_Localcoord43[1]) | |
45 | 82 | |
83 | + -- TODO: Check if this calculation of 'main.SP_Center' is rigth. | |
84 | + main.SP_Center = main.SP_Localcoord[1] - main.SP_Localcoord43[1] | |
46 | 85 | end |
47 | 86 | |
48 | 87 | function main.IntLifebarScale() |
49 | 88 | if config.LocalcoordScalingType == 0 then |
50 | 89 | setLifebarOffsetX( - main.LB_ScreenDiference / 2) |
51 | - setLuaLifebarScale(main.LB_ScreenWidth / main.LB_Localcoord43[0]) | |
90 | + setLuaLifebarScale(main.LB_ScreenWidth / main.LB_Localcoord43[1]) | |
52 | 91 | else |
53 | - setLifebarOffsetX((main.LB_Localcoord43[0] - main.LB_Localcoord[0]) / 2) | |
54 | - setLuaLifebarScale(320 / main.LB_Localcoord43[0]) | |
92 | + setLifebarOffsetX((main.LB_Localcoord43[1] - main.LB_Localcoord[1]) / 2) | |
93 | + setLuaLifebarScale(320 / main.LB_Localcoord43[1]) | |
55 | 94 | end |
56 | 95 | end |
57 | 96 | |
58 | 97 | function main.SetScaleValues() |
59 | - setLuaSpriteScale(main.SP_Localcoord43[0] / 320) | |
98 | + setLuaSpriteScale(main.SP_Localcoord43[1] / 320) | |
60 | 99 | setLuaSpriteOffsetX(main.SP_Localcoord_X_Dif) |
61 | - setLuaSmallPortraitScale(main.SP_Localcoord43[0] / main.SP_Localcoord[0]) | |
62 | - setLuaBigPortraitScale(main.SP_Localcoord43[0] / main.SP_Localcoord[0]) | |
100 | + setLuaSmallPortraitScale(main.SP_Localcoord43[1] / main.SP_Localcoord[1]) | |
101 | + setLuaBigPortraitScale(main.SP_Localcoord43[1] / main.SP_Localcoord[1]) | |
63 | 102 | main.normalSpriteCenter = main.SP_Center |
64 | 103 | main.screenOverscan = 0 |
65 | 104 | end |
@@ -72,4 +111,70 @@ function main.SetDefaultScale() | ||
72 | 111 | setLuaBigPortraitScale(1) |
73 | 112 | main.normalSpriteCenter = 0 |
74 | 113 | main.screenOverscan = 0 |
114 | +end | |
115 | + | |
116 | +-- Edited version of the parser in motif.lua, made to parse only a single value and end once it steps outside [searchBlock] | |
117 | +function main.ParseDefFileValue(argFile, searchBlock, searchParam, isNumber) | |
118 | + -- We use 'arg' inestead of 'config.Motif' because we also want the option to parse the lifebar | |
119 | + local file = io.open(argFile) | |
120 | + local weAreInInfo = 0 | |
121 | + local ret = {} | |
122 | + local ipos = 0 | |
123 | + | |
124 | + for line in file:lines() do | |
125 | + ipos = ipos +1 | |
126 | + if weAreInInfo ~= 2 then | |
127 | + local line = line:gsub('%s*;.*$', '') | |
128 | + if line:match('^%s*%[.-%s*%]%s*$') then -- matched [] group | |
129 | + line = line:match('^%s*%[(.-)%s*%]%s*$') -- match text between [] | |
130 | + line = line:gsub('[%. ]', '_') -- change . and space to _ | |
131 | + line = line:lower() -- lowercase line | |
132 | + local row = tostring(line:lower()) -- just in case it's a number (not really needed) | |
133 | + | |
134 | + if row == searchBlock then -- matched info | |
135 | + weAreInInfo = 1 | |
136 | + else | |
137 | + if weAreInInfo == 1 then weAreInInfo = 2 end | |
138 | + end | |
139 | + elseif weAreInInfo == 1 then -- matched non [] line inside [Info] | |
140 | + local param, value = line:match('^%s*([^=]-)%s*=%s*(.-)%s*$') | |
141 | + if param ~= nil then | |
142 | + param = param:gsub('[%. ]', '_') -- change param . and space to _ | |
143 | + param = param:lower() -- lowercase param | |
144 | + end | |
145 | + if param ~= nil and value ~= nil and param:match(searchParam) then -- param = value pattern matched | |
146 | + value = value:gsub('"', '') -- remove brackets from value | |
147 | + if value:match('.+,.+') then -- multiple values | |
148 | + for i, c in ipairs(main.f_strsplit(',', value)) do -- split value using "," delimiter | |
149 | + if c == nil or c == '' then | |
150 | + ret[i] = nil | |
151 | + else | |
152 | + if isNumber == true then | |
153 | + ret[i] = tonumber(c) | |
154 | + else | |
155 | + ret[i] = c | |
156 | + end | |
157 | + end | |
158 | + end | |
159 | + else --single value | |
160 | + if isNumber == true then | |
161 | + ret = tonumber(value) | |
162 | + else | |
163 | + ret = value | |
164 | + end | |
165 | + end | |
166 | + end | |
167 | + end | |
168 | + end | |
169 | + end | |
170 | + file:close() | |
171 | + | |
172 | + -- Let's check if the table values are valid | |
173 | + if type(ret) == "table" and (ret[1] == nil or ret[2] == nil) then | |
174 | + -- If not we return nil | |
175 | + ret = nil | |
176 | + end | |
177 | + | |
178 | + -- Return what we parsed | |
179 | + return ret | |
75 | 180 | end |
\ No newline at end of file |
@@ -2542,12 +2542,9 @@ local txt_credits = main.f_createTextImg( | ||
2542 | 2542 | ) |
2543 | 2543 | |
2544 | 2544 | function select.f_continue() |
2545 | - main.f_resetBG(motif.continue_screen, motif.continuebgdef, motif.music.continue_bgm, motif.music.continue_bgm_loop, motif.music.continue_bgm_volume, motif.music.continue_bgm_loopstart, motif.music.continue_bgm_loopend) | |
2546 | - animReset(motif.continue_screen.continue_anim_data) | |
2547 | - animUpdate(motif.continue_screen.continue_anim_data) | |
2548 | 2545 | continue = false |
2549 | - local text = main.f_extractText(motif.continue_screen.credits_text, main.credits) | |
2550 | - textImgSetText(txt_credits, text[1]) | |
2546 | + playBGM(motif.music.continue_bgm, true, motif.music.continue_bgm_loop, motif.music.continue_bgm_volume, motif.music.continue_bgm_loopstart or "0", motif.music.continue_bgm_loopend or "0") | |
2547 | + --textImgSetText(txt_credits, text[1]) | |
2551 | 2548 | main.f_cmdInput() |
2552 | 2549 | while true do |
2553 | 2550 | --draw clearcolor (disabled to not cover area) |
@@ -626,7 +626,7 @@ func JoystickState(joy, button int) bool { | ||
626 | 626 | return false |
627 | 627 | } |
628 | 628 | if (button == 8 || button == 10) && glfw.GetJoystickName(joystick[joy]) == "Xbox 360 Controller" { //Xbox360コントローラーのLRトリガー判定 |
629 | - return axes[button/2] > 0 | |
629 | + return axes[button/2] > sys.xinputTriggerSensitivity | |
630 | 630 | } |
631 | 631 | |
632 | 632 | // Ignore trigger axis on PS4 (We already have buttons) |
@@ -636,9 +636,9 @@ func JoystickState(joy, button int) bool { | ||
636 | 636 | |
637 | 637 | switch button & 1 { |
638 | 638 | case 0: |
639 | - return axes[button/2] < -0.2 | |
639 | + return axes[button/2] < -sys.controllerStickSensitivity | |
640 | 640 | case 1: |
641 | - return axes[button/2] > 0.2 | |
641 | + return axes[button/2] > sys.controllerStickSensitivity | |
642 | 642 | } |
643 | 643 | } |
644 | 644 | if len(btns) <= button { |
@@ -76,70 +76,84 @@ func main() { | ||
76 | 76 | } |
77 | 77 | chk(glfw.Init()) |
78 | 78 | defer glfw.Terminate() |
79 | - defcfg := []byte(strings.Join(strings.Split(`{ | |
80 | - "HelperMax":56, | |
81 | - "PlayerProjectileMax":256, | |
82 | - "ExplodMax":512, | |
83 | - "AfterImageMax":128, | |
84 | - "MasterVolume":80, | |
85 | - "WavVolume":80, | |
86 | - "BgmVolume":80, | |
87 | - "Attack.LifeToPowerMul":0.7, | |
88 | - "GetHit.LifeToPowerMul":0.6, | |
89 | - "Width":640, | |
90 | - "Height":480, | |
91 | - "Super.TargetDefenceMul":1.5, | |
92 | - "LifebarFontScale":1, | |
93 | - "System":"script/main.lua", | |
94 | - "KeyConfig":[{ | |
95 | - "Joystick":-1, | |
96 | - "Buttons":["UP","DOWN","LEFT","RIGHT","z","x","c","a","s","d","RETURN","q","w"] | |
97 | - },{ | |
98 | - "Joystick":-1, | |
99 | - "Buttons":["t","g","f","h","j","k","l","u","i","o","RSHIFT","LEFTBRACKET","RIGHTBRACKET"] | |
100 | - }], | |
101 | - "JoystickConfig":[{ | |
102 | - "Joystick":0, | |
103 | - "Buttons":["-7","-8","-5","-6","0","1","4","2","3","5","7","6","8"] | |
104 | - },{ | |
105 | - "Joystick":1, | |
106 | - "Buttons":["-7","-8","-5","-6","0","1","4","2","3","5","7","6","8"] | |
107 | - }], | |
108 | - "Motif":"data/system.def", | |
109 | - "CommonAir":"data/common.air", | |
110 | - "CommonCmd":"data/common.cmd", | |
111 | - "SimulMode":true, | |
112 | - "LifeMul":100, | |
113 | - "Team1VS2Life":120, | |
114 | - "TurnsRecoveryRate":300, | |
115 | - "ZoomActive":false, | |
116 | - "ZoomMin":0.75, | |
117 | - "ZoomMax":1.1, | |
118 | - "ZoomSpeed":1, | |
119 | - "RoundTime":99, | |
120 | - "SingleTeamMode":true, | |
121 | - "NumTurns":4, | |
122 | - "NumSimul":4, | |
123 | - "NumTag":4, | |
124 | - "Difficulty":8, | |
125 | - "Credits":10, | |
126 | - "ListenPort":7500, | |
127 | - "ContSelection":true, | |
128 | - "AIRandomColor":true, | |
129 | - "AIRamping":true, | |
130 | - "AutoGuard":false, | |
131 | - "TeamPowerShare":false, | |
132 | - "TeamLifeShare":false, | |
133 | - "Fullscreen":false, | |
134 | - "AudioDucking":false, | |
135 | - "QuickLaunch":0, | |
136 | - "AllowDebugKeys":true, | |
137 | - "ComboExtraFrameWindow": 1, | |
138 | - "PostProcessingShader": 0, | |
139 | - "LocalcoordScalingType": 1, | |
140 | - "MSAA": false, | |
141 | - "IP":{ | |
142 | - } | |
79 | + defcfg := []byte(strings.Join(strings.Split( | |
80 | +`{ | |
81 | + "HelperMax": 56, | |
82 | + "PlayerProjectileMax": 256, | |
83 | + "ExplodMax": 512, | |
84 | + "AfterImageMax": 128, | |
85 | + "MasterVolume": 80, | |
86 | + "WavVolume": 80, | |
87 | + "BgmVolume": 80, | |
88 | + "Attack.LifeToPowerMul": 0.7, | |
89 | + "GetHit.LifeToPowerMul": 0.6, | |
90 | + "Width": 640, | |
91 | + "Height": 480, | |
92 | + "Super.TargetDefenceMul": 1.5, | |
93 | + "LifebarFontScale": 1, | |
94 | + "System": "script/main.lua", | |
95 | + "KeyConfig": [ | |
96 | + { | |
97 | + "Joystick": -1, | |
98 | + "Buttons": ["UP", "DOWN", "LEFT", "RIGHT", "z", "x", "c", "a", "s", "d", "RETURN", "q", "w"] | |
99 | + }, | |
100 | + { | |
101 | + "Joystick": -1, | |
102 | + "Buttons": ["t", "g", "f", "h", "j", "k", "l", "u", "i", "o", "RSHIFT", "LEFTBRACKET", "RIGHTBRACKET"] | |
103 | + } | |
104 | + ], | |
105 | + "JoystickConfig": [ | |
106 | + { | |
107 | + "Joystick": 1, | |
108 | + "Buttons": ["-7", "-8", "-5", "-6", "0", "1", "4", "2", "3", "5", "7", "6", "8"] | |
109 | + }, | |
110 | + { | |
111 | + "Joystick": 1, | |
112 | + "Buttons": ["-7", "-8", "-5", "-6", "0", "1", "4", "2", "3", "5", "7", "6", "8"] | |
113 | + } | |
114 | + ], | |
115 | + "ControllerStickSensitivity": 0.4, | |
116 | + "XinputTriggerSensitivity": 0, | |
117 | + "Motif": "data/system.def", | |
118 | + "CommonAir": "data/common.air", | |
119 | + "CommonCmd": "data/common.cmd", | |
120 | + "SimulMode": true, | |
121 | + "LifeMul": 100, | |
122 | + "Team1VS2Life": 120, | |
123 | + "TurnsRecoveryRate": 300, | |
124 | + "ZoomActive": false, | |
125 | + "ZoomMin": 0.75, | |
126 | + "ZoomMax": 1.1, | |
127 | + "ZoomSpeed": 1, | |
128 | + "RoundTime": 99, | |
129 | + "SingleTeamMode": true, | |
130 | + "NumTurns": 4, | |
131 | + "NumSimul": 4, | |
132 | + "NumTag": 4, | |
133 | + "Difficulty": 8, | |
134 | + "Credits": 10, | |
135 | + "ListenPort": 7500, | |
136 | + "IP": { | |
137 | + | |
138 | + }, | |
139 | + "ContSelection": true, | |
140 | + "AIRandomColor": true, | |
141 | + "AIRamping": true, | |
142 | + "AutoGuard": false, | |
143 | + "TeamPowerShare": false, | |
144 | + "TeamLifeShare": false, | |
145 | + "Fullscreen": false, | |
146 | + "AudioDucking": false, | |
147 | + "QuickLaunch": 0, | |
148 | + "AllowDebugKeys": true, | |
149 | + "ComboExtraFrameWindow": 1, | |
150 | + "PostProcessingShader": 0, | |
151 | + "LocalcoordScalingType": 1, | |
152 | + "MSAA": false, | |
153 | + "WindowMainIconLocation": [ | |
154 | + "script/Icons/16x16.png", | |
155 | + "script/Icons/24x24.png" | |
156 | + ] | |
143 | 157 | } |
144 | 158 | `, "\n"), "\r\n")) |
145 | 159 | tmp := struct { |
@@ -165,19 +179,22 @@ func main() { | ||
165 | 179 | Joystick int |
166 | 180 | Buttons []interface{} |
167 | 181 | } |
168 | - NumTag int | |
169 | - TeamLifeShare bool | |
170 | - AIRandomColor bool | |
171 | - ComboExtraFrameWindow int32 | |
172 | - Fullscreen bool | |
173 | - AudioDucking bool | |
174 | - AllowDebugKeys bool | |
175 | - MSAA bool | |
176 | - PostProcessingShader int32 | |
177 | - LocalcoordScalingType int32 | |
178 | - CommonAir string | |
179 | - CommonCmd string | |
180 | - QuickLaunch int | |
182 | + NumTag int | |
183 | + TeamLifeShare bool | |
184 | + AIRandomColor bool | |
185 | + ComboExtraFrameWindow int32 | |
186 | + Fullscreen bool | |
187 | + AudioDucking bool | |
188 | + AllowDebugKeys bool | |
189 | + MSAA bool | |
190 | + PostProcessingShader int32 | |
191 | + LocalcoordScalingType int32 | |
192 | + CommonAir string | |
193 | + CommonCmd string | |
194 | + QuickLaunch int | |
195 | + ControllerStickSensitivity float32 | |
196 | + XinputTriggerSensitivity float32 | |
197 | + WindowMainIconLocation []string | |
181 | 198 | }{} |
182 | 199 | chk(json.Unmarshal(defcfg, &tmp)) |
183 | 200 | const configFile = "save/config.json" |
@@ -193,6 +210,8 @@ func main() { | ||
193 | 210 | } |
194 | 211 | chk(json.Unmarshal(bytes, &tmp)) |
195 | 212 | } |
213 | + sys.controllerStickSensitivity = tmp.ControllerStickSensitivity | |
214 | + sys.xinputTriggerSensitivity = tmp.XinputTriggerSensitivity | |
196 | 215 | sys.helperMax = tmp.HelperMax |
197 | 216 | sys.playerProjectileMax = tmp.PlayerProjectileMax |
198 | 217 | sys.explodMax = tmp.ExplodMax |
@@ -203,6 +222,9 @@ func main() { | ||
203 | 222 | sys.comboExtraFrameWindow = tmp.ComboExtraFrameWindow |
204 | 223 | sys.lifebarFontScale = tmp.LifebarFontScale |
205 | 224 | sys.quickLaunch = tmp.QuickLaunch |
225 | + sys.windowMainIconLocation = tmp.WindowMainIconLocation | |
226 | + // For debug testing letting this here comented because it could be usefull in the future. | |
227 | + // log.Printf("Unmarshaled: %v", tmp.WindowMainIconLocation) | |
206 | 228 | sys.masterVolume = tmp.MasterVolume |
207 | 229 | sys.wavVolume = tmp.WavVolume |
208 | 230 | sys.bgmVolume = tmp.BgmVolume |
@@ -239,6 +261,7 @@ func main() { | ||
239 | 261 | } |
240 | 262 | } |
241 | 263 | } |
264 | + | |
242 | 265 | sys.teamLifeShare = tmp.TeamLifeShare |
243 | 266 | sys.fullscreen = tmp.Fullscreen |
244 | 267 | sys.PostProcessingShader = tmp.PostProcessingShader |
@@ -1,6 +1,8 @@ | ||
1 | 1 | package main |
2 | 2 | |
3 | 3 | import ( |
4 | + "io" | |
5 | + "image" | |
4 | 6 | "bufio" |
5 | 7 | "fmt" |
6 | 8 | "io/ioutil" |
@@ -29,7 +31,7 @@ const ( | ||
29 | 31 | ) |
30 | 32 | |
31 | 33 | // System vars are accessed globally through the program |
32 | -var sys = System{ | |
34 | +var sys = System { | |
33 | 35 | randseed: int32(time.Now().UnixNano()), |
34 | 36 | scrrect: [...]int32{0, 0, 320, 240}, |
35 | 37 | gameWidth: 320, gameHeight: 240, |
@@ -250,6 +252,10 @@ type System struct { | ||
250 | 252 | bgmVolume int |
251 | 253 | AudioDucking bool |
252 | 254 | FLAC_FrameWait int |
255 | + | |
256 | + controllerStickSensitivity float32 | |
257 | + xinputTriggerSensitivity float32 | |
258 | + | |
253 | 259 | // Localcoord sceenpack |
254 | 260 | luaSpriteScale float64 |
255 | 261 | luaSmallPortraitScale float32 |
@@ -262,9 +268,15 @@ type System struct { | ||
262 | 268 | |
263 | 269 | PostProcessingShader int32 |
264 | 270 | MultisampleAntialiasing bool |
271 | + | |
272 | + // Icon :D | |
273 | + windowMainIcon []image.Image | |
274 | + windowMainIconLocation []string | |
265 | 275 | } |
266 | 276 | |
277 | +// Initialize stuff, this is called after the config int at main.go | |
267 | 278 | func (s *System) init(w, h int32) *lua.LState { |
279 | + // Create a GLWF window. | |
268 | 280 | glfw.WindowHint(glfw.Resizable, glfw.False) |
269 | 281 | glfw.WindowHint(glfw.ContextVersionMajor, 2) |
270 | 282 | glfw.WindowHint(glfw.ContextVersionMinor, 1) |
@@ -300,6 +312,20 @@ func (s *System) init(w, h int32) *lua.LState { | ||
300 | 312 | s.clsnSpr.Size, s.clsnSpr.Pal = [...]uint16{1, 1}, make([]uint32, 256) |
301 | 313 | s.clsnSpr.SetPxl([]byte{0}) |
302 | 314 | systemScriptInit(l) |
315 | + // So now that we have a windo we add a icon. | |
316 | + if len(s.windowMainIconLocation) > 0 { | |
317 | + // First we initialize arrays. | |
318 | + f := make([]io.ReadCloser, len(s.windowMainIconLocation) ) | |
319 | + s.windowMainIcon = make([]image.Image, len(s.windowMainIconLocation)) | |
320 | + // And then we load them. | |
321 | + for i, iconLocation := range s.windowMainIconLocation { | |
322 | + f[i], _ = os.Open(iconLocation) | |
323 | + s.windowMainIcon[i], _, err = image.Decode(f[i]) | |
324 | + } | |
325 | + s.window.SetIcon(s.windowMainIcon) | |
326 | + chk(err) | |
327 | + } | |
328 | + // [Icon add end] | |
303 | 329 | go func() { |
304 | 330 | stdin := bufio.NewScanner(os.Stdin) |
305 | 331 | for stdin.Scan() { |