Skip to content

Commit

Permalink
Merge pull request #6 from veu/next
Browse files Browse the repository at this point in the history
Version 1.3.0
  • Loading branch information
veu authored Jun 4, 2022
2 parents fb75f6a + e206160 commit 515495a
Show file tree
Hide file tree
Showing 10 changed files with 105 additions and 8 deletions.
5 changes: 4 additions & 1 deletion src/constants.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
VERSION = "1.2.1"
VERSION = "1.3.0"

CELL = 16
TOP_NUMBER_HEIGHT = 14
Expand Down Expand Up @@ -62,8 +62,11 @@ PLAYER_ID_QUICK_PLAY = "YWPAGTGGLDOLBBZL"
PLAYER_ID_SHOW_NAME = "NAME"
PLAYER_ID_SHOW_RENAME = "RENAME"

AVATAR_ID_CREATE_AVATAR = "CREATE_AVATAR"

OPTION_ID_RESET_PROGRESS = "RESET_PROGRESS"
OPTION_ID_RENAME_PROFILE = "RENAME_PROFILE"
OPTION_ID_CHANGE_AVATAR = "CHANGE_AVATAR"

HINTS_ID_OFF = 1
HINTS_ID_LINES = 2
Expand Down
2 changes: 2 additions & 0 deletions src/imports.lua
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import "screen/title"

import "sidebar/sidebar"
import "sidebar/about"
import "sidebar/change-avatar"
import "sidebar/create-avatar"
import "sidebar/create-puzzle"
import "sidebar/name-puzzle"
Expand Down Expand Up @@ -97,6 +98,7 @@ fontTime = gfx.font.new("font/time")
assert(fontTime)
imgAvatars, err = gfx.imagetable.new("img/avatars")
assert(imgAvatars, err)
nilAvatar = saveAvatar(imgAvatars:getImage(AVATAR_ID_NIL))
imgGrid, err = gfx.imagetable.new("img/grid")
assert(imgGrid, err)
imgCursor, err = gfx.imagetable.new("img/cursor")
Expand Down
31 changes: 29 additions & 2 deletions src/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ local titleScreen = TitleScreen()

-- sidebars
local aboutSidebar = AboutSidebar()
local changeAvatarSidebar = ChangeAvatarSidebar()
local createAvatarSidebar = CreateAvatarSidebar()
local createPuzzleSidebar = CreatePuzzleSidebar()
local namePlayerSidebar = SelectPlayerSidebar()
Expand Down Expand Up @@ -208,7 +209,7 @@ local onHintStyleNext = function ()
end

createAvatarScreen.onChanged = function()
switch(nil, createAvatarSidebar)
switch(nil, context.sidebar)
end

createPuzzleScreen.onChanged = function ()
Expand All @@ -233,8 +234,29 @@ aboutSidebar.onAbort = function ()
switch(titleScreen, titleSidebar, ACTION_ID_ABOUT, true)
end

changeAvatarSidebar.onAbort = function ()
switch(titleScreen, optionsSidebar, OPTION_ID_CHANGE_AVATAR, true)
end

changeAvatarSidebar.onInvertGrid = function ()
context.screen:invertGrid()
switch(nil, changeAvatarSidebar, ACTION_ID_INVERT_COLORS)
end

changeAvatarSidebar.onResetGrid = function()
context.screen:resetGrid()
switch(nil, changeAvatarSidebar, ACTION_ID_RESET_GRID)
end

changeAvatarSidebar.onSave = function()
context.player:setAvatar(createAvatarPreview(context.puzzle))
context.player:save(context)

switch(titleScreen, optionsSidebar, OPTION_ID_CHANGE_AVATAR, true)
end

createAvatarSidebar.onAbort = function ()
switch(titleScreen, selectAvatarSidebar, nil, true)
switch(titleScreen, selectAvatarSidebar, AVATAR_ID_CREATE_AVATAR, true)
end

createAvatarSidebar.onInvertGrid = function ()
Expand Down Expand Up @@ -291,6 +313,11 @@ optionsSidebar.onAbort = function ()
switch(nil, selectModeSidebar, MODE_OPTIONS, true)
end

