Skip to content

Commit dbdc077

Browse files
feat: revision 0.0.17 (#10)
* feat: bump 0.0.17 * feat: new file name for download * feat: line stroke config * feat: save code in url hash * docs: create dotgitattributes * docs: rename package.json
1 parent 5095f2a commit dbdc077

File tree

4 files changed

+39
-8
lines changed

4 files changed

+39
-8
lines changed

.gitattributes

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
*.html linguist-generated
2+
*.css linguist-generated
3+
*.lua linguist-generated

package.json

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
{
2-
"name": "@gamely/gly-ide",
2+
"name": "@gamely/tool-img-gen",
33
"license": "MIT",
4-
"homepage": "https://ide.gamely.com.br",
5-
"repository": "https://github.com/gamelly/gly-ide",
4+
"homepage": "https://gamelly.github.io/tool-img-gen",
5+
"repository": "https://github.com/gamelly/tool-img-gen",
66
"funding": "https://github.com/sponsors/RodrigoDornelles",
7-
"bugs": "https://github.com/gamelly/gly-ide/issues",
7+
"bugs": "https://github.com/gamelly/tool-img-gen/issues",
88
"devDependencies": {
9-
"@gamely/core-native-html5": "^0.0.16",
10-
"@gamely/gly-engine-lite": "^0.0.16",
9+
"@gamely/core-native-html5": "^0.0.17",
10+
"@gamely/gly-engine-lite": "^0.0.17",
1111
"copy-webpack-plugin": "11.0.0",
1212
"css-loader": "6.7.3",
1313
"html-webpack-plugin": "5.5.0",

src/index.html

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/index.js

+29-2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ let monacoTimeout;
1010
document.addEventListener('DOMContentLoaded', async () => {
1111
const elInpWidth = document.querySelector('#width')
1212
const elInpHeight = document.querySelector('#height')
13+
const elInpStroke = document.querySelector('#stroke')
1314
const elSelFormat = document.querySelector('#resolution')
1415
const elBtnDownload = document.querySelector('#download')
1516
const elChkAntiAliasing = document.querySelector('#antialiasing')
@@ -26,7 +27,24 @@ document.addEventListener('DOMContentLoaded', async () => {
2627
});
2728

2829
monacoEditor.setValue(defaultScript)
29-
30+
if (location.hash) {
31+
const params = new URLSearchParams(window.location.hash.slice(1))
32+
const code = atob(params.get('code').replace(/_/g, '='))
33+
const res = params.get('res').split('x')
34+
if (code && code.length > 0) {
35+
monacoEditor.setValue(code)
36+
}
37+
if (res && res.length == 2) {
38+
[elInpWidth.value, elInpHeight.value] = res
39+
}
40+
if (params.has('line')) {
41+
elInpStroke.value = parseFloat(params.get('line'))
42+
}
43+
if (params.has('aa')) {
44+
elChkAntiAliasing.checked = parseInt(params.get('aa')) == 1
45+
}
46+
}
47+
3048
const factory = new LuaFactory(wasmFile)
3149
const lua = await factory.createEngine()
3250
await lua.doString(gly_engine)
@@ -63,13 +81,20 @@ document.addEventListener('DOMContentLoaded', async () => {
6381
gly.init(elCanvas)
6482

6583
const apply = () => {
84+
const params = new URLSearchParams()
6685
const code = monacoEditor.getValue()
6786
gly.load(`return {init=function()end,loop=function()end,draw=function(std)\n${code}\nend}`)
6887
window.requestAnimationFrame(gly.update)
88+
params.set('res', `${elInpWidth.value}x${elInpHeight.value}`)
89+
params.set('code', btoa(code).replace(/=/g, '_'))
90+
params.set('line', elInpStroke.value)
91+
params.set('aa', elChkAntiAliasing.checked? 1: 0)
92+
location.hash = params.toString()
6993
}
7094

7195
const resizeAndApply = () => {
7296
gly.resize(elInpWidth.value, elInpHeight.value)
97+
gly.stroke(parseFloat(elInpStroke.value))
7398
apply()
7499
}
75100

@@ -98,14 +123,16 @@ document.addEventListener('DOMContentLoaded', async () => {
98123
const ext = elSelFormat.value
99124
const url = elCanvas.toDataURL(`image/${ext}`)
100125
const downloadLink = document.createElement('a')
126+
const uptime = (new Date()).toISOString().slice(2, 16).replace(/[-T:]/g, '').replace(/^(\d{6})(\d{4})$/, '$1-$2')
101127
downloadLink.href = url
102128
downloadLink.target = '_blank'
103-
downloadLink.download = `icon.${ext}`
129+
downloadLink.download = `img-${uptime}-${elInpWidth.value}x${elInpHeight.value}.${ext}`
104130
downloadLink.click()
105131
URL.revokeObjectURL(url)
106132
})
107133

108134
elChkAntiAliasing.addEventListener('change', toggleAntiAliasing);
135+
elInpStroke.addEventListener('change', resizeAndApply);
109136
elInpWidth.addEventListener('change', resizeAndApply);
110137
elInpHeight.addEventListener('change', resizeAndApply);
111138

0 commit comments

Comments
 (0)