Skip to content

Commit

Permalink
feat: revision 0.0.5 (#68)
Browse files Browse the repository at this point in the history
* ci: upgrade lua in CI to 5.4.7
* ci: dont use secrets in thirdy PRs
* feat: fps_counter making the code less complex
* feat: add core native #38
* feat: support table in module gameload
* feat: improve inputs in html5 for TVs
* feat: add support to utf8 in ginga #65
* feat: asyncronous curl in love #42
* feat: vendor json rxi from https://github.com/rxi/json.lua
* fix: some errors in lib fps #51
* fix: lib http util url_search_param
* fix: no content length in header #59
* fix: ginga correct params in http protocol
* fix: http module ginga not supporting ipv4 url #53
* fix: color alpha in gray colors
* fix: align renders in example launcher
* docs: add new cli help message (#64)
* style: refact http_util.create_request #52 #65
* style: making the code less complex in the fps_counter (#51)
* change: move csv to third_party #32
* change: move native_draw_poly to native_dict_poly poly2 in html5 core

---------

Co-authored-by: Lucas Noal Potter <[email protected]>
Co-authored-by: Yago Crispim Rodrigues Souza <[email protected]>
  • Loading branch information
3 people authored Sep 12, 2024
1 parent c02c34b commit a1caa68
Show file tree
Hide file tree
Showing 26 changed files with 984 additions and 217 deletions.
6 changes: 4 additions & 2 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
-
uses: leafo/gh-actions-lua@v10
with:
luaVersion: "5.1.5"
luaVersion: "5.4.7"
-
uses: leafo/gh-actions-luarocks@v4
-
Expand All @@ -30,5 +30,7 @@ jobs:
-
run: |
./cli.sh test-self --coverage
- run: |
-
if: github.event_name == 'push' || github.event.pull_request.head.repo.full_name == github.repository
run: |
bash <(curl -s https://codecov.io/bash) -t ${{ secrets.CODECOV_TOKEN }}
2 changes: 2 additions & 0 deletions .github/workflows/DOCS.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ jobs:
run: |
docker run --rm -v $(pwd):/app -w /app rodrigodornelles/doxygen:lua doxygen
-
if: github.event_name == 'push' || github.event.pull_request.head.repo.full_name == github.repository
uses: cloudflare/pages-action@v1
with:
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
Expand All @@ -42,6 +43,7 @@ jobs:
run: |
docker run --rm -v $(pwd):/app -w /app rodrigodornelles/doxygen:lua ./cli.sh build --core html5 ./examples/pong/game.lua --dist ./html/
-
if: github.event_name == 'push' || github.event.pull_request.head.repo.full_name == github.repository
uses: cloudflare/pages-action@v1
with:
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
Expand Down
12 changes: 6 additions & 6 deletions examples/launcher/game.lua
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ local function loop(std, game)
next_state(game, 3)
elseif game._state == 3 then
halt_state(game)(function()
std.csv(game._csv, game._list)
std.csv.decode(game._csv, game._list)
game._csv = ''
next_state(game, 4)
end)
Expand Down Expand Up @@ -181,18 +181,18 @@ local function draw(std, game)
std.draw.color(std.color.white)
std.draw.text(8, 8, 'parsing csv...')
elseif game._state == 4 then
local s = 0
std.draw.clear(std.color.darkgray)
std.draw.clear(0x333333FF)
std.draw.color(std.color.white)
std.draw.font('Tiresias', 12)
local index = 1
while index <= #game._list do
std.draw.text(16, 8 + (index * 14), game._list[index].title)
std.draw.text(100, 8 + (index * 14), game._list[index].version)
s=std.math.max(std.draw.text(200, 8 + (index * 12), game._list[index].author), s)
std.draw.text(200, 8 + (index * 14), game._list[index].version)
std.draw.text(300, 8 + (index * 14), game._list[index].author)
index = index + 1
end
std.draw.color(std.color.red)
std.draw.rect(1, 16, 5 + (game._menu * 16), 200 + s, 14)
std.draw.rect(1, 16, 9 + (game._menu * 14), game.width - 32, 16)
elseif game._state == 5 then
std.draw.clear(std.color.blue)
std.draw.color(std.color.white)
Expand Down
34 changes: 30 additions & 4 deletions src/cli/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,11 @@ local core_list = {
'src/engine/core/ginga/main.ncl'
}
},
native={
src='src/engine/core/native/main.lua',
},
html5_webos={
src='src/engine/core/html5/main.lua',
src='src/engine/core/native/main.lua',
post_exe='webos24 $(pwd)/dist',
pipeline={
zeebo_meta.late(game):file(dist..'index.html'):file(dist..'appinfo.json'):pipe()
Expand All @@ -47,7 +50,7 @@ local core_list = {
}
},
html5_tizen={
src='src/engine/core/html5/main.lua',
src='src/engine/core/native/main.lua',
pipeline={
zeebo_meta.late(game):file(dist..'index.html'):file(dist..'config.xml'):pipe(),
function() os.execute('cd '..dist..';~/tizen-studio/tools/ide/bin/tizen.sh package -t wgt;true') end
Expand All @@ -62,7 +65,7 @@ local core_list = {
}
},
html5_ginga={
src='src/engine/core/html5/main.lua',
src='src/engine/core/native/main.lua',
post_exe='ginga dist/main.ncl -s '..screen,
pipeline={
zeebo_meta.late(game):file(dist..'index.html'):pipe()
Expand All @@ -75,7 +78,7 @@ local core_list = {
}
},
html5={
src='src/engine/core/html5/main.lua',
src='src/engine/core/native/main.lua',
pipeline={
zeebo_meta.late(game):file(dist..'index.html'):pipe()
},
Expand Down Expand Up @@ -196,6 +199,29 @@ elseif command == 'build' then
end
os.exit(os.execute(core.post_exe) and 0 or 1)
end
elseif command == "help" then
local help_message = "Available commands:\n" ..
"- run: Executes the specified core. If no core is specified, defaults to 'love'.\n" ..
"- clear | clean: Clears the specified distribution directory.\n" ..
"- meta: Displays metadata for the current game.\n" ..
"- bundler: Builds the game using the bundler.\n" ..
"- test-self: Runs tests located in the './tests' directory.\n" ..
"- build: Builds the game and prepares it for distribution.\n" ..
"\n" ..
"Available cores:\n" ..
"- repl: Runs the REPL core.\n" ..
"- love: Runs the Love2D core.\n" ..
"- ginga: Runs the Ginga core.\n" ..
"- html5_webos: Builds for HTML5 on WebOS.\n" ..
"- html5_tizen: Builds for HTML5 on Tizen.\n" ..
"- html5_ginga: Runs the Ginga core for HTML5.\n" ..
"- html5: Runs the standard HTML5 core.\n" ..
"- nintendo_wii: Builds for the Nintendo Wii.\n" ..
"\n" ..
"Usage:\n" ..
"- To run a command, use: ./cli.sh <command> <game_path> --core <core_name> [options]\n" ..
"- For example: ./cli.sh build ./examples/asteroids/game.lua --core ginga"
print(help_message)
else
print('command not found: '..command)
os.exit(1)
Expand Down
7 changes: 5 additions & 2 deletions src/engine/core/ginga/main.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
local zeebo_module = require('src/lib/engine/module')
local engine_csv = require('src/lib/engine/csv')
local engine_encoder = require('src/lib/engine/encoder')
local engine_fps = require('src/lib/engine/fps')
local engine_math = require('src/lib/engine/math')
local engine_game = require('src/lib/engine/game')
Expand All @@ -10,6 +10,8 @@ local engine_loop = require('src/engine/core/ginga/loop')
local engine_draw = require('src/engine/core/ginga/draw')
local engine_draw_fps = require('src/lib/engine/draw_fps')
local engine_draw_poly = require('src/lib/engine/draw_poly')
local library_csv = require('src/third_party/csv/rodrigodornelles')
local library_json = require('src/third_party/json/rxi')
local protocol_http_ginga = require('src/lib/protocol/http_ginga')
local application = nil
local game = require('src/lib/object/game')
Expand Down Expand Up @@ -87,7 +89,8 @@ local function install(evt, gamefile)
:package('@draw_fps', engine_draw_fps)
:package('@draw_poly', engine_draw_poly, polygons)
:package('load', zeebo_module.load)
:package('csv', engine_csv)
:package('csv', engine_encoder, library_csv)
:package('json', engine_encoder, library_json)
:package('math', engine_math.clib)
:package('random', engine_math.clib_random)
:package('http', engine_http, protocol_http_ginga)
Expand Down
92 changes: 53 additions & 39 deletions src/engine/core/html5/engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,32 +21,36 @@ document.addEventListener('DOMContentLoaded', async () => {
},
() => canvas_ctx.stroke()
]
const canvas_std = {
clear: (color) => {
canvas_ctx.fillStyle = '#' + color.toString(16).padStart(8, '0')
canvas_ctx.fillRect(0, 0, canvas_element.width, canvas_element.height)
},
color: (color) => {
const hex = '#' + color.toString(16).padStart(8, '0')
canvas_ctx.strokeStyle = hex
canvas_ctx.fillStyle = hex
},
line: (x1, y1, x2, y2) => {
canvas_ctx.beginPath()
canvas_ctx.moveTo(x1, y1)
canvas_ctx.lineTo(x2, y2)
canvas_ctx.stroke()
},
rect: (mode, x, y, w, h) => mode === 1?
canvas_ctx.strokeRect(x, y, w, h):
canvas_ctx.fillRect(x, y, w, h),
font: (name, size) => {},
text: (x, y, text) => {
const { width } = canvas_ctx.measureText(text || x)
x && y && canvas_ctx.fillText(text, x, y)
return width
},
poly: (mode, verts, x, y, scale = 1, angle = 0, ox = 0, oy = 0) => {

lua.global.set('native_draw_start', () => {})
lua.global.set('native_draw_flush', () => {})
lua.global.set('native_draw_clear', (color) => {
canvas_ctx.fillStyle = '#' + color.toString(16).padStart(8, '0')
canvas_ctx.fillRect(0, 0, canvas_element.width, canvas_element.height)
})
lua.global.set('native_draw_color', (color) => {
const hex = '#' + color.toString(16).padStart(8, '0')
canvas_ctx.strokeStyle = hex
canvas_ctx.fillStyle = hex
})
lua.global.set('native_draw_line', (x1, y1, x2, y2) => {
canvas_ctx.beginPath()
canvas_ctx.moveTo(x1, y1)
canvas_ctx.lineTo(x2, y2)
canvas_ctx.stroke()
})
lua.global.set('native_draw_rect', (mode, x, y, w, h) => mode === 1?
canvas_ctx.strokeRect(x, y, w, h):
canvas_ctx.fillRect(x, y, w, h)
)
lua.global.set('native_draw_font', (name, size) => {})
lua.global.set('native_draw_text', (x, y, text) => {
const { width } = canvas_ctx.measureText(text || x)
x && y && canvas_ctx.fillText(text, x, y)
return width
})
lua.global.set('native_dict_poly', {
poly2: (mode, verts, x, y, scale = 1, angle = 0, ox = 0, oy = 0) => {
let index = 0
canvas_ctx.beginPath()
while (index < verts.length) {
Expand All @@ -63,8 +67,8 @@ document.addEventListener('DOMContentLoaded', async () => {
}
canvas_close[mode]()
}
}
const browser_protocol_http = {
})
lua.global.set('native_dict_http', {
handler: (self) => {
const method = self.method
const headers = new Headers(self.headers_dict)
Expand Down Expand Up @@ -92,7 +96,11 @@ document.addEventListener('DOMContentLoaded', async () => {
self.resolve()
})
}
}
})
lua.global.set('native_dict_json', {
encode: JSON.stringify,
decode: JSON.parse
})

if (body_element.clientWidth > body_element.clientHeight) {
canvas_element.height = body_element.clientHeight
Expand All @@ -103,14 +111,21 @@ document.addEventListener('DOMContentLoaded', async () => {
canvas_element.width = body_element.clientWidth
}

lua.global.set('game_lua', game_lua)
lua.global.set('browser_canvas', canvas_std)
lua.global.set('browser_protocol_http', browser_protocol_http)
const engine_callbacks = await lua.doString(engine_lua)
engine_callbacks.init(canvas_element.width, canvas_element.height)
await lua.doString(engine_lua)
const engine_callbacks = {
init: lua.global.get('native_callback_init'),
update: lua.global.get('native_callback_loop'),
draw: lua.global.get('native_callback_draw'),
keyboard: lua.global.get('native_callback_keyboard'),
}
engine_callbacks.init(canvas_element.width, canvas_element.height, game_lua)

setTimeout(() => {
const keys = [
[403, 'red'],
[404, 'green'],
[405, 'yellow'],
[406, 'blue'],
['KeyZ', 'red'],
['KeyX', 'green'],
['KeyC', 'yellow'],
Expand All @@ -122,10 +137,9 @@ document.addEventListener('DOMContentLoaded', async () => {
['ArrowRight', 'right'],
];

const keyHandler = (ev) => {
const key = keys.find(key => key[0] == ev.code)
key && engine_callbacks.keyboard(key[1], Number(ev.type === 'keydown'))
}
const keyHandler = (ev) => keys
.filter(key => [ev.code, ev.keyCode].includes(key[0]))
.map(key => engine_callbacks.keyboard(key[1], Number(ev.type === 'keydown')))

window.addEventListener('keydown', keyHandler)
window.addEventListener('keyup', keyHandler)
Expand All @@ -139,5 +153,5 @@ document.addEventListener('DOMContentLoaded', async () => {
window.requestAnimationFrame(tick)
}

window.requestAnimationFrame(tick)
tick()
})
58 changes: 0 additions & 58 deletions src/engine/core/html5/main.lua

This file was deleted.

11 changes: 7 additions & 4 deletions src/engine/core/love/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@ local engine_keys = require('src/engine/core/love/keys')
local engine_loop = require('src/engine/core/love/loop')
local engine_color = require('src/lib/object/color')
local engine_http = require('src/lib/engine/http')
local engine_csv = require('src/lib/engine/csv')
local engine_encoder = require('src/lib/engine/encoder')
local engine_draw_fps = require('src/lib/engine/draw_fps')
local engine_draw_poly = require('src/lib/engine/draw_poly')
local protocol_curl = require('src/lib/protocol/http_curl')
local protocol_curl_love = require('src/lib/protocol/http_curl_love')
local library_csv = require('src/third_party/csv/rodrigodornelles')
local library_json = require('src/third_party/json/rxi')
local game = require('src/lib/object/game')
local std = require('src/lib/object/std')

Expand Down Expand Up @@ -46,8 +48,9 @@ function love.load(args)
:package('load', zeebo_module.load)
:package('math', engine_math.clib)
:package('random', engine_math.clib_random)
:package('http', engine_http, protocol_curl)
:package('csv', engine_csv)
:package('http', engine_http, protocol_curl_love)
:package('csv', engine_encoder, library_csv)
:package('json', engine_encoder, library_json)
:run()

game.width, game.height = w, h
Expand Down
Loading

0 comments on commit a1caa68

Please sign in to comment.