optionsSidebar.onChangeAvatar = function ()
context.puzzle = nil
switch(createAvatarScreen, changeAvatarSidebar)
end

optionsSidebar.onDelete = function ()
local delete = function ()
context.player:delete(context)
Expand Down
2 changes: 1 addition & 1 deletion src/model/profile.lua
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ end
function Profile.createEmpty()
return Profile({
id = playdate.string.UUID(16),
avatar = saveAvatar(imgAvatars:getImage(AVATAR_ID_NIL)),
avatar = nilAvatar,
name = "Player",
created = {},
played = {}
Expand Down
14 changes: 14 additions & 0 deletions src/model/puzzle.lua
Original file line number Diff line number Diff line change
Expand Up @@ -114,3 +114,17 @@ Puzzle.createEmpty = function (width, height)
title = "",
})
end

Puzzle.createFromAvatar = function (avatar)
if avatar == nilAvatar then
return Puzzle.createEmpty(10, 10)
end

return Puzzle({
id = playdate.string.UUID(16),
grid = avatar,
width = 10,
height = 10,
title = "",
})
end
4 changes: 2 additions & 2 deletions src/pdxinfo
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ author=RDK
description=A nonogram game you sketch yourself
bundleID=net.monometric.sketch-share-solve
imagePath=launcherAssets/
version=1.2.1
buildNumber=102011
version=1.3.0
buildNumber=103000
2 changes: 1 addition & 1 deletion src/screen/create-avatar.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ function CreateAvatarScreen:init()
end

function CreateAvatarScreen:enter(context)
self.puzzle = Puzzle.createEmpty(10, 10)
self.puzzle = Puzzle.createFromAvatar(context.player._avatar)
context.puzzle = self.puzzle
self.grid.onUpdateSolution = function ()
self.puzzle.grid = self.grid.solution
Expand Down
42 changes: 42 additions & 0 deletions src/sidebar/change-avatar.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
class("ChangeAvatarSidebar").extends(Sidebar)

function ChangeAvatarSidebar:init()
ChangeAvatarSidebar.super.init(self)
end

function ChangeAvatarSidebar:enter(context, selected)
local config = {
player = createAvatarPreview(context.puzzle) or context.player.avatar,
menuTitle = "Change avatar",
menuItems = {
{
text = "Sketch",
exec = function()
closeSidebar()
end
},
{
text = "Save",
exec = function()
self.onSave()
end
},
{
text = "Invert colors",
selected = selected == ACTION_ID_INVERT_COLORS,
exec = function()
self.onInvertGrid()
end
},
{
text = "Reset avatar",
selected = selected == ACTION_ID_RESET_GRID,
exec = function()
self.onResetGrid()
end
}
}
}

ChangeAvatarSidebar.super.enter(self, context, config)
end
8 changes: 8 additions & 0 deletions src/sidebar/options.lua
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,14 @@ function OptionsSidebar:enter(context, selected)
})
end

table.insert(config.menuItems, {
text = "Change avatar",
selected = selected == OPTION_ID_CHANGE_AVATAR,
exec = function ()
self.onChangeAvatar()
end
})

table.insert(config.menuItems, {
text = "Rename profile",
selected = selected == OPTION_ID_RENAME_PROFILE,
Expand Down
3 changes: 2 additions & 1 deletion src/sidebar/select-avatar.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ function SelectAvatarSidebar:init()
self.onNewPlayer = function () end
end

function SelectAvatarSidebar:enter(context)
function SelectAvatarSidebar:enter(context, selected)
local config = {
player = imgAvatars:getImage(1),
menuItems = {},
Expand All @@ -22,6 +22,7 @@ function SelectAvatarSidebar:enter(context)

table.insert(config.menuItems, {
text = "Create new avatar",
selected = selected == AVATAR_ID_CREATE_AVATAR,
avatar = imgAvatars:getImage(AVATAR_ID_NIL),
exec = function()
self.onNewAvatar()
Expand Down

0 comments on commit 515495a

Please sign in to comment.