Go で書き直した Ikemen
修订版 | c9a73394d575f8752bcb49d1380237f7a21af92d (tree) |
---|---|
时间 | 2019-09-08 19:04:30 |
作者 | neatunsou <sisiy4excite@gmai...> |
Commiter | neatunsou |
BGMのloopstartとloopendを読み込むようにした
Screenpackでbgmのloopとvolumeを読み込むようにした
Storyboardでテキスト表示ができなかったのを修正
StoryboardのBGdefを読み込むときに文字列でインデックスを取ろうとする場合があったのを修正
@@ -658,7 +658,7 @@ function main.f_drawBG(data, info, layerno, timer) | ||
658 | 658 | end |
659 | 659 | |
660 | 660 | --reset screenpack data |
661 | -function main.f_resetBG(info, bgdef, bgm) | |
661 | +function main.f_resetBG(info, bgdef, bgm, bgmLoop, bgmVolume, bgmloopstart, bgmloopend) | |
662 | 662 | bgm = bgm or nil |
663 | 663 | animReset(info.fadein_data) |
664 | 664 | animUpdate(info.fadein_data) |
@@ -684,7 +684,7 @@ function main.f_resetBG(info, bgdef, bgm) | ||
684 | 684 | end |
685 | 685 | end |
686 | 686 | if bgm ~= nil then |
687 | - playBGM(bgm) | |
687 | + playBGM(bgm, true, bgmLoop, bgmVolume, bgmloopstart or "0", bgmloopend or "0") | |
688 | 688 | end |
689 | 689 | end |
690 | 690 |
@@ -1152,7 +1152,7 @@ for line in content:gmatch('[^\r\n]+') do | ||
1152 | 1152 | break |
1153 | 1153 | end |
1154 | 1154 | main.t_selStages[row] = {name = tmp, stage = c} |
1155 | - local zoomout, zoomin, bgmusic, bgmvolume = getStageInfo(row) | |
1155 | + local zoomout, zoomin, bgmusic, bgmvolume, bgmloopstart, bgmloopend = getStageInfo(row) | |
1156 | 1156 | if zoomout ~= '' then |
1157 | 1157 | main.t_selStages[row].zoommin = tonumber(zoomout) |
1158 | 1158 | end |
@@ -1161,7 +1161,7 @@ for line in content:gmatch('[^\r\n]+') do | ||
1161 | 1161 | end |
1162 | 1162 | if bgmusic ~= '' then |
1163 | 1163 | bgmusic = bgmusic:gsub('\\', '/') |
1164 | - main.t_selStages[row].music = {[1] = {bgmusic = bgmusic, bgmvolume = tonumber(bgmvolume)}} | |
1164 | + main.t_selStages[row].music = {[1] = {bgmusic = bgmusic, bgmvolume = tonumber(bgmvolume), bgmloopstart = bgmloopstart, bgmloopend = bgmloopend}} | |
1165 | 1165 | end |
1166 | 1166 | main.t_includeStage[#main.t_includeStage + 1] = row |
1167 | 1167 | main.t_stageDef[c] = row |
@@ -1231,7 +1231,7 @@ for i = 1, #main.t_selChars do | ||
1231 | 1231 | break |
1232 | 1232 | end |
1233 | 1233 | main.t_selStages[row] = {name = tmp, stage = main.t_selChars[i].stage[j]} |
1234 | - local zoomout, zoomin, bgmusic, bgmvolume = getStageInfo(row) | |
1234 | + local zoomout, zoomin, bgmusic, bgmvolume, bgmloopstart, bgmloopend = getStageInfo(row) | |
1235 | 1235 | if zoomout ~= '' then |
1236 | 1236 | main.t_selStages[row].zoommin = tonumber(zoomout) |
1237 | 1237 | end |
@@ -1241,7 +1241,7 @@ for i = 1, #main.t_selChars do | ||
1241 | 1241 | if bgmusic ~= '' then |
1242 | 1242 | bgmusic = bgmusic:gsub('\\', '/') |
1243 | 1243 | main.t_selStages[row].music = {} |
1244 | - main.t_selStages[row].music[1] = {bgmusic = bgmusic, bgmvolume = tonumber(bgmvolume)} | |
1244 | + main.t_selStages[row].music[1] = {bgmusic = bgmusic, bgmvolume = tonumber(bgmvolume), bgmloopstart = bgmloopstart, bgmloopend = bgmloopend} | |
1245 | 1245 | end |
1246 | 1246 | if main.t_selChars[i].includestage == nil or main.t_selChars[i].includestage == 1 then |
1247 | 1247 | main.t_includeStage[#main.t_includeStage + 1] = row |
@@ -1583,7 +1583,7 @@ function main.f_mainMenu() | ||
1583 | 1583 | if motif.files.intro_storyboard ~= '' then |
1584 | 1584 | storyboard.f_storyboard(motif.files.intro_storyboard) |
1585 | 1585 | end |
1586 | - main.f_resetBG(motif.title_info, motif.titlebgdef, motif.music.title_bgm) | |
1586 | + main.f_resetBG(motif.title_info, motif.titlebgdef, motif.music.title_bgm, motif.music.title_bgm_loop, motif.music.title_bgm_volume, motif.music.title_bgm_loopstart, motif.music.title_bgm_loopend) | |
1587 | 1587 | while true do |
1588 | 1588 | cursorPosY, moveTxt, item = main.f_menuCommon1(cursorPosY, moveTxt, item, t) |
1589 | 1589 | if esc() then |
@@ -42,42 +42,44 @@ local motif = | ||
42 | 42 | { |
43 | 43 | title_bgm = '', |
44 | 44 | title_bgm_volume = 100, |
45 | - title_bgm_loop = 1, --not supported yet | |
46 | - title_bgm_loopstart = nil, --not supported yet | |
47 | - title_bgm_loopend = nil, --not supported yet | |
45 | + title_bgm_loop = 1, | |
46 | + title_bgm_loopstart = nil, | |
47 | + title_bgm_loopend = nil, | |
48 | 48 | select_bgm = '', |
49 | 49 | select_bgm_volume = 100, |
50 | - select_bgm_loop = 1, --not supported yet | |
51 | - select_bgm_loopstart = nil, --not supported yet | |
52 | - select_bgm_loopend = nil, --not supported yet | |
50 | + select_bgm_loop = 1, | |
51 | + select_bgm_loopstart = nil, | |
52 | + select_bgm_loopend = nil, | |
53 | 53 | vs_bgm = '', |
54 | 54 | vs_bgm_volume = 100, |
55 | - vs_bgm_loop = 1, --not supported yet | |
56 | - vs_bgm_loopstart = nil, --not supported yet | |
57 | - vs_bgm_loopend = nil, --not supported yet | |
55 | + vs_bgm_loop = 1, | |
56 | + vs_bgm_loopstart = nil, | |
57 | + vs_bgm_loopend = nil, | |
58 | 58 | victory_bgm = '', |
59 | 59 | victory_bgm_volume = 100, |
60 | - victory_bgm_loop = 1, --not supported yet | |
61 | - victory_bgm_loopstart = nil, --not supported yet | |
62 | - victory_bgm_loopend = nil, --not supported yet | |
60 | + victory_bgm_loop = 1, | |
61 | + victory_bgm_loopstart = nil, | |
62 | + victory_bgm_loopend = nil, | |
63 | 63 | continue_bgm = 'sound/CONTINUE.ogg', --Ikemen feature |
64 | - continue_bgm_volume = 100, --Ikemen feature (not supported yet) | |
65 | - continue_bgm_loop = 1, --Ikemen feature (not supported yet) | |
66 | - continue_bgm_loopstart = nil, --Ikemen feature (not supported yet) | |
67 | - continue_bgm_loopend = nil, --Ikemen feature (not supported yet) | |
64 | + continue_bgm_volume = 100, --Ikemen feature | |
65 | + continue_bgm_loop = 1, --Ikemen feature | |
66 | + continue_bgm_loopstart = nil, --Ikemen feature | |
67 | + continue_bgm_loopend = nil, --Ikemen feature | |
68 | 68 | continue_end_bgm = 'sound/GAME_OVER.ogg', --Ikemen feature |
69 | - continue_end_volume = 100, --Ikemen feature (not supported yet) | |
70 | - continue_end_loop = 0, --Ikemen feature (not supported yet) | |
71 | - continue_end_loopstart = nil, --Ikemen feature (not supported yet) | |
72 | - continue_end_loopend = nil, --Ikemen feature (not supported yet) | |
69 | + continue_end_bgm_volume = 100, --Ikemen feature | |
70 | + continue_end_bgm_loop = 0, --Ikemen feature | |
71 | + continue_end_bgm_loopstart = nil, --Ikemen feature | |
72 | + continue_end_bgm_loopend = nil, --Ikemen feature | |
73 | 73 | results_bgm = '', --Ikemen feature |
74 | - results_bgm_loop = 1, --Ikemen feature (not supported yet) | |
75 | - results_bgm_loopstart = nil, --Ikemen feature (not supported yet) | |
76 | - results_bgm_loopend = nil, --Ikemen feature (not supported yet) | |
74 | + results_bgm_volume = 100, --Ikemen feature | |
75 | + results_bgm_loop = 1, --Ikemen feature | |
76 | + results_bgm_loopstart = nil, --Ikemen feature | |
77 | + results_bgm_loopend = nil, --Ikemen feature | |
77 | 78 | tournament_bgm = '', --Ikemen feature |
78 | - tournament_bgm_loop = 1, --Ikemen feature (not supported yet) | |
79 | - tournament_bgm_loopstart = nil, --Ikemen feature (not supported yet) | |
80 | - tournament_bgm_loopend = nil, --Ikemen feature (not supported yet) | |
79 | + tournament_bgm_volume = 100, --Ikemen feature | |
80 | + tournament_bgm_loop = 1, --Ikemen feature | |
81 | + tournament_bgm_loopstart = nil, --Ikemen feature | |
82 | + tournament_bgm_loopend = nil, --Ikemen feature | |
81 | 83 | }, |
82 | 84 | title_info = |
83 | 85 | { |
@@ -374,22 +374,33 @@ end | ||
374 | 374 | |
375 | 375 | function select.f_assignMusic() |
376 | 376 | local track = '' |
377 | + local trackVolume = 100 | |
378 | + local tracloopstart,tracloopend = nil | |
377 | 379 | if main.stageMenu then |
378 | 380 | if main.t_selStages[stageNo].music ~= nil then |
379 | 381 | track = math.random(1, #main.t_selStages[stageNo].music) |
382 | + trackVolume = main.t_selStages[stageNo].music[track].bgmvolume | |
383 | + trackloopstart = main.t_selStages[stageNo].music[track].bgmloopstart | |
384 | + trackloopend = main.t_selStages[stageNo].music[track].bgmloopend | |
380 | 385 | track = main.t_selStages[stageNo].music[track].bgmusic |
381 | 386 | end |
382 | 387 | else |
383 | 388 | if main.t_selChars[t_p2Selected[1].cel + 1].music ~= nil then |
384 | 389 | track = math.random(1, #main.t_selChars[t_p2Selected[1].cel + 1].music) |
390 | + trackVolume = main.t_selChars[t_p2Selected[1].cel + 1].music[track].bgmvolume | |
391 | + trackloopstart = main.t_selChars[t_p2Selected[1].cel + 1].music[track].bgmloopstart | |
392 | + trackloopend = main.t_selChars[t_p2Selected[1].cel + 1].music[track].bgmloopend | |
385 | 393 | track = main.t_selChars[t_p2Selected[1].cel + 1].music[track].bgmusic |
386 | 394 | elseif main.t_selStages[stageNo].music ~= nil then |
387 | 395 | track = math.random(1, #main.t_selStages[stageNo].music) |
396 | + trackVolume = main.t_selStages[stageNo].music[track].bgmvolume | |
397 | + trackloopstart = main.t_selStages[stageNo].music[track].bgmloopstart | |
398 | + trackloopend = main.t_selStages[stageNo].music[track].bgmloopend | |
388 | 399 | track = main.t_selStages[stageNo].music[track].bgmusic |
389 | 400 | end |
390 | 401 | stageEnd = true |
391 | 402 | end |
392 | - playBGM(track) | |
403 | + playBGM(track, true, 1, trackVolume, trackloopstart or "0", trackloopend or "0") | |
393 | 404 | end |
394 | 405 | |
395 | 406 | function select.f_selectStage() |
@@ -697,13 +708,13 @@ function select.f_selectSimple() | ||
697 | 708 | stageList = 0 |
698 | 709 | main.f_cmdInput() |
699 | 710 | while true do |
700 | - main.f_resetBG(motif.select_info, motif.selectbgdef, motif.music.select_bgm) | |
711 | + main.f_resetBG(motif.select_info, motif.selectbgdef, motif.music.select_bgm, motif.music.select_bgm_loop, motif.music.select_bgm_volume, motif.music.select_bgm_loopstart, motif.music.select_bgm_loopend) | |
701 | 712 | select.f_selectReset() |
702 | 713 | selectStart() |
703 | 714 | while not selScreenEnd do |
704 | 715 | if esc() then |
705 | 716 | sndPlay(motif.files.snd_data, motif.select_info.cancel_snd[1], motif.select_info.cancel_snd[2]) |
706 | - main.f_resetBG(motif.title_info, motif.titlebgdef, motif.music.title_bgm) | |
717 | + main.f_resetBG(motif.title_info, motif.titlebgdef, motif.music.title_bgm, motif.music.title_bgm_loop, motif.music.title_bgm_volume, motif.music.title_bgm_loopstart, motif.music.title_bgm_loopend) | |
707 | 718 | return |
708 | 719 | end |
709 | 720 | select.f_selectScreen() |
@@ -743,12 +754,12 @@ getSpriteInfo('chars/kfm/kfm.sff', 0, 1) | ||
743 | 754 | select.f_selectReset() |
744 | 755 | stageEnd = true |
745 | 756 | while true do |
746 | - main.f_resetBG(motif.select_info, motif.selectbgdef, motif.music.select_bgm) | |
757 | + main.f_resetBG(motif.select_info, motif.selectbgdef, motif.music.select_bgm, motif.music.select_bgm_loop, motif.music.select_bgm_volume, motif.music.select_bgm_loopstart, motif.music.select_bgm_loopend) | |
747 | 758 | selectStart() |
748 | 759 | while not selScreenEnd do |
749 | 760 | if esc() then |
750 | 761 | sndPlay(motif.files.snd_data, motif.select_info.cancel_snd[1], motif.select_info.cancel_snd[2]) |
751 | - main.f_resetBG(motif.title_info, motif.titlebgdef, motif.music.title_bgm) | |
762 | + main.f_resetBG(motif.title_info, motif.titlebgdef, motif.music.title_bgm, motif.music.title_bgm_loop, motif.music.title_bgm_volume, motif.music.title_bgm_loopstart, motif.music.title_bgm_loopend) | |
752 | 763 | return |
753 | 764 | end |
754 | 765 | select.f_selectScreen() |
@@ -789,7 +800,7 @@ getSpriteInfo('chars/kfm/kfm.sff', 0, 1) | ||
789 | 800 | if motif.files.intro_storyboard ~= '' then |
790 | 801 | storyboard.f_storyboard(motif.files.intro_storyboard) |
791 | 802 | end |
792 | - main.f_resetBG(motif.title_info, motif.titlebgdef, motif.music.title_bgm) | |
803 | + main.f_resetBG(motif.title_info, motif.titlebgdef, motif.music.title_bgm, motif.music.title_bgm_loop, motif.music.title_bgm_volume, motif.music.title_bgm_loopstart, motif.music.title_bgm_loopend) | |
793 | 804 | return |
794 | 805 | --player won (also if lost in VS 100 Kumite) |
795 | 806 | elseif winner == 1 or main.gameMode == '100kumite' then |
@@ -830,7 +841,7 @@ getSpriteInfo('chars/kfm/kfm.sff', 0, 1) | ||
830 | 841 | if motif.files.intro_storyboard ~= '' then |
831 | 842 | storyboard.f_storyboard(motif.files.intro_storyboard) |
832 | 843 | end |
833 | - main.f_resetBG(motif.title_info, motif.titlebgdef, motif.music.title_bgm) | |
844 | + main.f_resetBG(motif.title_info, motif.titlebgdef, motif.music.title_bgm, motif.music.title_bgm_loop, motif.music.title_bgm_volume, motif.music.title_bgm_loopstart, motif.music.title_bgm_loopend) | |
834 | 845 | return |
835 | 846 | --next match available |
836 | 847 | else |
@@ -856,7 +867,7 @@ getSpriteInfo('chars/kfm/kfm.sff', 0, 1) | ||
856 | 867 | if motif.files.intro_storyboard ~= '' then |
857 | 868 | storyboard.f_storyboard(motif.files.intro_storyboard) |
858 | 869 | end |
859 | - main.f_resetBG(motif.title_info, motif.titlebgdef, motif.music.title_bgm) | |
870 | + main.f_resetBG(motif.title_info, motif.titlebgdef, motif.music.title_bgm, motif.music.title_bgm_loop, motif.music.title_bgm_volume, motif.music.title_bgm_loopstart, motif.music.title_bgm_loopend) | |
860 | 871 | return |
861 | 872 | --player lost but can continue |
862 | 873 | else |
@@ -877,7 +888,7 @@ getSpriteInfo('chars/kfm/kfm.sff', 0, 1) | ||
877 | 888 | if motif.files.intro_storyboard ~= '' then |
878 | 889 | storyboard.f_storyboard(motif.files.intro_storyboard) |
879 | 890 | end |
880 | - main.f_resetBG(motif.title_info, motif.titlebgdef, motif.music.title_bgm) | |
891 | + main.f_resetBG(motif.title_info, motif.titlebgdef, motif.music.title_bgm, motif.music.title_bgm_loop, motif.music.title_bgm_volume, motif.music.title_bgm_loopstart, motif.music.title_bgm_loopend) | |
881 | 892 | return |
882 | 893 | end |
883 | 894 | if config.ContSelection then --true if 'Char change at Continue' option is enabled |
@@ -894,14 +905,14 @@ getSpriteInfo('chars/kfm/kfm.sff', 0, 1) | ||
894 | 905 | while not selScreenEnd do |
895 | 906 | if esc() then |
896 | 907 | sndPlay(motif.files.snd_data, motif.select_info.cancel_snd[1], motif.select_info.cancel_snd[2]) |
897 | - main.f_resetBG(motif.title_info, motif.titlebgdef, motif.music.title_bgm) | |
908 | + main.f_resetBG(motif.title_info, motif.titlebgdef, motif.music.title_bgm, motif.music.title_bgm_loop, motif.music.title_bgm_volume, motif.music.title_bgm_loopstart, motif.music.title_bgm_loopend) | |
898 | 909 | return |
899 | 910 | end |
900 | 911 | select.f_selectScreen() |
901 | 912 | end |
902 | 913 | elseif esc() then |
903 | 914 | sndPlay(motif.files.snd_data, motif.select_info.cancel_snd[1], motif.select_info.cancel_snd[2]) |
904 | - main.f_resetBG(motif.title_info, motif.titlebgdef, motif.music.title_bgm) | |
915 | + main.f_resetBG(motif.title_info, motif.titlebgdef, motif.music.title_bgm, motif.music.title_bgm_loop, motif.music.title_bgm_volume, motif.music.title_bgm_loopstart, motif.music.title_bgm_loopend) | |
905 | 916 | return |
906 | 917 | end |
907 | 918 | end |
@@ -992,12 +1003,12 @@ function select.f_selectTournament() | ||
992 | 1003 | stageList = 0 |
993 | 1004 | main.f_cmdInput() |
994 | 1005 | while true do |
995 | - main.f_resetBG(motif.tournament_info, motif.tournamentbgdef, motif.music.tournament_bgm) | |
1006 | + main.f_resetBG(motif.tournament_info, motif.tournamentbgdef, motif.music.tournament_bgm, motif.music.tournament_bgm_loop, motif.music.tournament_bgm_volume, motif.music.tournament_bgm_loopstart, motif.music.tournament_bgm_loopend) | |
996 | 1007 | select.f_selectReset() |
997 | 1008 | while not selScreenEnd do |
998 | 1009 | if esc() then |
999 | 1010 | sndPlay(motif.files.snd_data, motif.select_info.cancel_snd[1], motif.select_info.cancel_snd[2]) |
1000 | - main.f_resetBG(motif.title_info, motif.titlebgdef, motif.music.title_bgm) | |
1011 | + main.f_resetBG(motif.title_info, motif.titlebgdef, motif.music.title_bgm, motif.music.title_bgm_loop, motif.music.title_bgm_volume, motif.music.title_bgm_loopstart, motif.music.title_bgm_loopend) | |
1001 | 1012 | return |
1002 | 1013 | end |
1003 | 1014 | select.f_selectTournamentScreen() |
@@ -1992,7 +2003,7 @@ function select.f_selectVersus() | ||
1992 | 2003 | textImgSetText(txt_matchNo, text[1]) |
1993 | 2004 | local delay = 0 |
1994 | 2005 | local minTime = 15 --let's reserve few extra ticks in case selectChar function needs time to load data, also prevents sound from being interrupted |
1995 | - main.f_resetBG(motif.vs_screen, motif.versusbgdef, motif.music.vs_bgm) | |
2006 | + main.f_resetBG(motif.vs_screen, motif.versusbgdef, motif.music.vs_bgm, motif.music.vs_bgm_loop, motif.music.vs_bgm_volume, motif.music.vs_bgm_loopstart, motif.music.vs_bgm_loopend) | |
1996 | 2007 | if not main.versusScreen then |
1997 | 2008 | delay = minTime |
1998 | 2009 | select.f_selectChar(1, t_p1Selected) |
@@ -2038,7 +2049,7 @@ function select.f_selectVersus() | ||
2038 | 2049 | while true do |
2039 | 2050 | if esc() then |
2040 | 2051 | sndPlay(motif.files.snd_data, motif.select_info.cancel_snd[1], motif.select_info.cancel_snd[2]) |
2041 | - main.f_resetBG(motif.title_info, motif.titlebgdef, motif.music.title_bgm) | |
2052 | + main.f_resetBG(motif.title_info, motif.titlebgdef, motif.music.title_bgm, motif.music.title_bgm_loop, motif.music.title_bgm_volume, motif.music.title_bgm_loopstart, motif.music.title_bgm_loopend) | |
2042 | 2053 | break |
2043 | 2054 | elseif p1Confirmed and p2Confirmed then |
2044 | 2055 | if orderTime == -1 and main.f_btnPalNo(main.p1Cmd) > 0 and delay > motif.versusbgdef.timer + minTime then |
@@ -2309,15 +2320,15 @@ function select.f_result(state) | ||
2309 | 2320 | else |
2310 | 2321 | return |
2311 | 2322 | end |
2312 | - main.f_resetBG(t, motif.resultsbgdef, motif.music.results_bgm) | |
2323 | + main.f_resetBG(t, motif.resultsbgdef, motif.music.results_bgm, motif.music.results_bgm_loop, motif.music.results_bgm_volume, motif.music.results_bgm_loopstart, motif.music.results_bgm_loopend) | |
2313 | 2324 | main.f_cmdInput() |
2314 | 2325 | while true do |
2315 | 2326 | if esc() or main.f_btnPalNo(main.p1Cmd) > 0 then |
2316 | - main.f_resetBG(motif.title_info, motif.titlebgdef, motif.music.title_bgm) | |
2327 | + main.f_resetBG(motif.title_info, motif.titlebgdef, motif.music.title_bgm, motif.music.title_bgm_loop, motif.music.title_bgm_volume, motif.music.title_bgm_loopstart, motif.music.title_bgm_loopend) | |
2317 | 2328 | break |
2318 | 2329 | elseif motif.resultsbgdef.timer >= t.show_time then |
2319 | 2330 | --add fadeout code here |
2320 | - main.f_resetBG(motif.title_info, motif.titlebgdef, motif.music.title_bgm) | |
2331 | + main.f_resetBG(motif.title_info, motif.titlebgdef, motif.music.title_bgm, motif.music.title_bgm_loop, motif.music.title_bgm_volume, motif.music.title_bgm_loopstart, motif.music.title_bgm_loopend) | |
2321 | 2332 | break |
2322 | 2333 | end |
2323 | 2334 | --draw clearcolor |
@@ -2394,7 +2405,7 @@ function select.f_selectVictory() | ||
2394 | 2405 | if motif.music.victory_bgm == '' then |
2395 | 2406 | main.f_resetBG(motif.victory_screen, motif.victorybgdef) |
2396 | 2407 | else |
2397 | - main.f_resetBG(motif.victory_screen, motif.victorybgdef, motif.music.victory_bgm) | |
2408 | + main.f_resetBG(motif.victory_screen, motif.victorybgdef, motif.music.victory_bgm, motif.music.victory_bgm_loop, motif.music.victory_bgm_volume, motif.music.victory_bgm_loopstart, motif.music.victory_bgm_loopend) | |
2398 | 2409 | end |
2399 | 2410 | local winquote = '' |
2400 | 2411 | local winnerNum = 0 |
@@ -2503,7 +2514,7 @@ local txt_credits = main.f_createTextImg( | ||
2503 | 2514 | ) |
2504 | 2515 | |
2505 | 2516 | function select.f_continue() |
2506 | - main.f_resetBG(motif.continue_screen, motif.continuebgdef, motif.music.continue_bgm) | |
2517 | + 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) | |
2507 | 2518 | animReset(motif.continue_screen.continue_anim_data) |
2508 | 2519 | animUpdate(motif.continue_screen.continue_anim_data) |
2509 | 2520 | continue = false |
@@ -2526,7 +2537,7 @@ function select.f_continue() | ||
2526 | 2537 | text = main.f_extractText(motif.continue_screen.credits_text, main.credits) |
2527 | 2538 | textImgSetText(txt_credits, text[1]) |
2528 | 2539 | main.f_cmdInput() |
2529 | - main.f_resetBG(motif.select_info, motif.selectbgdef, motif.music.select_bgm) | |
2540 | + main.f_resetBG(motif.select_info, motif.selectbgdef, motif.music.select_bgm, motif.music.select_bgm_loop, motif.music.select_bgm_volume, motif.music.select_bgm_loopstart, motif.music.select_bgm_loopend) | |
2530 | 2541 | break |
2531 | 2542 | elseif main.f_btnPalNo(main.p1Cmd) > 0 and motif.continuebgdef.timer >= motif.continue_screen.continue_starttime + motif.continue_screen.continue_skipstart then |
2532 | 2543 | local cnt = 0 |
@@ -2578,7 +2589,7 @@ function select.f_continue() | ||
2578 | 2589 | sndPlay(motif.files.continue_snd_data, motif.continue_screen.continue_0_snd[1], motif.continue_screen.continue_0_snd[2]) |
2579 | 2590 | end |
2580 | 2591 | elseif motif.continuebgdef.timer == motif.continue_screen.continue_end_skiptime then |
2581 | - playBGM(motif.music.continue_end_bgm) | |
2592 | + playBGM(motif.music.continue_end_bgm, true, motif.music.continue_end_loop, motif.music.continue_end_volume, motif.music.continue_end_loopstart or "0", motif.music.continue_end_loopend or "0") | |
2582 | 2593 | sndPlay(motif.files.continue_snd_data, motif.continue_screen.continue_end_snd[1], motif.continue_screen.continue_end_snd[2]) |
2583 | 2594 | end |
2584 | 2595 | --draw credits text |
@@ -61,7 +61,7 @@ local function f_play(t) | ||
61 | 61 | end |
62 | 62 | --play bgm |
63 | 63 | if i == 0 and t.scene[k].bgm ~= nil then |
64 | - playBGM(t.scene[k].bgm) | |
64 | + playBGM(t.scene[k].bgm, true, t.scene[k].bgm_loop, t.scene[k].bgm_volume, t.scene[k].bgm_loopstart or "0", t.scene[k].bgm_loopend or "0") | |
65 | 65 | end |
66 | 66 | --play snd |
67 | 67 | if t.scenedef.snd_data ~= nil then |
@@ -92,10 +92,10 @@ local function f_play(t) | ||
92 | 92 | t.scene[k].layer[k2].text_data, |
93 | 93 | t.scene[k].layer[k2].text, |
94 | 94 | t.scene[k].layer[k2].text_timer, |
95 | - t.scene[k].layerall_pos[1] + t_layer[k2].offset[1], | |
96 | - t.scene[k].layerall_pos[2] + t_layer[k2].offset[2], | |
97 | - t.scene[k].layer[k2].text_spacing, | |
98 | - t.scene[k].layer[k2].text_delay, | |
95 | + t.scene[k].layerall_pos[1] + t.scene[k].layer[k2].offset[1], | |
96 | + t.scene[k].layerall_pos[2] + t.scene[k].layer[k2].offset[2], | |
97 | + t.scene[k].layer[k2].text_spacing[2], | |
98 | + t.scene[k].layer[k2].textdelay, | |
99 | 99 | t.scene[k].layer[k2].text_length |
100 | 100 | ) |
101 | 101 | end |
@@ -120,7 +120,7 @@ local function f_play(t) | ||
120 | 120 | end |
121 | 121 | end |
122 | 122 | end |
123 | - playBGM('') | |
123 | + playBGM('', true, 1, 100, "0", "0") | |
124 | 124 | end |
125 | 125 | |
126 | 126 | local function f_parse(path) |
@@ -238,6 +238,9 @@ local function f_parse(path) | ||
238 | 238 | sound = {}, |
239 | 239 | --bgm = '', |
240 | 240 | bgm_loop = 0, |
241 | + bgm_volume = 100, | |
242 | + bgm_loopstart = nil, | |
243 | + bgm_loopend = nil, | |
241 | 244 | --window = {0, 0, 0, 0}, |
242 | 245 | bg_name = '' |
243 | 246 | } |
@@ -281,9 +284,9 @@ local function f_parse(path) | ||
281 | 284 | { |
282 | 285 | anim = -1, |
283 | 286 | text = '', |
284 | - font = {1, 0, 1, nil, nil, nil}, | |
287 | + font = {1, 0, 0, nil, nil, nil}, | |
285 | 288 | text_spacing = {0, 15}, --Ikemen feature |
286 | - text_delay = 2, --Ikemen feature | |
289 | + textdelay = 2, | |
287 | 290 | text_length = 50, --Ikemen feature |
288 | 291 | text_timer = 0, --Ikemen feature |
289 | 292 | offset = {0, 0}, |
@@ -396,8 +399,12 @@ local function f_parse(path) | ||
396 | 399 | elseif main.f_fileExists('font/' .. t.scenedef.font[k]) then |
397 | 400 | t.scenedef.font[k] = 'font/' .. t.scenedef.font[k] |
398 | 401 | end |
402 | + t.scenedef.font_data[k] = fontNew(t.scenedef.font[k]) | |
403 | + t.scenedef.font[k] = {} | |
404 | + t.scenedef.font[k][1] = k | |
405 | + t.scenedef.font[k][2] = 0 | |
406 | + t.scenedef.font[k][3] = 0 | |
399 | 407 | end |
400 | - t.scenedef.font_data[k] = fontNew(t.scenedef.font[k]) | |
401 | 408 | end |
402 | 409 | end |
403 | 410 | --loop through scenes |
@@ -435,7 +442,7 @@ local function f_parse(path) | ||
435 | 442 | local t_bgdef = t[t.scene[k].bg_name .. 'def'] |
436 | 443 | local prev_k2 = '' |
437 | 444 | for k2, v2 in pairs(t_bgdef) do --loop through table keys |
438 | - if t_bgdef[k2].type ~= nil then | |
445 | + if type(k2) == "number" and t_bgdef[k2].type ~= nil then | |
439 | 446 | t_bgdef[k2].type = t_bgdef[k2].type:lower() |
440 | 447 | --mugen ignores delta = 0 (defaults to 1) |
441 | 448 | if t_bgdef[k2].delta[1] == 0 then t_bgdef[k2].delta[1] = 1 end |
@@ -520,17 +527,17 @@ local function f_parse(path) | ||
520 | 527 | --text |
521 | 528 | if t_layer[k2].text ~= '' then |
522 | 529 | t.scene[k].layer[k2].text_data = main.f_createTextImg( |
523 | - t.scenedef.font_data[t.scenedef.font[t_layer[k2].font][1]], | |
524 | - t.scenedef.font[t_layer[k2].font][2], | |
525 | - t.scenedef.font[t_layer[k2].font][3], | |
530 | + t.scenedef.font_data[t.scenedef.font[t_layer[k2].font[1]][1]], | |
531 | + t_layer[k2].font[2], | |
532 | + t_layer[k2].font[3], | |
526 | 533 | t_layer[k2].text, |
527 | 534 | t.scene[k].layerall_pos[1] + t_layer[k2].offset[1], |
528 | 535 | t.scene[k].layerall_pos[2] + t_layer[k2].offset[2], |
529 | 536 | 320/t.info.localcoord[1], |
530 | 537 | 240/t.info.localcoord[2], |
531 | - t.scenedef.font[t_layer[k2].font][4], | |
532 | - t.scenedef.font[t_layer[k2].font][5], | |
533 | - t.scenedef.font[t_layer[k2].font][6] | |
538 | + t_layer[k2].font[4], | |
539 | + t_layer[k2].font[5], | |
540 | + t_layer[k2].font[6] | |
534 | 541 | ) |
535 | 542 | end |
536 | 543 | --endtime |
@@ -201,7 +201,7 @@ func scriptCommonInit(l *lua.LState) { | ||
201 | 201 | return 0 |
202 | 202 | }) |
203 | 203 | luaRegister(l, "playBGM", func(l *lua.LState) int { |
204 | - sys.bgm.Open(strArg(l, 1)) | |
204 | + sys.bgm.Open(strArg(l, 1), boolArg(l, 2), int(numArg(l, 3)), int(numArg(l, 4)), int(Atoi(strArg(l, 5))), int(Atoi(strArg(l, 6)))) | |
205 | 205 | return 0 |
206 | 206 | }) |
207 | 207 | luaRegister(l, "esc", func(l *lua.LState) int { |
@@ -1203,12 +1203,14 @@ func systemScriptInit(l *lua.LState) { | ||
1203 | 1203 | return 1 |
1204 | 1204 | }) |
1205 | 1205 | luaRegister(l, "getStageInfo", func(*lua.LState) int { |
1206 | - a, b, c, d := sys.sel.GetStageInfo(int(numArg(l, 1))) | |
1206 | + a, b, c, d, e, f := sys.sel.GetStageInfo(int(numArg(l, 1))) | |
1207 | 1207 | l.Push(lua.LString(a)) |
1208 | 1208 | l.Push(lua.LString(b)) |
1209 | 1209 | l.Push(lua.LString(c)) |
1210 | 1210 | l.Push(lua.LString(d)) |
1211 | - return 4 | |
1211 | + l.Push(lua.LString(e)) | |
1212 | + l.Push(lua.LString(f)) | |
1213 | + return 6 | |
1212 | 1214 | }) |
1213 | 1215 | luaRegister(l, "getKey", func(*lua.LState) int { |
1214 | 1216 | s := "" |
@@ -236,8 +236,18 @@ func (n *NormalizerLR) process(bai float64, sam *float32) float64 { | ||
236 | 236 | // Bgm |
237 | 237 | |
238 | 238 | type Bgm struct { |
239 | - filename string | |
240 | - ctrl *beep.Ctrl | |
239 | + filename string | |
240 | + bgmLoopStart int | |
241 | + bgmLoopEnd int | |
242 | + defaultFilename string | |
243 | + defaultBgmVolume int | |
244 | + defaultbgmLoopStart int | |
245 | + defaultbgmLoopEnd int | |
246 | + sampleRate beep.SampleRate | |
247 | + streamer beep.StreamSeekCloser | |
248 | + ctrl *beep.Ctrl | |
249 | + resampler *beep.Resampler | |
250 | + volume *effects.Volume | |
241 | 251 | } |
242 | 252 | |
243 | 253 | func newBgm() *Bgm { |
@@ -260,58 +270,71 @@ func (bgm *Bgm) IsFormat(extension string) bool { | ||
260 | 270 | return filepath.Ext(bgm.filename) == extension |
261 | 271 | } |
262 | 272 | |
263 | -func (bgm *Bgm) Open(filename string) { | |
264 | - | |
273 | +func (bgm *Bgm) Open(filename string, isDefaultBGM bool, loop, bgmVolume, bgmLoopStart, bgmLoopEnd int) { | |
265 | 274 | if filepath.Base(bgm.filename) == filepath.Base(filename) { |
266 | 275 | return |
267 | 276 | } |
268 | - | |
269 | 277 | bgm.filename = filename |
278 | + bgm.bgmLoopStart = bgmLoopStart | |
279 | + bgm.bgmLoopEnd = bgmLoopEnd | |
280 | + if isDefaultBGM { | |
281 | + bgm.defaultFilename = filename | |
282 | + bgm.defaultBgmVolume = bgmVolume | |
283 | + bgm.defaultbgmLoopStart = bgmLoopStart | |
284 | + bgm.defaultbgmLoopEnd = bgmLoopEnd | |
285 | + } | |
270 | 286 | speaker.Clear() |
271 | 287 | |
272 | 288 | if bgm.IsVorbis() { |
273 | - bgm.ReadVorbis() | |
289 | + bgm.ReadVorbis(loop, bgmVolume) | |
274 | 290 | } else if bgm.IsMp3() { |
275 | - bgm.ReadMp3() | |
291 | + bgm.ReadMp3(loop, bgmVolume) | |
276 | 292 | } else if bgm.IsFLAC() { |
277 | - bgm.ReadFLAC() | |
293 | + bgm.ReadFLAC(loop, bgmVolume) | |
278 | 294 | } |
279 | 295 | |
280 | 296 | } |
281 | 297 | |
282 | -func (bgm *Bgm) ReadMp3() { | |
298 | +func (bgm *Bgm) ReadMp3(loop int, bgmVolume int) { | |
283 | 299 | f, _ := os.Open(bgm.filename) |
284 | 300 | s, format, err := mp3.Decode(f) |
301 | + bgm.streamer = s | |
285 | 302 | if err != nil { |
286 | 303 | return |
287 | 304 | } |
288 | - bgm.ReadFormat(s, format) | |
305 | + bgm.ReadFormat(format, loop, bgmVolume) | |
289 | 306 | } |
290 | 307 | |
291 | -func (bgm *Bgm) ReadFLAC() { | |
308 | +func (bgm *Bgm) ReadFLAC(loop int, bgmVolume int) { | |
292 | 309 | f, _ := os.Open(bgm.filename) |
293 | 310 | s, format, err := flac.Decode(f) |
311 | + bgm.streamer = s | |
294 | 312 | if err != nil { |
295 | 313 | return |
296 | 314 | } |
297 | - bgm.ReadFormat(s, format) | |
315 | + bgm.ReadFormat(format, loop, bgmVolume) | |
298 | 316 | } |
299 | 317 | |
300 | -func (bgm *Bgm) ReadVorbis() { | |
318 | +func (bgm *Bgm) ReadVorbis(loop int, bgmVolume int) { | |
301 | 319 | f, _ := os.Open(bgm.filename) |
302 | 320 | s, format, err := vorbis.Decode(f) |
321 | + bgm.streamer = s | |
303 | 322 | if err != nil { |
304 | 323 | return |
305 | 324 | } |
306 | - bgm.ReadFormat(s, format) | |
325 | + bgm.ReadFormat(format, loop, bgmVolume) | |
307 | 326 | } |
308 | 327 | |
309 | -func (bgm *Bgm) ReadFormat(s beep.StreamSeekCloser, format beep.Format) { | |
310 | - streamer := beep.Loop(-1, s) | |
311 | - volume := -5 + float64(sys.bgmVolume)*0.06*(float64(sys.masterVolume)/100) | |
312 | - streamer = &effects.Volume{Streamer: streamer, Base: 2, Volume: volume, Silent: volume <= -5} | |
313 | - resample := beep.Resample(int(3), format.SampleRate, beep.SampleRate(Mp3SampleRate), streamer) | |
314 | - bgm.ctrl = &beep.Ctrl{Streamer: resample} | |
328 | +func (bgm *Bgm) ReadFormat(format beep.Format, loop int, bgmVolume int) { | |
329 | + loopCount := int(1) | |
330 | + if loop > 0 { | |
331 | + loopCount = -1 | |
332 | + } | |
333 | + streamer := beep.Loop(loopCount, bgm.streamer) | |
334 | + volume := -5 + float64(sys.bgmVolume)*0.06*(float64(sys.masterVolume)/100)*(float64(bgmVolume)/100) | |
335 | + bgm.volume = &effects.Volume{Streamer: streamer, Base: 2, Volume: volume, Silent: volume <= -5} | |
336 | + bgm.resampler = beep.Resample(int(3), format.SampleRate, beep.SampleRate(Mp3SampleRate), bgm.volume) | |
337 | + bgm.ctrl = &beep.Ctrl{Streamer: bgm.resampler} | |
315 | 338 | speaker.Play(bgm.ctrl) |
316 | 339 | } |
317 | 340 |
@@ -406,15 +406,11 @@ func (s *System) audioOpen() { | ||
406 | 406 | func (s *System) soundWrite() { |
407 | 407 | defer func() { s.audioClose <- true }() |
408 | 408 | src := NewAudioSource() |
409 | - bgmSrc := NewAudioSource() | |
410 | 409 | processed := false |
411 | 410 | for !s.gameEnd { |
412 | 411 | if src.Src.State() != openal.Playing { |
413 | 412 | src.Src.Play() |
414 | 413 | } |
415 | - if bgmSrc.Src.State() != openal.Playing { | |
416 | - bgmSrc.Src.Play() | |
417 | - } | |
418 | 414 | if !processed { |
419 | 415 | time.Sleep(10 * time.Millisecond) |
420 | 416 | } |
@@ -434,27 +430,20 @@ func (s *System) soundWrite() { | ||
434 | 430 | } |
435 | 431 | processed = true |
436 | 432 | } |
437 | - if bgmSrc.Src.BuffersProcessed() > 0 { | |
438 | - out := s.nullSndBuf[:] | |
439 | - if !s.nomusic { | |
440 | - if s.bgm.ctrl != nil { | |
441 | - s.bgm.ctrl.Paused = false | |
442 | - } | |
443 | - } else { | |
444 | - if s.bgm.ctrl != nil { | |
445 | - s.bgm.Pause() | |
433 | + if !s.nomusic { | |
434 | + if s.bgm.ctrl != nil { | |
435 | + s.bgm.ctrl.Paused = false | |
436 | + if s.bgm.bgmLoopEnd > 0 && s.bgm.streamer.Position() >= s.bgm.bgmLoopEnd { | |
437 | + s.bgm.streamer.Seek(s.bgm.bgmLoopStart) | |
446 | 438 | } |
447 | 439 | } |
448 | - buf := bgmSrc.Src.UnqueueBuffer() | |
449 | - buf.SetDataInt16(openal.FormatStereo16, out, audioFrequency) | |
450 | - bgmSrc.Src.QueueBuffer(buf) | |
451 | - if err := openal.Err(); err != nil { | |
452 | - s.errLog.Println(err.Error()) | |
440 | + } else { | |
441 | + if s.bgm.ctrl != nil { | |
442 | + s.bgm.Pause() | |
453 | 443 | } |
454 | - processed = true | |
455 | 444 | } |
445 | + | |
456 | 446 | } |
457 | - bgmSrc.Delete() | |
458 | 447 | src.Delete() |
459 | 448 | openal.NullContext.Activate() |
460 | 449 | device := s.audioContext.GetDevice() |
@@ -1748,7 +1737,7 @@ type SelectChar struct { | ||
1748 | 1737 | sportrait, lportrait, vsportrait, vportrait *Sprite |
1749 | 1738 | } |
1750 | 1739 | type SelectStage struct { |
1751 | - def, name, zoomout, zoomin, bgmusic, bgmvolume string | |
1740 | + def, name, zoomout, zoomin, bgmusic, bgmvolume, bgmloopstart, bgmloopend string | |
1752 | 1741 | } |
1753 | 1742 | type Select struct { |
1754 | 1743 | columns, rows int |
@@ -1810,12 +1799,12 @@ func (s *Select) GetStageName(n int) string { | ||
1810 | 1799 | } |
1811 | 1800 | return s.stagelist[n-1].name |
1812 | 1801 | } |
1813 | -func (s *Select) GetStageInfo(n int) (zoomin, zoomout, bgmusic, bgmvolume string) { | |
1802 | +func (s *Select) GetStageInfo(n int) (zoomin, zoomout, bgmusic, bgmvolume, bgmloopstart, bgmloopend string) { | |
1814 | 1803 | n %= len(s.stagelist) + 1 |
1815 | 1804 | if n < 0 { |
1816 | 1805 | n += len(s.stagelist) + 1 |
1817 | 1806 | } |
1818 | - return s.stagelist[n-1].zoomin, s.stagelist[n-1].zoomout, s.stagelist[n-1].bgmusic, s.stagelist[n-1].bgmvolume | |
1807 | + return s.stagelist[n-1].zoomin, s.stagelist[n-1].zoomout, s.stagelist[n-1].bgmusic, s.stagelist[n-1].bgmvolume, s.stagelist[n-1].bgmloopstart, s.stagelist[n-1].bgmloopend | |
1819 | 1808 | } |
1820 | 1809 | func (s *Select) addCahr(def string) { |
1821 | 1810 | s.charlist = append(s.charlist, SelectChar{}) |
@@ -1968,6 +1957,14 @@ func (s *Select) AddStage(def string) error { | ||
1968 | 1957 | if !ok { |
1969 | 1958 | ss.bgmvolume = "100" |
1970 | 1959 | } |
1960 | + ss.bgmloopstart, ok = is.getString("bgmloopstart") | |
1961 | + if !ok { | |
1962 | + ss.bgmloopstart = "" | |
1963 | + } | |
1964 | + ss.bgmloopend, ok = is.getString("bgmloopend") | |
1965 | + if !ok { | |
1966 | + ss.bgmloopend = "" | |
1967 | + } | |
1971 | 1968 | } |
1972 | 1969 | } |
1973 | 1970 | } |