Skip to content

Commit 753936a

Browse files
feat: start project
1 parent db135ba commit 753936a

12 files changed

+336
-0
lines changed

.github/funding.yml

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
github: rodrigodornelles

.github/workflows/docs.yml

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
name: cd
2+
3+
on:
4+
workflow_dispatch:
5+
push:
6+
branches:
7+
- main
8+
9+
jobs:
10+
pages:
11+
runs-on: ubuntu-latest
12+
if: github.event_name == 'push' || github.event.pull_request.draft == false
13+
steps:
14+
-
15+
uses: actions/checkout@master
16+
-
17+
run: |
18+
npm install
19+
-
20+
run: |
21+
npm run build
22+
-
23+
uses: actions/configure-pages@v3
24+
-
25+
uses: actions/upload-pages-artifact@v2
26+
with:
27+
path: 'src'
28+
-
29+
id: deployment
30+
uses: actions/deploy-pages@v2

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
package-lock.json
2+
13
# Logs
24
logs
35
*.log

README.md

75 Bytes

package.json

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{
2+
"name": "@gamely/gly-ide",
3+
"license": "MIT",
4+
"homepage": "https://ide.gamely.com.br",
5+
"repository": "https://github.com/gamelly/gly-ide",
6+
"funding": "https://github.com/sponsors/RodrigoDornelles",
7+
"bugs": "https://github.com/gamelly/gly-ide/issues",
8+
"devDependencies": {
9+
"@gamely/core-native-html5": "^0.0.10",
10+
"@gamely/gly-engine": "^0.0.10",
11+
"copy-webpack-plugin": "11.0.0",
12+
"css-loader": "6.7.3",
13+
"html-webpack-plugin": "5.5.0",
14+
"monaco-editor": "0.35.0",
15+
"monaco-editor-webpack-plugin": "7.0.1",
16+
"style-loader": "3.3.1",
17+
"wasmoon": "1.16.0",
18+
"webpack": "^5.95.0",
19+
"webpack-cli": "5.0.1",
20+
"webpack-dev-server": "^5.1.0"
21+
},
22+
"scripts": {
23+
"serve": "webpack serve --mode=development --watch --progress --open",
24+
"start": "webpack --mode=development --watch --progress",
25+
"build": "webpack --mode=production"
26+
}
27+
}

src/assets/CascadiaMono.ttf

364 KB
Binary file not shown.

src/assets/index.css

+71
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
*,
2+
*::after,
3+
*::before {
4+
touch-action: none;
5+
box-sizing: border-box;
6+
border: 0;
7+
padding: 0;
8+
margin: 0;
9+
}
10+
11+
body {
12+
background-color: #222;
13+
color: #f5f5f5;
14+
font-family: "Cascadia Code", monospace;
15+
}
16+
17+
main {
18+
height: 100vh;
19+
width: 80vmin;
20+
margin: auto auto;
21+
overflow: hidden;
22+
}
23+
24+
#editor-block {
25+
display: block;
26+
height: 50vh;
27+
}
28+
29+
#gameCanvas {
30+
width: 100%
31+
}
32+
33+
#game {
34+
height: 50vh;
35+
}
36+
37+
#editor {
38+
width: 100%;
39+
height: 100%;
40+
}
41+
42+
#buttons {
43+
display: flex;
44+
gap: 10px;
45+
}
46+
47+
form {
48+
display: flex;
49+
gap: 10px;
50+
}
51+
52+
input,
53+
select {
54+
width: 64px;
55+
padding: 5px;
56+
border: 1px solid #ccc;
57+
border-radius: 4px;
58+
}
59+
60+
button {
61+
padding: 5px 10px;
62+
background-color: #007bff;
63+
color: white;
64+
border: none;
65+
border-radius: 4px;
66+
cursor: pointer;
67+
}
68+
69+
button:hover {
70+
background-color: #0056b3;
71+
}

src/assets/logo.png

70.3 KB
Loading

