-
Notifications
You must be signed in to change notification settings - Fork 469
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
78a618a
commit d7c21f3
Showing
9 changed files
with
3,455 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2023 mgt | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
Dependencies: | ||
|
||
Name: tetris-fumen | ||
Version: 1.1.3 | ||
License: MIT | ||
Private: false | ||
Description: Fumen parser for tetris | ||
Repository: undefined | ||
Homepage: https://github.com/knewjade/tetris-fumen | ||
Author: knewjade <knewjade@gmail.com> (https://github.com/knewjade) | ||
License Copyright: | ||
=== | ||
|
||
MIT License | ||
|
||
Copyright (c) 2019 | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
# [Mino](https://github.com/Enter-tainer/mino) | ||
|
||
Render tetris [fumen](https://harddrop.com/fumen/) in typst! | ||
|
||
 | ||
|
||
|
||
````typ | ||
#import "typst-package/lib.typ": decode-fumen, render-field | ||
// Uncomment the following line to use the mino from the official package registry | ||
// #import "@preview/mino:0.1.0": decode-fumen, render-field | ||
#set page(margin: 1.5cm) | ||
#align(center)[ | ||
#text(size: 25pt)[ | ||
DT Cannon | ||
] | ||
] | ||
#let fumen = decode-fumen("v115@vhPJHYaAkeEfEXoC+BlvlzByEEfE03k2AlP5ABwfAA?A+rQAAqsBsqBvtBTpBVhQeAlvlzByEEfE03k2AlP5ABwvDf?E33ZBBlfbOBV5AAAOfQeAlvlzByEEfE03+2BlP5ABwvDfEV?5k2AlPJVBjzAAA6WQAAzdBpeB0XBXUBFlQnAlvlzByEEfE0?3+2BlP5ABwvDfEXhWEBUYPNBkkuRA1GCLBUupAAdqQnAlvl?zByEEfE038UBlP5ABwvDfEXhWEBUYPNBkkuRA1GCLBU+rAA?AAPAA") | ||
#for i in range(fumen.len()) { | ||
let field = fumen.at(i).at("field") | ||
[#box(render-field(field, rows: 8, cell-size: 14pt)) #h(2em)] | ||
} | ||
```` | ||
|
||
## Documentation | ||
|
||
### `decode-fumen` | ||
|
||
Decode a fumen string into a series of pages. | ||
|
||
#### Arguments | ||
|
||
* `data`: `str` - The fumen string to decode | ||
|
||
#### Returns | ||
|
||
The pages, of type `Array<{ field: Array<string, 20>, comment: string }>`. | ||
|
||
``` | ||
( | ||
( | ||
field: ( | ||
"....", | ||
"....", | ||
... | ||
), | ||
comment: "..." | ||
), | ||
... | ||
) | ||
``` | ||
|
||
### `render-field` | ||
|
||
#### Arguments | ||
|
||
* `field`: `array` of `str` - The field to render | ||
* `rows`: `number` - The number of rows to render, default to `20` | ||
* `cell-size`: `length` - The size of each cell, default to `10pt` | ||
* `bg-color`: `color` - The background color, default to `#f3f3ed` | ||
* `stroke`: The stroke for the field, default to `none` | ||
* `radius`: The border radius for the field, default to `0.25 * cell-size` | ||
* `shadow`: Whether to show shadow for cells, default to `true` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
#import "mino.typ": decode-fumen | ||
#import "tetris.typ": render-field |
Large diffs are not rendered by default.
Oops, something went wrong.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#import "@preview/jogs:0.2.1": compile-js, call-js-function | ||
|
||
|
||
#let mj-src = read("./mino.js") | ||
#let mj-bytecode = compile-js(mj-src) | ||
|
||
#let get-text(src) = { | ||
if type(src) == str { | ||
src | ||
} else if type(src) == content { | ||
src.text | ||
} | ||
} | ||
|
||
#let decode-fumen(fumen) = call-js-function(mj-bytecode, "mino", fumen) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
|
||
#let color-data = ( | ||
"Z": rgb("#ef624d"), | ||
"S": rgb("#66c65c"), | ||
"L": rgb("#ef9535"), | ||
"J": rgb("#1983bf"), | ||
"T": rgb("#9c27b0"), | ||
"O": rgb("#f7d33e"), | ||
"I": rgb("#41afde"), | ||
"X": rgb("#686868") | ||
) | ||
|
||
#let shadow-color = ( | ||
"Z": rgb("#ff9484"), | ||
"S": rgb("#88ee86"), | ||
"L": rgb("#ffbf60"), | ||
"J": rgb("#1ba6f9"), | ||
"T": rgb("#e56add"), | ||
"O": rgb("#fff952"), | ||
"I": rgb("#43d3ff"), | ||
"X": rgb("#949494") | ||
) | ||
|
||
#let is-upper(c) = upper(c) == c | ||
|
||
#let render-field(field, rows: 20, cell-size: 10pt, bg-color: rgb("#f3f3ed"), stroke: none, radius: auto, shadow: true) = { | ||
let actual-radius = if radius == auto { cell-size / 4 } else { radius } | ||
let shadow-height = cell-size / 5 | ||
block(width: 10 * cell-size, height: rows * cell-size, inset: 0pt, stroke: stroke, radius: actual-radius, clip: true, fill: bg-color, breakable: false, { | ||
for i in range(rows) { | ||
for j in range(10) { | ||
if field.at(i).codepoints().at(j) == "_" { | ||
continue | ||
} | ||
let block = field.at(i).codepoints().at(j) | ||
if is-upper(block) { | ||
place(top + left, | ||
dx: cell-size * j, | ||
dy: cell-size * (rows - 1 - i), | ||
rect( | ||
width: cell-size, | ||
height: cell-size, | ||
fill: color-data.at(upper(block)) | ||
) | ||
) | ||
if shadow and block != "_" { | ||
place(top + left, | ||
dx: cell-size * j, | ||
dy: cell-size * (rows - i - 1) - shadow-height, | ||
rect( | ||
width: cell-size, | ||
height: shadow-height, | ||
fill: shadow-color.at(upper(block)) | ||
) | ||
) | ||
} | ||
} else { | ||
// operation mino is displayed in lower case | ||
place(top + left, | ||
dx: cell-size * j, | ||
dy: cell-size * (rows - 1 - i), | ||
rect( | ||
width: cell-size, | ||
height: cell-size, | ||
fill: bg-color | ||
) | ||
) | ||
place(top + left, | ||
dx: cell-size * j + cell-size * 0.1, | ||
dy: cell-size * (rows - 1 - i) + cell-size * 0.1, | ||
rect( | ||
width: cell-size * 0.8, | ||
height: cell-size * 0.8, | ||
stroke: color-data.at(upper(block)) + cell-size * 0.1, | ||
) | ||
) | ||
} | ||
} | ||
} | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
[package] | ||
name = "mino" | ||
version = "0.1.0" | ||
entrypoint = "lib.typ" | ||
authors = ["Wenzhuo Liu"] | ||
license = "MIT" | ||
description = "Render tetris fumen in typst." | ||
|
||
homepage = "https://github.com/Enter-tainer/m-jaxon" | ||
repository = "https://github.com/Enter-tainer/m-jaxon" | ||
keywords = ["js", "javascript", "tetris", "fumen", "game"] | ||
exclude = ["mino.svg"] |