Skip to content

Commit

Permalink
Editor buttons
Browse files Browse the repository at this point in the history
  • Loading branch information
29cmb committed Jul 25, 2024
1 parent 1deef4d commit 80baee7
Show file tree
Hide file tree
Showing 5 changed files with 111 additions and 12 deletions.
69 changes: 69 additions & 0 deletions .github/workflows/build-love-file.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
name: Create .love file and build to .exe

on:
push:
branches:
- main
pull_request:
branches:
- main

jobs:
create-love:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: Install zip utility
run: sudo apt-get install zip -y

- name: Create .love file
run: |
zip -r game.love *
mv game.love ${GITHUB_REPOSITORY#*/}-$(date +%Y%m%d%H%M%S).love
- name: Upload .love file as artifact
uses: actions/upload-artifact@v2
with:
name: .LOVE file
path: |
*.love
convert-love:
runs-on: ubuntu-latest
needs: create-love

steps:
- name: Download .love file from previous job
uses: actions/download-artifact@v2
with:
name: .LOVE file
path: .

- name: Install zip utility
run: sudo apt-get install zip -y

- name: Download LOVE.exe
run: |
mkdir love
cd love
curl -L -o love-win.zip https://github.com/love2d/love/releases/download/11.5/love-11.5-win64.zip
unzip love-win.zip
mv love-11.5-win64/* .
cd ..
- name: Create .exe file
run: |
cp love/love.exe game.exe
cat ${GITHUB_REPOSITORY#*/}-*.love >> game.exe
cp love/*.dll .
- name: Upload .exe file as artifact
uses: actions/upload-artifact@v2
with:
name: Game Build
path: |
game.exe
*.dll
30 changes: 28 additions & 2 deletions editor.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
local editor = {}
local Sprites = require("modules.sprite")
local utils = require("modules.utils")
editor.InEditor = true

editor.CameraData = {
Expand All @@ -24,12 +25,31 @@ function editor:Load()
["Hazards"] = {},
["Gates"] = {}
} -- return level to defaults when the editor loads

buttons = {
{
["Sprite"] = Sprites.Player,
["Transform"] = {10, 10, 50, 50},
["IsVisible"] = function()
return true
end,
["Callback"] = function()
print("Calling back!")
end
}
}
end

local firstDrawCall = true

function editor:Draw()
love.graphics.setColor(1, 1, 1, 0.5)
love.graphics.draw(Sprites.Player, level.Start.X + self.CameraData.CameraX, level.Start.Y + self.CameraData.CameraY)
love.graphics.setColor(1,1,1,1)

for _,button in pairs(buttons) do
love.graphics.draw(button.Sprite, button.Transform[1], button.Transform[2])
end
end

local cX, cY = 0, 0
Expand All @@ -47,8 +67,14 @@ function editor:Update(dt)
cX, cY = 0, 0
end

function editor:Keypressed(key)

function editor:MousePressed(x, y, button)
if button == 1 then
for _,btn in pairs(buttons) do
if btn.IsVisible() == true and utils:CheckCollision(x, y, 1, 1, btn.Transform[1], btn.Transform[2], btn.Transform[3], btn.Transform[4]) then
btn.Callback()
end
end
end
end

return editor
4 changes: 4 additions & 0 deletions main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ function love.keypressed(key)
end
end

function love.mousepressed(x, y, button)
if editor.InEditor == true then editor:MousePressed(x, y, button) end
end

function beginContact(a, b)
if a:getUserData() == "Player" and b:getUserData() == "Hazard" then
player:YieldRespawn()
Expand Down
10 changes: 0 additions & 10 deletions modules/collision.lua

This file was deleted.

10 changes: 10 additions & 0 deletions modules/utils.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
local utils = {}

function utils:CheckCollision(x1, y1, w1, h1, x2, y2, w2, h2)
return x1 < x2+w2 and
x2 < x1+w1 and
y1 < y2+h2 and
y2 < y1+h1
end

return utils

0 comments on commit 80baee7

Please sign in to comment.