src/default.lua

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
std.draw.clear(std.color.blue)
2+
std.draw.color(std.color.white)
3+
std.draw.font(48)
4+
std.draw.text(8 , 8, 'Hello world!')

src/index.html

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<!doctype html>
2+
<html lang="pt-BR">
3+
<head>
4+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
5+
<meta charset="UTF-8" />
6+
<meta name="description" content="Tente Lua online" />
7+
<link rel="icon" type="image/png" href="./assets/logo.png" />
8+
<title>IDE - Gly Game Engine</title>
9+
<link rel="preload" href="/assets/CascadiaMono.ttf" as="font" type="font/ttf" crossorigin />
10+
<style>
11+
@font-face {
12+
font-family: "Cascadia Code";
13+
src: url(assets/CascadiaMono.ttf);
14+
}
15+
</style>
16+
<link rel="stylesheet" href="./assets/index.css" />
17+
</head>
18+
<body>
19+
<main>
20+
<div id="game">
21+
<canvas id="gameCanvas"></canvas>
22+
</div>
23+
<div id="buttons">
24+
<form>
25+
<select id="resolution" name="resolution">
26+
<option value="48x48">48x48</option>
27+
<option value="80x80">80x80</option>
28+
<option value="128x128">128x128</option>
29+
<option value="256x256">256x256</option>
30+
<option value="512x512" selected>512x512</option>
31+
</select>
32+
<select id="format" name="format">
33+
<option value="png">png</option>
34+
<option value="bmp">bmp</option>
35+
</select>
36+
<label for="width">Width:</label>
37+
<input type="number" id="width" name="width" value="512" required>
38+
<label for="height">Height:</label>
39+
<input type="number" id="height" name="height" value="512" required>
40+
<button id="download">download</button>
41+
</form>
42+
</div>
43+
<div id="editor-block">
44+
<div id="editor"></div>
45+
</div>
46+
</main>
47+
<script type="module" src="index.js"></script>
48+
</body>
49+
</html>

src/index.js

