Skip to content
This repository has been archived by the owner on Jan 4, 2023. It is now read-only.

Commit

Permalink
Added save support.
Browse files Browse the repository at this point in the history
  • Loading branch information
jessefreeman committed Oct 4, 2021
1 parent 3b100f9 commit 9772466
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 108 deletions.
4 changes: 4 additions & 0 deletions Game/Src/scene-editor.lua
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,10 @@ function EditorScene:Update(timeDelta)
self.startTimer = 0
self.startCount = self.startCounts


-- Save the tilemap

SaveLevel()

-- TODO clear data if we are going back to load screen and go to the loader instead of the splash screen
-- Switch to play scene
Expand Down
13 changes: 10 additions & 3 deletions Game/Src/scene-loader.lua
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@ function LoaderScene:Init()
flickerTime = 0,
flickerDelay = 400,
flickerVisible = true,
-- Load the image using the bg as the mask
defaultMapImage = ReadImage(NewWorkspacePath("/Game/template.png"), Color(2)) -- TODO need to figure out how to pass an image into this
imagePath = NewWorkspacePath("/Game/map.spacestation8.png"),
}

-- Load the image using the bg as the mask
_loader.defaultMapImage = ReadImage(_loader.imagePath, Color(2))

-- Remap the colors of the template image when first loaded
_loader.defaultMapImage.RemapColors({MaskColor(),Color(0), Color(1), Color(2), Color(3)})

Expand Down Expand Up @@ -139,7 +141,8 @@ function LoaderScene:Reset()


-- Tile Editor
NewMetaSprite("tile-picker", {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19}, 20)
NewMetaSprite("tile-picker", {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39}, 20)

NewMetaSprite("bottom-hud", {39, 39, 39, 39, 39, 39, 39, 35, 37, 37, 37, 37, 37, 39, 39, 39, 39, 39, 39, 39}, 20)

Expand Down Expand Up @@ -173,6 +176,10 @@ function LoaderScene:Reset()
-- nextSceneId = tonumber(ReadSaveData("lastSceneId", tostring(SPLASH)))
-- end

-- self.imagePath = UniqueFilePath(NewWorkspacePath())

SaveLevel(NewWorkspacePath("/User/Levels/" .. self.imagePath.EntityName))

SwitchScene(SPLASH)

end
Expand Down
103 changes: 0 additions & 103 deletions Game/Src/scene-over.lua

This file was deleted.

6 changes: 4 additions & 2 deletions Game/Src/scene-splash.lua
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ function SplashScene:Init()
flickerVisible = true,
selectLock = false,
startLock = false
-- Load the image using the bg as the mask
-- mapImage = ReadImage(NewWorkspacePath("/Game/template.png"), Color(2))
}

setmetatable(_splash, SplashScene) -- make Account handle lookup
Expand All @@ -32,6 +30,10 @@ end

function SplashScene:Reset()

print("Create new image")



self.selectLock = Button(Buttons.Select, InputState.Down)
self.startLock = Button(Buttons.Start, InputState.Down)

Expand Down
59 changes: 59 additions & 0 deletions Game/code.lua
Original file line number Diff line number Diff line change
Expand Up @@ -214,3 +214,62 @@ function OnLoadImage(value)
-- DrawPixels(value.GetPixels(), 0, 0, value.Width, value.Height, false, false, DrawMode.TilemapCache)

end

local lastImagePath = "/User/Levels/map.spacestation8.png"

function SaveLevel(newPath)

if(newPath) then

lastImagePath = UniqueFilePath(newPath)

end

local mapImage = NewCanvas(TilemapSize().X * 8, TilemapSize().Y * 8)


-- Copy the tilemap to the canvas
local total = TilemapSize().X * TilemapSize().Y

for i = 1, total do

local pos = CalculatePosition(i-1, TilemapSize().X)
local sprite = Tile(pos.X, pos.Y).SpriteId

mapImage.DrawSprite(sprite, pos.X * 8, pos.Y * 8)

end

-- Draw the UI on top of the image
mapImage.DrawMetaSprite("top-bar", 0, 0)

local message = "PLAY AT SPACESTATION8.DOWNLOAD"
mapImage.DrawText(message, (Display().X - (#message * 4)) * .5, -1, "medium", 3, -4)

mapImage.DrawMetaSprite("tile-picker", 0, (TilemapSize().Y - 2) * 8)

local tmpImage = NewImage(mapImage.Width, mapImage.Height, mapImage.GetPixels(), {MaskColor(),Color(0), Color(1), Color(2), Color(3)})




-- local mapImage = NewCanvas(TilemapSize().X * 8, TilemapSize().Y * 8)

-- local total = TilemapSize().X * TilemapSize().Y

-- for i = 1, total do

-- local pos = CalculatePosition(i-1, TilemapSize().X)
-- local sprite = Tile(pos.X, pos.Y).SpriteId

-- mapImage.DrawSprite(sprite, pos.X * 8, pos.Y * 8)

-- end

-- local tmpImage = NewImage(mapImage.Width, mapImage.Height, mapImage.GetPixels(), {MaskColor(),Color(0), Color(1), Color(2), Color(3)})

-- SaveImage(scenes[LOADER].imagePath, tmpImage)

SaveImage(lastImagePath, tmpImage)

end
File renamed without changes

0 comments on commit 9772466

Please sign in to comment.