diff --git a/funcs.lua b/funcs.lua index 5a1d69f..6342986 100644 --- a/funcs.lua +++ b/funcs.lua @@ -107,7 +107,7 @@ function table.lowest(table) return lowest end -function clamp(x, min, max) +function math.clamp(x, min, max) if max < min then min, max = max, min end @@ -116,7 +116,7 @@ end function drawText(text, x, y, size, orientation, color) if color == nil then color = {1, 1, 1, 1} end - love.graphics.setFont(tromi_font) + love.graphics.setFont(FONT_tromi) love.graphics.setColor(0, 0, 0, 0.8) love.graphics.printf(text, x+1, y+1, size*2, orientation, nil, 0.50) love.graphics.setColor(color) @@ -125,7 +125,7 @@ end function drawBigText(text, x, y, size, orientation, color) if color == nil then color = {1, 1, 1, 1} end - love.graphics.setFont(big_font) + love.graphics.setFont(FONT_big) love.graphics.setColor(0, 0, 0, 0.8) love.graphics.printf(text, x+1, y+1, size*2, orientation, nil, 0.50) love.graphics.setColor(color) diff --git a/game/gamemode.lua b/game/gamemode.lua index d3d7f78..971893d 100644 --- a/game/gamemode.lua +++ b/game/gamemode.lua @@ -3,7 +3,7 @@ local bit = require("bit") local lualzw = require 'libs.lualzw' local bitser = require 'libs.bitser' require 'funcs' -require 'load.save' +require 'settings' local playedReadySE = false local playedGoSE = false @@ -84,8 +84,8 @@ function GameMode:new(player_name, input_file, replay_grade) self.speed_divisor = 10000 self.line_clear_flash = 0 self.lines_cleared = 0 - sounds['bgm_firsthalf']:setVolume(0.3) - sounds['bgm_secondhalf']:setVolume(0.35) + SOUNDS['bgm_firsthalf']:setVolume(0.3) + SOUNDS['bgm_secondhalf']:setVolume(0.35) self.audio_stopped = false self.recorded_inputs = {} self.input_saved = false @@ -373,7 +373,7 @@ function GameMode:update(inputs, ruleset) if self.grade_change_flash > 0 and self.game_over_frames >= 2 then self.grade_change_flash = self.grade_change_flash - 1 end if self.point_flash > 0 and self.game_over_frames >= 2 then self.point_flash = self.point_flash - 1 end if self.game_over_frames == 2 then - playSEOnce(self.end_game_sound) + PlaySEOnce(self.end_game_sound) end if self.game_over or self.completed then self.game_over_frames = self.game_over_frames + 1 @@ -500,7 +500,7 @@ function GameMode:update(inputs, ruleset) --if spin < 0 then spin = 0 end self.spin_rng[i] = spin end - playSE("erase") + PlaySE("erase") self.lcd = self:getLineClearDelay() self.last_lcd = self.lcd self.are = self:getLineARE() @@ -613,28 +613,28 @@ end function GameMode:advanceOneFrame() if self.ready_frames ~= 0 and not self.audio_stopped and not self.training then - if sounds['bgm_title']:getVolume() > 0.01 then sounds['bgm_title']:setVolume(sounds['bgm_title']:getVolume()-0.01) end + if SOUNDS['bgm_title']:getVolume() > 0.01 then SOUNDS['bgm_title']:setVolume(SOUNDS['bgm_title']:getVolume()-0.01) end if self.ready_frames == 5 then love.audio.stop() self.audio_stopped = true end end - if self.training and not sounds['bgm_title']:isPlaying() and config["music"] then sounds['bgm_title']:play() end + if self.training and not SOUNDS['bgm_title']:isPlaying() and SETTINGS["music"] then SOUNDS['bgm_title']:play() end if not self.training then - if self.nextbgmflag and sounds['bgm_firsthalf']:isPlaying() then - if sounds['bgm_firsthalf']:getVolume() > 0.1 then - sounds['bgm_firsthalf']:setVolume(sounds['bgm_firsthalf']:getVolume()-0.01) + if self.nextbgmflag and SOUNDS['bgm_firsthalf']:isPlaying() then + if SOUNDS['bgm_firsthalf']:getVolume() > 0.1 then + SOUNDS['bgm_firsthalf']:setVolume(SOUNDS['bgm_firsthalf']:getVolume()-0.01) else - sounds['bgm_firsthalf']:stop() + SOUNDS['bgm_firsthalf']:stop() end end - if self.ready_frames < 1 and not sounds['bgm_firsthalf']:isPlaying() and not sounds['bgm_secondhalf']:isPlaying() and config["music"] then - if not self.nextbgmflag then sounds['bgm_firsthalf']:play() - elseif self.total_lines < 296 then sounds['bgm_secondhalf']:play() end + if self.ready_frames < 1 and not SOUNDS['bgm_firsthalf']:isPlaying() and not SOUNDS['bgm_secondhalf']:isPlaying() and SETTINGS["music"] then + if not self.nextbgmflag then SOUNDS['bgm_firsthalf']:play() + elseif self.total_lines < 296 then SOUNDS['bgm_secondhalf']:play() end end if self.total_lines >= 296 then - sounds['bgm_firsthalf']:stop() - sounds['bgm_secondhalf']:stop() + SOUNDS['bgm_firsthalf']:stop() + SOUNDS['bgm_secondhalf']:stop() end end if self.clear then @@ -688,7 +688,7 @@ function GameMode:onPieceLock(piece, cleared_row_count) self.moved = true end self.lastdir = 0 - playSE("lock") + PlaySE("lock") end function GameMode:onLineClear(cleared_row_count) @@ -810,7 +810,7 @@ function GameMode:processDelays(inputs, ruleset, drop_speed) if self.ready_frames > 0 then if not playedReadySE then playedReadySE = true - playSEOnce("ready") + PlaySEOnce("ready") end self.ready_frames = self.ready_frames - 1 if self.ready_frames == 0 then @@ -822,7 +822,7 @@ function GameMode:processDelays(inputs, ruleset, drop_speed) local cleared_row_count = self.grid:getClearedRowCount() self.grid:clearClearedRows() self:afterLineClear(cleared_row_count) - playSE("fall") + PlaySE("fall") if self.are == 0 then self:initializeOrHold(inputs, ruleset) end @@ -861,7 +861,7 @@ function GameMode:initializeNextPiece(inputs, ruleset, piece_data, generate_next self.piece_soft_locked = false if self.piece:isDropBlocked(self.grid) and self.grid:canPlacePiece(self.piece) then - playSE("bottom") + PlaySE("bottom") end if generate_next_piece == nil then table.remove(self.next_queue, 1) @@ -893,10 +893,10 @@ function GameMode:drawLineClearAnimation() fall_timer = (fall_timer*fall_timer)+drift fade_timer = self.lcd/20 love.graphics.setColor(1,1,1,fade_timer) - love.graphics.draw(blocks[block.skin][block.colour..'_d'], real_x, real_y+fall_timer) + love.graphics.draw(BLOCKS[block.skin][block.colour..'_d'], real_x, real_y+fall_timer) if self.lcd > self:getLineClearDelay() - 5 then love.graphics.setColor(1,1,1,fade_timer*0.3) - love.graphics.draw(blocks[block.skin]['W'], real_x, real_y+fall_timer) + love.graphics.draw(BLOCKS[block.skin]['W'], real_x, real_y+fall_timer) end end end @@ -917,7 +917,7 @@ function GameMode:drawNextQueue(ruleset) for index, offset in pairs(offsets) do local x = offset.x + ruleset:getDrawOffset(piece, rotation).x + ruleset.spawn_positions[piece].x local y = offset.y + ruleset:getDrawOffset(piece, rotation).y + 4.7 - love.graphics.draw(blocks[skin][ColourSchemes.Arika[piece]], pos_x+x*16, pos_y+y*16) + love.graphics.draw(BLOCKS[skin][COLOUR_SCHEMES.Arika[piece]], pos_x+x*16, pos_y+y*16) end end for i = 1, self.next_queue_length do @@ -1067,8 +1067,8 @@ function GameMode:drawScoringInfo() if self.clear or self.game_over then - sounds['bgm_firsthalf']:stop() - sounds['bgm_secondhalf']:stop() + SOUNDS['bgm_firsthalf']:stop() + SOUNDS['bgm_secondhalf']:stop() end end @@ -1080,16 +1080,16 @@ function GameMode:drawBackground() --if self.training then bg = math.mod(math.floor(((self.frames+1)/1200)), 10) end if bg == 0 or bg == 6 or bg == 9 then limit = 5 end if bg == 5 then limit = 4.76 end - if not backgrounds[bg]:isPlaying() then - backgrounds[bg]:play() + if not BACKGROUNDS[bg]:isPlaying() then + BACKGROUNDS[bg]:play() end - if backgrounds[bg]:tell() >= limit then - backgrounds[bg]:rewind() + if BACKGROUNDS[bg]:tell() >= limit then + BACKGROUNDS[bg]:rewind() end if bg == 0 or bg == 8 or bg == 9 or bg == 3 then brightness = 0.7 end love.graphics.setColor(brightness, brightness, brightness, 1) love.graphics.draw( - backgrounds[bg], + BACKGROUNDS[bg], 0, 0, 0, 0.5, 0.5 ) diff --git a/game/grid.lua b/game/grid.lua index c84cee5..184f30d 100644 --- a/game/grid.lua +++ b/game/grid.lua @@ -185,23 +185,23 @@ function Grid:draw(greyscale, timer) love.graphics.line(256,31+45,256+80,31+45) for y = 1, self.height do for x = 1, self.width do - if blocks[self.grid[y][x].skin] and - blocks[self.grid[y][x].skin][self.grid[y][x].colour] then + if BLOCKS[self.grid[y][x].skin] and + BLOCKS[self.grid[y][x].skin][self.grid[y][x].colour] then if self.grid[y][x].flash ~= nil then if self.grid[y][x].flash > 0 then love.graphics.setColor(0.4+(self.grid[y][x].flash*0.1), 0.4+(self.grid[y][x].flash*0.1), 0.4+(self.grid[y][x].flash*0.1), 1) - love.graphics.draw(blocks[self.grid[y][x].skin]['W'], 200+x*16, 64+y*16) + love.graphics.draw(BLOCKS[self.grid[y][x].skin]['W'], 200+x*16, 64+y*16) self.grid[y][x].flash = self.grid[y][x].flash - 1 else love.graphics.setColor(1, 1, 1, 1) - love.graphics.draw(blocks[self.grid[y][x].skin][self.grid[y][x].colour..'_d'], 200+x*16, 64+y*16) + love.graphics.draw(BLOCKS[self.grid[y][x].skin][self.grid[y][x].colour..'_d'], 200+x*16, 64+y*16) end end if greyscale then if timer > 1 then timer = 1 end love.graphics.setColor(0.7, 0.7, 0.7, 0+timer) if self.grid[y][x] ~= empty and self.grid[y][x].colour ~= 'X' then - love.graphics.draw(blocks[self.grid[y][x].skin]["A"], 200+x*16, 64+y*16) + love.graphics.draw(BLOCKS[self.grid[y][x].skin]["A"], 200+x*16, 64+y*16) end end end diff --git a/game/piece.lua b/game/piece.lua index e1f11c5..5594ca3 100644 --- a/game/piece.lua +++ b/game/piece.lua @@ -135,14 +135,14 @@ function Piece:addGravity(gravity, grid, classic_lock) self.gravity = new_frac_gravity self:dropSquares(dropped_squares, grid) if self:isDropBlocked(grid) then - playSE("bottom") + PlaySE("bottom") end else local new_frac_gravity = new_gravity + dropped_squares self.gravity = new_frac_gravity self:moveInGrid({ x=0, y=-1 }, dropped_squares, grid) if self:isMoveBlocked(grid, { x=0, y=-1 }) then - playSE("bottom") + PlaySE("bottom") end end else @@ -164,7 +164,7 @@ function Piece:draw(opacity, brightness, grid, partial_das) local x = self.position.x + offset.x local y = self.position.y + offset.y love.graphics.draw( - blocks[self.skin][self.colour], + BLOCKS[self.skin][self.colour], 216+x*16+partial_das, 80+y*16+gravity_offset ) end diff --git a/game/rotation.lua b/game/rotation.lua index d09b5fb..49b04d7 100644 --- a/game/rotation.lua +++ b/game/rotation.lua @@ -96,7 +96,7 @@ function Rotation:rotatePiece(inputs, piece, grid, prev_inputs, initial, lastdir end if not initial and not was_drop_blocked and piece:isDropBlocked(grid) then - playSE("bottom") + PlaySE("bottom") end -- prev_inputs becomes the previous inputs @@ -201,7 +201,7 @@ function Rotation:movePiece(piece, grid, move, instant) end end if not was_drop_blocked and piece:isDropBlocked(grid) then - playSE("bottom") + PlaySE("bottom") end end diff --git a/game/rotation_pent.lua b/game/rotation_pent.lua index 7e11df3..d1bd009 100644 --- a/game/rotation_pent.lua +++ b/game/rotation_pent.lua @@ -96,7 +96,7 @@ function Rotation:rotatePiece(inputs, piece, grid, prev_inputs, initial, lastdir end if not initial and not was_drop_blocked and piece:isDropBlocked(grid) then - playSE("bottom") + PlaySE("bottom") end -- prev_inputs becomes the previous inputs @@ -189,7 +189,7 @@ function Rotation:movePiece(piece, grid, move, instant) end end if not was_drop_blocked and piece:isDropBlocked(grid) then - playSE("bottom") + PlaySE("bottom") end end diff --git a/load.lua b/load.lua new file mode 100644 index 0000000..52b5bfc --- /dev/null +++ b/load.lua @@ -0,0 +1,108 @@ +-- Bigint library +bigint = require "libs.bigint.bigint" +number_names = require "libs.bigint.named-powers-of-ten" + +-- Fonts +FONT_tromi = love.graphics.newFont('res/fonts/monofonto rg.otf', 28) +FONT_big = love.graphics.newFont('res/fonts/monofonto rg.otf', 56) + +-- GRAPHICS +BACKGROUNDS = { + [0] = love.graphics.newVideo("res/backgrounds/green_waterfall.ogv", {audio=false}), + love.graphics.newVideo("res/backgrounds/water.ogv", {audio=false}), + love.graphics.newVideo("res/backgrounds/green_streams.ogv", {audio=false}), + love.graphics.newVideo("res/backgrounds/streams.ogv", {audio=false}), + love.graphics.newVideo("res/backgrounds/red_forest_waterfall.ogv", {audio=false}), + love.graphics.newVideo("res/backgrounds/flowers_rain.ogv", {audio=false}), + love.graphics.newVideo("res/backgrounds/moonlight_tree.ogv", {audio=false}), + love.graphics.newVideo("res/backgrounds/lisa_frank.ogv", {audio=false}), + love.graphics.newVideo("res/backgrounds/snowy_trees.ogv", {audio=false}), + love.graphics.newVideo("res/backgrounds/snowy_cabin.ogv", {audio=false}), +} + + +BLOCKS = { + ["2tie"] = { + R = love.graphics.newImage("res/img/r.png"), + O = love.graphics.newImage("res/img/o.png"), + Y = love.graphics.newImage("res/img/y.png"), + G = love.graphics.newImage("res/img/g.png"), + C = love.graphics.newImage("res/img/b.png"), + B = love.graphics.newImage("res/img/i.png"), + M = love.graphics.newImage("res/img/v.png"), + F = love.graphics.newImage("res/img/bl.png"), + A = love.graphics.newImage("res/img/bl.png"), + X = love.graphics.newImage("res/img/t.png"), + W = love.graphics.newImage("res/img/w.png"), + R_d = love.graphics.newImage("res/img/r_d.png"), + O_d = love.graphics.newImage("res/img/o_d.png"), + Y_d = love.graphics.newImage("res/img/y_d.png"), + G_d = love.graphics.newImage("res/img/g_d.png"), + C_d = love.graphics.newImage("res/img/b_d.png"), + B_d = love.graphics.newImage("res/img/i_d.png"), + M_d = love.graphics.newImage("res/img/v_d.png"), + } +} + +COLOUR_SCHEMES = { + Arika = { + I = "R", + L = "O", + J = "B", + S = "M", + Z = "G", + O = "Y", + T = "C", + } +} + +-- BGMs and SFXs +SOUNDS = { + bottom = love.audio.newSource("res/se/bottom.wav", "static"), + lock = love.audio.newSource("res/se/lock.wav", "static"), + erase = love.audio.newSource("res/se/erase.wav", "static"), + fall = love.audio.newSource("res/se/fall.wav", "static"), + ready = love.audio.newSource("res/se/ready.wav", "static"), + promote = love.audio.newSource("res/se/promote.wav", "static"), + demote = love.audio.newSource("res/se/demote.wav", "static"), + autopromote = love.audio.newSource("res/se/autopromote.wav", "static"), + bgm_firsthalf = love.audio.newSource("res/bgm/firsthalf.flac", "static"), + bgm_secondhalf = love.audio.newSource("res/bgm/secondhalf.flac", "static"), + bgm_title = love.audio.newSource("res/bgm/title.flac", "static") +} + +function PlaySE(sound, subsound) + if sound ~= nil then + if subsound ~= nil then + SOUNDS[sound][subsound]:setVolume(0.4) + if SOUNDS[sound][subsound]:isPlaying() then + SOUNDS[sound][subsound]:stop() + end + SOUNDS[sound][subsound]:play() + else + SOUNDS[sound]:setVolume(0.4) + if SOUNDS[sound]:isPlaying() then + SOUNDS[sound]:stop() + end + SOUNDS[sound]:play() + end + end +end + +function PlaySEOnce(sound, subsound) + if sound ~= nil then + if subsound ~= nil then + SOUNDS[sound][subsound]:setVolume(0.4) + if SOUNDS[sound][subsound]:isPlaying() then + return + end + SOUNDS[sound][subsound]:play() + else + SOUNDS[sound]:setVolume(0.4) + if SOUNDS[sound]:isPlaying() then + return + end + SOUNDS[sound]:play() + end + end +end diff --git a/load/bigint.lua b/load/bigint.lua deleted file mode 100644 index c7f7207..0000000 --- a/load/bigint.lua +++ /dev/null @@ -1,2 +0,0 @@ -bigint = require "libs.bigint.bigint" -number_names = require "libs.bigint.named-powers-of-ten" \ No newline at end of file diff --git a/load/fonts.lua b/load/fonts.lua deleted file mode 100644 index 226731e..0000000 --- a/load/fonts.lua +++ /dev/null @@ -1,2 +0,0 @@ -tromi_font = love.graphics.newFont('res/fonts/monofonto rg.otf', 28) -big_font = love.graphics.newFont('res/fonts/monofonto rg.otf', 56) diff --git a/load/graphics.lua b/load/graphics.lua deleted file mode 100644 index 4227eac..0000000 --- a/load/graphics.lua +++ /dev/null @@ -1,48 +0,0 @@ -backgrounds = { - [0] = love.graphics.newVideo("res/backgrounds/green_waterfall.ogv", {audio=false}), - love.graphics.newVideo("res/backgrounds/water.ogv", {audio=false}), - love.graphics.newVideo("res/backgrounds/green_streams.ogv", {audio=false}), - love.graphics.newVideo("res/backgrounds/streams.ogv", {audio=false}), - love.graphics.newVideo("res/backgrounds/red_forest_waterfall.ogv", {audio=false}), - love.graphics.newVideo("res/backgrounds/flowers_rain.ogv", {audio=false}), - love.graphics.newVideo("res/backgrounds/moonlight_tree.ogv", {audio=false}), - love.graphics.newVideo("res/backgrounds/lisa_frank.ogv", {audio=false}), - love.graphics.newVideo("res/backgrounds/snowy_trees.ogv", {audio=false}), - love.graphics.newVideo("res/backgrounds/snowy_cabin.ogv", {audio=false}), -} - - -blocks = { - ["2tie"] = { - R = love.graphics.newImage("res/img/r.png"), - O = love.graphics.newImage("res/img/o.png"), - Y = love.graphics.newImage("res/img/y.png"), - G = love.graphics.newImage("res/img/g.png"), - C = love.graphics.newImage("res/img/b.png"), - B = love.graphics.newImage("res/img/i.png"), - M = love.graphics.newImage("res/img/v.png"), - F = love.graphics.newImage("res/img/bl.png"), - A = love.graphics.newImage("res/img/bl.png"), - X = love.graphics.newImage("res/img/t.png"), - W = love.graphics.newImage("res/img/w.png"), - R_d = love.graphics.newImage("res/img/r_d.png"), - O_d = love.graphics.newImage("res/img/o_d.png"), - Y_d = love.graphics.newImage("res/img/y_d.png"), - G_d = love.graphics.newImage("res/img/g_d.png"), - C_d = love.graphics.newImage("res/img/b_d.png"), - B_d = love.graphics.newImage("res/img/i_d.png"), - M_d = love.graphics.newImage("res/img/v_d.png"), - } -} - -ColourSchemes = { - Arika = { - I = "R", - L = "O", - J = "B", - S = "M", - Z = "G", - O = "Y", - T = "C", - } -} diff --git a/load/save.lua b/load/save.lua deleted file mode 100644 index a66bdab..0000000 --- a/load/save.lua +++ /dev/null @@ -1,65 +0,0 @@ -local bitser = require 'libs.bitser' -local fs = love.filesystem - -function loadSave() --- config = loadFromFile(CONFIG_FILE) -end - -function loadFromFile(filename) - if fs.read(filename) == nil then - return {} -- new object - end - return bitser.loadLoveFile(filename) -end - -function initConfig() --- if config.fullscreen == nil then config.fullscreen = false end --- if config.music == nil then config.music = true end --- if not config.input then --- scene = InputConfigScene(true) --- else --- scene = TitleScene() --- end -end - -local _config = loadFromFile(CONFIG_FILE) or {} -local _defaultConfig = { - firstTime = true, - - fullscreen = false, - music = true, - - input = { - keys = {}, - mobile = { -- Should not be changed for any reason, used for mobile only - enter = 'menu_decide', - f13 = 'up', - f14 = 'down', - f15 = 'left', - f16 = 'right', - f17 = 'rotate_left', - f18 = 'rotate_left2', - f19 = 'rotate_right', - f20 = 'rotate_right2', - } - } -} - -function saveConfig() - bitser.dumpLoveFile(CONFIG_FILE, _config) -end - - -config = setmetatable( - {}, - { - __index = function(_, k) - if _config[k] == nil then _config[k] = _defaultConfig[k] end - return _config[k] - end, - __newindex = function(_, k, v) - _config[k] = v - saveConfig() - end - } -) \ No newline at end of file diff --git a/load/sounds.lua b/load/sounds.lua deleted file mode 100644 index 37e4d1b..0000000 --- a/load/sounds.lua +++ /dev/null @@ -1,49 +0,0 @@ -sounds = { - bottom = love.audio.newSource("res/se/bottom.wav", "static"), - lock = love.audio.newSource("res/se/lock.wav", "static"), - erase = love.audio.newSource("res/se/erase.wav", "static"), - fall = love.audio.newSource("res/se/fall.wav", "static"), - ready = love.audio.newSource("res/se/ready.wav", "static"), - promote = love.audio.newSource("res/se/promote.wav", "static"), - demote = love.audio.newSource("res/se/demote.wav", "static"), - autopromote = love.audio.newSource("res/se/autopromote.wav", "static"), - bgm_firsthalf = love.audio.newSource("res/bgm/firsthalf.flac", "static"), - bgm_secondhalf = love.audio.newSource("res/bgm/secondhalf.flac", "static"), - bgm_title = love.audio.newSource("res/bgm/title.flac", "static") -} - -function playSE(sound, subsound) - if sound ~= nil then - if subsound ~= nil then - sounds[sound][subsound]:setVolume(0.4) - if sounds[sound][subsound]:isPlaying() then - sounds[sound][subsound]:stop() - end - sounds[sound][subsound]:play() - else - sounds[sound]:setVolume(0.4) - if sounds[sound]:isPlaying() then - sounds[sound]:stop() - end - sounds[sound]:play() - end - end -end - -function playSEOnce(sound, subsound) - if sound ~= nil then - if subsound ~= nil then - sounds[sound][subsound]:setVolume(0.4) - if sounds[sound][subsound]:isPlaying() then - return - end - sounds[sound][subsound]:play() - else - sounds[sound]:setVolume(0.4) - if sounds[sound]:isPlaying() then - return - end - sounds[sound]:play() - end - end -end diff --git a/main.lua b/main.lua index d377299..d5a74e6 100644 --- a/main.lua +++ b/main.lua @@ -22,15 +22,12 @@ HIscoreFILE = 'hiscores.sav' function love.load() math.randomseed(os.time()) highscores = {} - require "load.graphics" - require "load.fonts" - require "load.sounds" - require "load.save" - require "load.bigint" + require "load" + require "settings" require "scene" require "game.vctrl" -- VCTRL - SCENE = config.firstTime and InputConfigScene() or TitleScene() + SCENE = SETTINGS.firstTime and InputConfigScene() or TitleScene() love.mouse.setVisible(false) love.window.setMode(love.graphics.getWidth(), love.graphics.getHeight(), {resizable = true}); @@ -38,9 +35,7 @@ function love.load() GLOBAL_TRANSFORM = love.math.newTransform() love.resize(love.graphics.getWidth(), love.graphics.getHeight()) - -- init config - initConfig() - love.window.setFullscreen(config["fullscreen"]) + love.window.setFullscreen(SETTINGS["fullscreen"]) VCTRL.new{ -- {type='button',x= 100,y=320,key= 'up',icon= 'up',r=35,iconSize=60,alpha=1}, @@ -127,8 +122,8 @@ function love.keypressed(key, scancode) -- global hotkeys if scancode == "f4" then - config["fullscreen"] = not config["fullscreen"] - love.window.setFullscreen(config["fullscreen"]) + SETTINGS["fullscreen"] = not SETTINGS["fullscreen"] + love.window.setFullscreen(SETTINGS["fullscreen"]) elseif scancode == "f2" and SCENE.title ~= "Input Config" and SCENE.title ~= "Game" then SCENE = InputConfigScene() -- function keys are reserved @@ -139,8 +134,8 @@ function love.keypressed(key, scancode) SCENE:onInputPress({input="menu_back", type="key", key=key, scancode=scancode}) -- pass any other key to the scene, with its configured mapping else - if config.input and config.input.keys then - input_pressed = config.input.keys[scancode] + if SETTINGS.input and SETTINGS.input.keys then + input_pressed = SETTINGS.input.keys[scancode] end SCENE:onInputPress({input=input_pressed, type="key", key=key, scancode=scancode}) end @@ -159,8 +154,8 @@ function love.keyreleased(key, scancode) return -- handle all other keys; tab is reserved, but the input config scene keeps it from getting configured as a game input, so pass tab to the scene here else - if config.input and config.input.keys then - input_released = config.input.keys[scancode] + if SETTINGS.input and SETTINGS.input.keys then + input_released = SETTINGS.input.keys[scancode] end SCENE:onInputRelease({input=input_released, type="key", key=key, scancode=scancode}) end @@ -171,12 +166,12 @@ end function love.joystickpressed(joystick, button) local input_pressed = nil if - config.input and - config.input.joysticks and - config.input.joysticks[joystick:getName()] and - config.input.joysticks[joystick:getName()].buttons + SETTINGS.input and + SETTINGS.input.joysticks and + SETTINGS.input.joysticks[joystick:getName()] and + SETTINGS.input.joysticks[joystick:getName()].buttons then - input_pressed = config.input.joysticks[joystick:getName()].buttons[button] + input_pressed = SETTINGS.input.joysticks[joystick:getName()].buttons[button] end SCENE:onInputPress({input=input_pressed, type="joybutton", name=joystick:getName(), button=button}) end @@ -184,12 +179,12 @@ end function love.joystickreleased(joystick, button) local input_released = nil if - config.input and - config.input.joysticks and - config.input.joysticks[joystick:getName()] and - config.input.joysticks[joystick:getName()].buttons + SETTINGS.input and + SETTINGS.input.joysticks and + SETTINGS.input.joysticks[joystick:getName()] and + SETTINGS.input.joysticks[joystick:getName()].buttons then - input_released = config.input.joysticks[joystick:getName()].buttons[button] + input_released = SETTINGS.input.joysticks[joystick:getName()].buttons[button] end SCENE:onInputRelease({input=input_released, type="joybutton", name=joystick:getName(), button=button}) end @@ -199,17 +194,17 @@ function love.joystickaxis(joystick, axis, value) local positive_released = nil local negative_released = nil if - config.input and - config.input.joysticks and - config.input.joysticks[joystick:getName()] and - config.input.joysticks[joystick:getName()].axes and - config.input.joysticks[joystick:getName()].axes[axis] + SETTINGS.input and + SETTINGS.input.joysticks and + SETTINGS.input.joysticks[joystick:getName()] and + SETTINGS.input.joysticks[joystick:getName()].axes and + SETTINGS.input.joysticks[joystick:getName()].axes[axis] then if math.abs(value) >= 1 then - input_pressed = config.input.joysticks[joystick:getName()].axes[axis][value >= 1 and "positive" or "negative"] + input_pressed = SETTINGS.input.joysticks[joystick:getName()].axes[axis][value >= 1 and "positive" or "negative"] end - positive_released = config.input.joysticks[joystick:getName()].axes[axis].positive - negative_released = config.input.joysticks[joystick:getName()].axes[axis].negative + positive_released = SETTINGS.input.joysticks[joystick:getName()].axes[axis].positive + negative_released = SETTINGS.input.joysticks[joystick:getName()].axes[axis].negative end if math.abs(value) >= 1 then SCENE:onInputPress({input=input_pressed, type="joyaxis", name=joystick:getName(), axis=axis, value=value}) @@ -231,14 +226,14 @@ function love.joystickhat(joystick, hat, direction) local input_pressed = nil local has_hat = false if - config.input and - config.input.joysticks and - config.input.joysticks[joystick:getName()] and - config.input.joysticks[joystick:getName()].hats and - config.input.joysticks[joystick:getName()].hats[hat] + SETTINGS.input and + SETTINGS.input.joysticks and + SETTINGS.input.joysticks[joystick:getName()] and + SETTINGS.input.joysticks[joystick:getName()].hats and + SETTINGS.input.joysticks[joystick:getName()].hats[hat] then if direction ~= "c" then - input_pressed = config.input.joysticks[joystick:getName()].hats[hat][direction] + input_pressed = SETTINGS.input.joysticks[joystick:getName()].hats[hat][direction] end has_hat = true end @@ -247,20 +242,20 @@ function love.joystickhat(joystick, hat, direction) local char = direction:sub(i, i) local _, count = last_hat_direction:gsub(char, char) if count == 0 then - SCENE:onInputPress({input=config.input.joysticks[joystick:getName()].hats[hat][char], type="joyhat", name=joystick:getName(), hat=hat, direction=char}) + SCENE:onInputPress({input=SETTINGS.input.joysticks[joystick:getName()].hats[hat][char], type="joyhat", name=joystick:getName(), hat=hat, direction=char}) end end for i = 1, #last_hat_direction do local char = last_hat_direction:sub(i, i) local _, count = direction:gsub(char, char) if count == 0 then - SCENE:onInputRelease({input=config.input.joysticks[joystick:getName()].hats[hat][char], type="joyhat", name=joystick:getName(), hat=hat, direction=char}) + SCENE:onInputRelease({input=SETTINGS.input.joysticks[joystick:getName()].hats[hat][char], type="joyhat", name=joystick:getName(), hat=hat, direction=char}) end end last_hat_direction = direction elseif has_hat then for i, direction in ipairs{"d", "l", "ld", "lu", "r", "rd", "ru", "u"} do - SCENE:onInputRelease({input=config.input.joysticks[joystick:getName()].hats[hat][direction], type="joyhat", name=joystick:getName(), hat=hat, direction=direction}) + SCENE:onInputRelease({input=SETTINGS.input.joysticks[joystick:getName()].hats[hat][direction], type="joyhat", name=joystick:getName(), hat=hat, direction=direction}) end last_hat_direction = "" elseif direction ~= "c" then @@ -355,9 +350,9 @@ local main_bg_draw_frame = 0 local main_bg_last_color = nil function mainBackground() - if config["music"] and not sounds["bgm_title"]:isPlaying() then - sounds["bgm_title"]:setVolume(0.3) - sounds["bgm_title"]:play() + if SETTINGS["music"] and not SOUNDS["bgm_title"]:isPlaying() then + SOUNDS["bgm_title"]:setVolume(0.3) + SOUNDS["bgm_title"]:play() end local y = 40 if main_bg_draw_frame >= 16 then @@ -389,7 +384,7 @@ function mainBackground() for y=1,30 do if main_bg_grid[x][y] ~= 0 then love.graphics.setColor(1, 1, 1, 0.4) - if ((x-1)*48)-560 > 0 and ((x-1)*48)-560 < 640 then love.graphics.draw(blocks["2tie"][main_bg_grid[x][y]], ((x-1)*48)-570, (((y+2)*48)+main_bg_draw_frame*3)-480,0, 3) end + if ((x-1)*48)-560 > 0 and ((x-1)*48)-560 < 640 then love.graphics.draw(BLOCKS["2tie"][main_bg_grid[x][y]], ((x-1)*48)-570, (((y+2)*48)+main_bg_draw_frame*3)-480,0, 3) end love.graphics.setColor(1, 1, 1, 1) end end @@ -398,7 +393,7 @@ function mainBackground() for y=1,30 do if main_bg_grid[x][y] ~= 0 then love.graphics.setColor(1, 1, 1, 1) - love.graphics.draw(blocks["2tie"][main_bg_grid[x][y]], (x-1)*16, ((y-1)*16)+main_bg_draw_frame) + love.graphics.draw(BLOCKS["2tie"][main_bg_grid[x][y]], (x-1)*16, ((y-1)*16)+main_bg_draw_frame) end end end @@ -406,7 +401,7 @@ function mainBackground() for y=1,30 do if main_bg_grid[x][y] ~= 0 then love.graphics.setColor(1, 1, 1, 0.6) - if ((x-1)*32)-320 > 0 and ((x-1)*32)-320 < 640 then love.graphics.draw(blocks["2tie"][main_bg_grid[x][y]], ((x-1)*32)-320, (((y+1)*32)+main_bg_draw_frame*2)-320,0, 2) end + if ((x-1)*32)-320 > 0 and ((x-1)*32)-320 < 640 then love.graphics.draw(BLOCKS["2tie"][main_bg_grid[x][y]], ((x-1)*32)-320, (((y+1)*32)+main_bg_draw_frame*2)-320,0, 2) end love.graphics.setColor(1, 1, 1, 1) end end diff --git a/scene/exit.lua b/scene/exit.lua index 095e8f1..73300a5 100644 --- a/scene/exit.lua +++ b/scene/exit.lua @@ -1,5 +1,5 @@ local ExitScene = SCENE:extend() -require 'load.save' +require 'settings' ExitScene.title = "Exit Game" diff --git a/scene/fullscreen.lua b/scene/fullscreen.lua index c36972d..d817586 100644 --- a/scene/fullscreen.lua +++ b/scene/fullscreen.lua @@ -1,5 +1,5 @@ local FullscreenScene = SCENE:extend() -require 'load.save' +require 'settings' FullscreenScene.title = "Fullscreen" @@ -7,9 +7,8 @@ function FullscreenScene:new() end function FullscreenScene:update() - config["fullscreen"] = not config["fullscreen"] - saveConfig() - love.window.setFullscreen(config["fullscreen"]) + SETTINGS["fullscreen"] = not SETTINGS["fullscreen"] + love.window.setFullscreen(SETTINGS["fullscreen"]) SCENE = TitleScene() end diff --git a/scene/game.lua b/scene/game.lua index 7fe0500..96e31c3 100644 --- a/scene/game.lua +++ b/scene/game.lua @@ -2,7 +2,7 @@ local GameScene = SCENE:extend() GameScene.title = "Game" local tas = false -require 'load.save' +require 'settings' function GameScene:new(player_name, replay_file, replay_grade) game_mode = require 'game.gamemode' diff --git a/scene/input_config.lua b/scene/input_config.lua index af0bc59..35da56a 100644 --- a/scene/input_config.lua +++ b/scene/input_config.lua @@ -50,7 +50,7 @@ function ConfigScene:onInputPress(e) self:changeOption(-1) elseif e.input == "down" or e.scancode == "down" then self:changeOption(1) - elseif config.input and ( + elseif SETTINGS.input and ( e.input == "menu_back" or e.input == "rotate_right" or e.scancode == "backspace" or e.scancode == "delete" ) then SCENE = TitleScene() diff --git a/scene/key_config.lua b/scene/key_config.lua index e1f1cbc..9895095 100644 --- a/scene/key_config.lua +++ b/scene/key_config.lua @@ -2,7 +2,7 @@ local KeyConfigScene = SCENE:extend() KeyConfigScene.title = "Key Config" -require 'load.save' +require 'settings' local minos = {'R_d', 'O_d', 'Y_d', 'G_d', 'C_d', 'B_d', 'M_d'} @@ -59,7 +59,7 @@ function KeyConfigScene:render() end end if self.input_state > #configurable_inputs then - drawText("Press enter to confirm, delete/backspace to retry" .. (config.input and ", escape to cancel" or ""),0,0,1000) + drawText("Press enter to confirm, delete/backspace to retry" .. (SETTINGS.input and ", escape to cancel" or ""),0,0,1000) else drawText("Press key input for " .. input_names[configurable_inputs[self.input_state]] .. ", tab to skip, escape to cancel",0,0,1000) drawText("Function keys (F1, F2, etc.), escape, and tab can't be changed", 0, 20,1000) @@ -73,10 +73,9 @@ function KeyConfigScene:onInputPress(e) SCENE = InputConfigScene() elseif self.input_state > #configurable_inputs then if e.scancode == "return" then - config.input.keys = self.new_input - saveConfig() - SCENE = config.firstTime and TitleScene() or InputConfigScene() - config.firstTime = false + SETTINGS.input.keys = self.new_input + SCENE = SETTINGS.firstTime and TitleScene() or InputConfigScene() + SETTINGS.firstTime = false elseif e.scancode == "delete" or e.scancode == "backspace" then -- retry self.input_state = 1 diff --git a/scene/music_toggle.lua b/scene/music_toggle.lua index 7ef0227..0f751f9 100644 --- a/scene/music_toggle.lua +++ b/scene/music_toggle.lua @@ -1,5 +1,5 @@ local MusicToggleScene = SCENE:extend() -require 'load.save' +require 'settings' MusicToggleScene.title = "Play music during game:" @@ -7,8 +7,7 @@ function MusicToggleScene:new() end function MusicToggleScene:update() - config["music"] = not config["music"] - saveConfig() + SETTINGS["music"] = not SETTINGS["music"] SCENE = TitleScene() end diff --git a/scene/name_entry.lua b/scene/name_entry.lua index d5babaf..9240c70 100644 --- a/scene/name_entry.lua +++ b/scene/name_entry.lua @@ -1,7 +1,7 @@ local NameEntryScene = SCENE:extend() local Grid = require 'game.grid' local bitser = require 'libs.bitser' -require 'load.save' +require 'settings' NameEntryScene.title = "Game Start" @@ -26,8 +26,8 @@ function NameEntryScene:new() "10k", "9k", "8k", "7k", "6k", "5k", "4k", "3k", "2k", "1k", "1D", "2D", "3D", "4D", "5D", "6D", "7D", "8D", "9D" } - if config['last_entry'] ~= nil then - self.name_entry = {config['last_entry']:sub(1,1),config['last_entry']:sub(2,2),config['last_entry']:sub(3,3)} + if SETTINGS['last_entry'] ~= nil then + self.name_entry = {SETTINGS['last_entry']:sub(1,1),SETTINGS['last_entry']:sub(2,2),SETTINGS['last_entry']:sub(3,3)} self.entry_pos = 3 end if love.filesystem.getInfo(HIscoreFILE) then @@ -115,8 +115,7 @@ function NameEntryScene:onInputPress(e) self.delete_confirm = false self.delete_input_count = 0 if self.entry_pos == 4 then - config['last_entry'] = name:upper() - saveConfig() + SETTINGS['last_entry'] = name:upper() SCENE = GameScene(name:lower()) else if self.entry_pos == 3 then diff --git a/scene/stick_config.lua b/scene/stick_config.lua index 1d14e3e..4afdbe5 100644 --- a/scene/stick_config.lua +++ b/scene/stick_config.lua @@ -2,7 +2,7 @@ local StickConfigScene = SCENE:extend() StickConfigScene.title = "Controller Config" -require 'load.save' +require 'settings' local minos = {'R_d', 'O_d', 'Y_d', 'G_d', 'C_d', 'B_d', 'M_d'} @@ -59,7 +59,7 @@ function StickConfigScene:render() end end if self.input_state > #configurable_inputs then - drawText("Press enter to confirm, delete/backspace to retry" .. (config.input and ", escape to cancel" or ""), 0, 0, 1000) + drawText("Press enter to confirm, delete/backspace to retry" .. (SETTINGS.input and ", escape to cancel" or ""), 0, 0, 1000) else drawText("Press joystick input for " .. input_names[configurable_inputs[self.input_state]] .. ", tab to skip, escape to cancel", 0, 0, 1000) end @@ -81,10 +81,9 @@ function StickConfigScene:onInputPress(e) elseif self.input_state > #configurable_inputs then if e.scancode == "return" then -- save new input, then load next scene - local had_config = config.input ~= nil - if not config.input then config.input = {} end - config.input.joysticks = self.new_input - saveConfig() + local had_config = SETTINGS.input ~= nil + if not SETTINGS.input then SETTINGS.input = {} end + SETTINGS.input.joysticks = self.new_input SCENE = had_config and InputConfigScene() or TitleScene() elseif e.scancode == "delete" or e.scancode == "backspace" then -- retry diff --git a/scene/title.lua b/scene/title.lua index fa616cd..1b700cb 100644 --- a/scene/title.lua +++ b/scene/title.lua @@ -1,5 +1,5 @@ local TitleScene = SCENE:extend() -require 'load.save' +require 'settings' require 'funcs' TitleScene.title = "Title" @@ -16,7 +16,7 @@ local main_menu_screens = { } function TitleScene:new() - if sounds['bgm_firsthalf']:isPlaying() or sounds['bgm_secondhalf']:isPlaying() or not config["music"] then + if SOUNDS['bgm_firsthalf']:isPlaying() or SOUNDS['bgm_secondhalf']:isPlaying() or not SETTINGS["music"] then love.audio.stop() end self.main_menu_state = 1 @@ -68,7 +68,7 @@ function TitleScene:render() drawText("Based on Cambridge - t-sp.in/cambridge", 20, 420, 1000) drawText("Music for Tromi by Jerry Martin, all rights reserved - jerrymartinmusic.com", 20, 435, 1000) drawText("Game backgrounds by Pixabay users Joe_hackney, yokim, Favorisxp, Any_Ann, VisualSkyFX ", 20, 450, 1000) - if config["music"] == true then + if SETTINGS["music"] == true then drawText("On", 230, 320, 1000) else drawText("Off", 230, 320, 1000) diff --git a/scene/training.lua b/scene/training.lua index 72791ea..a6b7d19 100644 --- a/scene/training.lua +++ b/scene/training.lua @@ -2,7 +2,7 @@ local TrainingScene = SCENE:extend() TrainingScene.title = "Max Gravity Training" -require 'load.save' +require 'settings' function TrainingScene:new() game_mode = require 'game.gamemode' diff --git a/settings.lua b/settings.lua new file mode 100644 index 0000000..5b67dba --- /dev/null +++ b/settings.lua @@ -0,0 +1,39 @@ +local bitser = require 'libs.bitser' +local fs = love.filesystem + +local _settings = fs.read(CONFIG_FILE) ~= nil and bitser.loadLoveFile(CONFIG_FILE) or {} +local _defaultSettings = { + firstTime = true, + + fullscreen = false, + music = true, + + input = { + keys = {}, + mobile = { -- Should not be changed for any reason, used for mobile only + enter = 'menu_decide', + f13 = 'up', + f14 = 'down', + f15 = 'left', + f16 = 'right', + f17 = 'rotate_left', + f18 = 'rotate_left2', + f19 = 'rotate_right', + f20 = 'rotate_right2', + } + } +} + +SETTINGS = setmetatable( + {}, + { + __index = function(_, k) + if _settings[k] == nil then _settings[k] = _defaultSettings[k] end + return _settings[k] + end, + __newindex = function(_, k, v) + _settings[k] = v + bitser.dumpLoveFile(CONFIG_FILE,_settings) + end + } +) \ No newline at end of file