+95
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
import wasmFile from 'wasmoon/dist/glue.wasm';
2+
import { LuaFactory, LuaMultiReturn } from 'wasmoon'
3+
import { editor } from 'monaco-editor'
4+
import gly from '@gamely/core-native-html5'
5+
import gly_engine from '@gamely/gly-engine/dist/main.lua'
6+
import defaultScript from './default.lua'
7+
8+
let monacoTimeout;
9+
10+
document.addEventListener('DOMContentLoaded', async () => {
11+
const elInpWidth = document.querySelector('#width')
12+
const elInpHeight = document.querySelector('#height')
13+
const elSelFormat = document.querySelector('#resolution')
14+
const elBtnDownload = document.querySelector('#download')
15+
const elSelResolution = document.querySelector('#resolution')
16+
const elMonacoEditor = document.querySelector('#editor')
17+
const elCanvas = document.querySelector('#gameCanvas')
18+
19+
const monacoEditor = editor.create(elMonacoEditor, {
20+
language: 'lua',
21+
theme: 'vs-dark',
22+
automaticLayout: true,
23+
fontLigatures: true,
24+
fontFamily: 'Cascadia Code'
25+
});
26+
27+
monacoEditor.setValue(defaultScript)
28+
29+
const factory = new LuaFactory(wasmFile)
30+
const lua = await factory.createEngine()
31+
await lua.doString(gly_engine)
32+
33+
gly.global.set('native_callback_init', lua.global.get('native_callback_init'))
34+
gly.global.set('native_callback_loop', lua.global.get('native_callback_loop'))
35+
gly.global.set('native_callback_draw', lua.global.get('native_callback_draw'))
36+
gly.global.set('native_callback_resize', lua.global.get('native_callback_resize'))
37+
gly.global.set('native_callback_keyboard', lua.global.get('native_callback_keyboard'))
38+
lua.global.set('native_draw_start', gly.global.get('native_draw_start'))
39+
lua.global.set('native_draw_flush', gly.global.get('native_draw_flush'))
40+
lua.global.set('native_draw_clear', gly.global.get('native_draw_clear'))
41+
lua.global.set('native_draw_color', gly.global.get('native_draw_color'))
42+
lua.global.set('native_draw_font', gly.global.get('native_draw_font'))
43+
lua.global.set('native_draw_rect', gly.global.get('native_draw_rect'))
44+
lua.global.set('native_draw_line', gly.global.get('native_draw_line'))
45+
lua.global.set('native_draw_image', gly.global.get('native_draw_image'))
46+
lua.global.set('native_dict_http', gly.global.get('native_dict_http'))
47+
lua.global.set('native_dict_json', gly.global.get('native_dict_json'))
48+
lua.global.set('native_dict_poly', gly.global.get('native_dict_poly'))
49+
lua.global.set('native_draw_text', (x, y, text) => {
50+
const native_draw_text = gly.global.get('native_draw_text')
51+
return LuaMultiReturn.from(native_draw_text(x, y, text))
52+
})
53+
54+
gly.error('canvas')
55+
gly.init('#gameCanvas')
56+
57+
const apply = () => {
58+
const code = monacoEditor.getValue()
59+
gly.load(`return {draw=function(std)\nprint('oi')\n${code}\nend}`)
60+
elCanvas.width = elInpWidth.value;
61+
elCanvas.height= elInpHeight.value;
62+
window.requestAnimationFrame(gly.update)
63+
}
64+
65+
monacoEditor.onDidChangeModelContent(() => {
66+
clearTimeout(monacoTimeout);
67+
monacoTimeout = setTimeout(() => {
68+
apply()
69+
}, 100);
70+
});
71+
72+
elSelResolution.addEventListener('change', () => {
73+
const [width, height] = elSelResolution.value.split('x').map(Number);
74+
elInpWidth.value = width;
75+
elInpHeight.value = height;
76+
apply();
77+
})
78+
79+
elBtnDownload.addEventListener('click', (ev) => {
80+
ev.preventDefault();
81+
const ext = elSelFormat.value
82+
const url = elCanvas.toDataURL(`image/${ext}`)
83+
const downloadLink = document.createElement('a')
84+
downloadLink.href = url
85+
downloadLink.target = '_blank'
86+
downloadLink.download = `icon.${ext}`
87+
downloadLink.click()
88+
URL.revokeObjectURL(url)
89+
})
90+
91+
elInpWidth.addEventListener('change', apply);
92+
elInpHeight.addEventListener('change', apply);
93+
94+
apply();
95+
})

webpack.config.js

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
const MonacoWebpackPlugin = require('monaco-editor-webpack-plugin');
2+
const HtmlWebpackPlugin = require('html-webpack-plugin');
3+
const CopyWebpackPlugin = require('copy-webpack-plugin');
4+
const path = require('path');
5+
6+
/** @type {import('webpack').Configuration} */
7+
const config = {
8+
entry: './src/index.js',
9+
output: {
10+
path: path.resolve(__dirname, 'dist'),
11+
filename: 'app.js'
12+
},
13+
resolve: {
14+
fallback: {
15+
path: false,
16+
fs: false,
17+
child_process: false,
18+
crypto: false,
19+
url: false,
20+
module: false
21+
}
22+
},
23+
module: {
24+
rules: [
25+
{
26+
test: /\.css$/,
27+
use: ['style-loader', 'css-loader']
28+
},
29+
{
30+
test: /\.(ttf|wasm)$/,
31+
type: 'asset/resource',
32+
},
33+
{
34+
test: /\.lua$/,
35+
type: 'asset/source'
36+
}
37+
]
38+
},
39+
plugins: [
40+
new MonacoWebpackPlugin({
41+
languages: ['lua']
42+
}),
43+
new HtmlWebpackPlugin({
44+
template: 'src/index.html'
45+
}),
46+
new CopyWebpackPlugin({
47+
patterns: [
48+
{ from: 'src/assets', to: 'assets' },
49+
],
50+
}),
51+
],
52+
experiments: {
53+
asyncWebAssembly: true
54+
}
55+
};
56+
57+
module.exports = config;

0 commit comments

Comments
 (0)