Skip to content
This repository has been archived by the owner on Aug 26, 2022. It is now read-only.

Commit

Permalink
Version 3.3.1
Browse files Browse the repository at this point in the history
  • Loading branch information
smallsco committed Oct 9, 2021
1 parent 1177f0d commit 06d15d3
Show file tree
Hide file tree
Showing 6 changed files with 135 additions and 36 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
## CHANGELOG

### v3.3.1 (2021-10-09)

* You can now use the function keys on your keyboard to control Mojave:
* F4 - toggles music and SFX
* F5 - toggles fullscreen mode
* F6 through F12 - correspond to the in-game controls: first turn, previous turn, pause/resume, next turn, last turn, restart game, and exit.
* Thank you to [Xtagon](https://github.com/xtagon) for suggesting this feature!

### v3.3 (2021-09-26)

* Mojave can now run at higher resolutions!
Expand Down
20 changes: 11 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,15 +119,16 @@ Under Wrapped rules, if a snake crosses the edge of the board, instead of being
<img src="readme_screenshots/development_tools.png">
</p>

You can use the playback controls at the top right of the game window, while a game is taking place, to debug your snake:
You can use the playback controls at the top right of the game window, while a game is taking place, to debug your snake:
(these controls can also be accessed by using the function keys on your keyboard)

* The "First" button will jump to the first turn of the game.
* The "Rewind" button will step back one turn.
* The "Play/Pause" button will pause and resume game playback (do note that pausing will only pause the UI, the game will continue to run in the background).
* The "Fast Forward" button will step forward one turn.
* The "Last" button will jump to the last turn of the game.
* The "Rematch" button will end the current game and start a new game with the same options.
* The "Close" button will end the current game and return to the main menu.
* The "First" button (or F6) will jump to the first turn of the game.
* The "Rewind" button (or F7) will step back one turn.
* The "Play/Pause" button (or F8) will pause and resume game playback (do note that pausing will only pause the UI, the game will continue to run in the background).
* The "Fast Forward" button (or F9) will step forward one turn.
* The "Last" button (or F10) will jump to the last turn of the game.
* The "Rematch" button (or F11) will end the current game and start a new game with the same options.
* The "Close" button (or F12) will end the current game and return to the main menu.

The "Debug" button located above each snake preview will copy the JSON data that was sent to that snake on the last turn, and that snake's response, to the clipboard.

Expand All @@ -147,7 +148,7 @@ You can also hover over a snake's preview image to see their latency for the cur
* Hazard Color
* This changes the color of hazard tiles on the game board (note: you cannot set the transparancy value because these tiles fade in and out).
* Fullscreen
* This toggles full-screen mode.
* This toggles fullscreen mode. Fullscreen mode can also be toggled by using the F5 key on your keyboard.
* Vignette
* This enables a [vignette](https://en.wikipedia.org/wiki/Vignette_(graphic_design)), which shades the background at the cost of performance.
* The radius, opacity, softness, and color of the vignette can be adjusted.
Expand All @@ -161,6 +162,7 @@ You can also hover over a snake's preview image to see their latency for the cur
* This will draw snake bodies using curves when they make turns on the game board. Doesn't impact performance.

### Audio
Note: Audio can be quickly toggled by using the F4 key. This will toggle both the SFX and the music at once.
* Enable Music
* When enabled, plays background music on the menu and during the game.
* Enable SFX
Expand Down
2 changes: 1 addition & 1 deletion packager/lp-config.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ copyrightYear="2017-2021"
# (It should be fine to leave this as its default.)
identifier="org.scottsmall.mojave3"
# Current version (of your program)
version="3.3"
version="3.3.1"

###### Important! ONLY USE ABSOLUATE PATHS ######
# Where to place the resulting executables.
Expand Down
22 changes: 19 additions & 3 deletions src/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,8 @@ function love.resize(width, height)
screenHeight = height
if activeGame then
activeGame:resize(width, height)
else
Menu.resize(width, height)
end
Menu.resize(width, height)
end

function love.quit()
Expand All @@ -180,7 +179,24 @@ function love.keypressed(key)
end
imgui.KeyPressed(key)
if not imgui.GetWantCaptureKeyboard() then
-- Pass event to the game

-- Keys used during both the menu and the game
if key == 'f4' then
if config.audio.enableMusic or config.audio.enableSFX then
config.audio.enableMusic = false
config.audio.enableSFX = false
else
config.audio.enableMusic = true
config.audio.enableSFX = true
end
elseif key == 'f5' then
local fullscreen = not love.window.getFullscreen()
config.appearance.fullscreen = fullscreen
love.window.setFullscreen( fullscreen )
love.resize(love.graphics.getDimensions())
end

-- Keys used in-game only (i.e. human player controls)
if activeGame then
activeGame:keypressed(key)
end
Expand Down
117 changes: 95 additions & 22 deletions src/modules/Game.lua
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ function Game.new( opt )
local self = setmetatable( {}, Game )
self.opt = opt or {}

self.drawExitDialogOnNextFrame = false

-- Create game thread
self.thread = love.thread.newThread("thread.lua")
self.channel = love.thread.getChannel("game")
Expand Down Expand Up @@ -92,6 +94,66 @@ function Game.new( opt )
return self
end

-- Previous UI button
-- returns to the start of the current game
function Game:btnPrevious()
self.state = self.history[1]
end

-- Rewind UI button
-- goes back 1 turn
function Game:btnRewind()
local index = self.state.turn
if index < 1 then
index = 1
end
self.state = self.history[index]
end

-- Pause UI button
function Game:btnPause()
self.running = false
end

-- Forward UI button
-- resumes the paused game or returns to start if game is over
function Game:btnForward()
local index = self.state.turn + 2
if index > #self.history then
self.state = self.history[1]
end
self.running = true
end

-- Fast Forward UI button
-- advances 1 turn (or does nothing if the next turn hasn't been played yet)
function Game:btnFastForward()
local index = self.state.turn + 2
if index > #self.history then
index = #self.history
end
self.state = self.history[index]
end

-- Next UI button
-- advances to the current turn
function Game:btnNext()
self.state = self.history[#self.history]
end

-- Return UI button
-- ends the current game and immediately starts a new game with the same configuration
function Game:btnReturn()
self:shutdownThread()
activeGame = Game(self.opt)
end

-- Cross UI button
-- prompts the user if they would like to return to the main menu
function Game:btnCross()
self.drawExitDialogOnNextFrame = true
end

-- Check if we need to play a sound. The gameplay is happening in a thread
-- ahead of real time, but we want sounds to play when the user sees an event
-- happen.
Expand Down Expand Up @@ -156,53 +218,44 @@ function Game:draw()

-- Playback, rematch, and return-to-menu controls
if imgui.ImageButton( imgPrevious, 16, 16 ) then
self.state = self.history[1]
self:btnPrevious()
end
imgui.SameLine()
if imgui.ImageButton( imgRewind, 16, 16 ) then
local index = self.state.turn
if index < 1 then
index = 1
end
self.state = self.history[index]
self:btnRewind()
end
imgui.SameLine()
if self.running then
if imgui.ImageButton( imgPause, 16, 16 ) then
self.running = false
self:btnPause()
end
else
if imgui.ImageButton( imgForward, 16, 16 ) then
local index = self.state.turn + 2
if index > #self.history then
self.state = self.history[1]
end
self.running = true
self:btnForward()
end
end
imgui.SameLine()
if imgui.ImageButton( imgFastForward, 16, 16 ) then
local index = self.state.turn + 2
if index > #self.history then
index = #self.history
end
self.state = self.history[index]
self:btnFastForward()
end
imgui.SameLine()
if imgui.ImageButton( imgNext, 16, 16 ) then
self.state = self.history[#self.history]
self:btnNext()
end
imgui.SameLine()
if imgui.ImageButton( imgReturn, 16, 16 ) then
self:shutdownThread()
activeGame = Game(self.opt)
self:btnReturn()
end
imgui.SameLine()
if imgui.ImageButton( imgCross, 16, 16 ) then
imgui.OpenPopup( "ReturnMenu" )
self:btnCross()
end
imgui.PopStyleVar()

if self.drawExitDialogOnNextFrame == true then
imgui.OpenPopup( "ReturnMenu" )
end

-- Return to Menu dialog
if imgui.BeginPopupModal( "ReturnMenu", nil, { "NoResize" } ) then
imgui.Text( "Are you sure you want to return to the menu?\n\n" )
Expand All @@ -214,6 +267,7 @@ function Game:draw()
end
imgui.SameLine()
if imgui.Button( "Cancel" ) then
self.drawExitDialogOnNextFrame = false
imgui.CloseCurrentPopup()
end
imgui.EndPopup()
Expand Down Expand Up @@ -361,9 +415,28 @@ function Game:drawLatency(snake)
end

-- Keypress handler - allows a human player to control a snake
-- also handles shortcut keys for UI functions
-- @param key The key that was pressed
function Game:keypressed(key)
if self.running then
if key == 'f6' then
self:btnPrevious()
elseif key == 'f7' then
self:btnRewind()
elseif key == 'f8' then
if self.running then
self:btnPause()
else
self:btnForward()
end
elseif key == 'f9' then
self:btnFastForward()
elseif key == 'f10' then
self:btnNext()
elseif key == 'f11' then
self:btnReturn()
elseif key == 'f12' then
self:btnCross()
elseif self.running then
self.humanChannel:push(key)
end
end
Expand Down
2 changes: 1 addition & 1 deletion src/modules/Utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ local Utils = {}
local ffi = require 'ffi'

-- Version constant
Utils.MOJAVE_VERSION = '3.3'
Utils.MOJAVE_VERSION = '3.3.1'

-- Shared Library Hashes (used for library updates)
-- If these change, we'll re-extract the corresponding library when the app starts.
Expand Down

0 comments on commit 06d15d3

Please sign in to comment.