Restructured frontend 💯

This commit is contained in:
Seoxi Ryouko
2025-02-13 06:45:01 -06:00
parent 04532aaafe
commit 7c3e1fc9e9
8 changed files with 31 additions and 17 deletions

8
.gitignore vendored
View File

@ -1,6 +1,6 @@
/target /target
Rocket.toml Rocket.toml
/static/script.js /web/dynamic/script.js
/static/style.css /web/dynamic/style.css
/static/style.css.map /web/static
/static/assets

4
build
View File

@ -1,5 +1,5 @@
#!/usr/bin/env bash #!/usr/bin/env bash
lsc -bc --no-header -o static/ web-src/script.ls || exit 1 lsc --no-header -bco web/static/ web/src/script.ls || exit 1
npx sass web-src/style.scss static/style.css || exit 2 npx sass --no-source-map web/src/style.scss web/static/style.css || exit 2
rustfmt src/*.rs || exit 3 rustfmt src/*.rs || exit 3
cargo $(basename $0) "${@:1}" cargo $(basename $0) "${@:1}"

View File

@ -238,14 +238,14 @@ fn rocket() -> _ {
println!("B: {}", b_uuid); println!("B: {}", b_uuid);
rocket::build() rocket::build()
.mount("/", FileServer::from(relative!("static/assets")).rank(0)) .mount("/", FileServer::from(relative!("web/static")).rank(0))
.mount( .mount(
format!("/{}", a_uuid.hyphenated()), format!("/{}/", a_uuid.hyphenated()),
FileServer::from(relative!("static")), FileServer::from(relative!("web/dynamic")),
) )
.mount( .mount(
format!("/{}", b_uuid.hyphenated()), format!("/{}/", b_uuid.hyphenated()),
FileServer::from(relative!("static")), FileServer::from(relative!("web/dynamic")),
) )
.mount( .mount(
"/", "/",

BIN
web/dynamic/card_back.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.4 KiB

View File

@ -11,13 +11,17 @@
<main> <main>
<div class="hand" id="opponent-hand"></div> <div class="hand" id="opponent-hand"></div>
<div id="border"></div> <div id="border"></div>
<div id="play"></div>
<div class="hand" id="own-hand"></div> <div class="hand" id="own-hand"></div>
</main> </main>
<aside id="view-card-container"> <aside id="view-card-container">
<div id="param-container"> <div id="param-container">
<span id="param"></span> <span id="param"></span>
</div> </div>
<img src=".." alt="" id="view-card" /> <img src="" alt="" id="view-card" />
<div id="card-text-container">
<span id="card-text"></span>
</div>
</aside> </aside>
</body> </body>
</html> </html>

View File

@ -34,7 +34,7 @@
img = document.create-element \img img = document.create-element \img
img.src = it img.src = it
img img
const make-blank-card = -> make-card \assets/card_back.jpg const make-blank-card = -> make-card \./card_back.png
const gen-opponent-cards$ = -> const gen-opponent-cards$ = ->
diff = it - $opponent-hand.child-element-count diff = it - $opponent-hand.child-element-count
switch switch
@ -50,7 +50,8 @@
player-state = JSON.parse player-state-json player-state = JSON.parse player-state-json
events-json = await fetch \/get_events .then (.text!) .catch err events-json = await fetch \/get_events .then (.text!) .catch err
events = JSON.parse events-json events = JSON.parse events-json
return { player-state-json, player-state, events-json, events } play-map = new Map player-state.play.map -> [it.id, it]
return { player-state-json, player-state, events-json, events, play-map }
const show-card$ = (e) -> const show-card$ = (e) ->
const hide-card$ = -> const hide-card$ = ->
@ -60,11 +61,8 @@
$view-card.style.opacity = 1 $view-card.style.opacity = 1
e.target.add-event-listener \mouseleave hide-card$ e.target.add-event-listener \mouseleave hide-card$
state = await get-state! state = await get-state!
window.state = state
const apply-state$ = -> const apply-state$ = ->
gen-opponent-cards$ it.opponent_cards_in_hand gen-opponent-cards$ it.opponent_cards_in_hand
#const my-card-ids = [...$own-hand.children].map ->
# it.get-attribute \data-id*/
if document.body.class-list.contains \my-turn if document.body.class-list.contains \my-turn
document.body.class-list.remove \my-turn if it.you != it.turn_player document.body.class-list.remove \my-turn if it.you != it.turn_player
else else
@ -75,6 +73,7 @@
card-data = cards[card-id] card-data = cards[card-id]
card = make-card card-data.jpg card = make-card card-data.jpg
card.set-attribute \data-index index card.set-attribute \data-index index
card.set-attribute \data-text card-data.txt
card.add-event-listener \mouseenter show-card$ card.add-event-listener \mouseenter show-card$
card.set-attribute \data-png card-data.png card.set-attribute \data-png card-data.png
$own-hand.append-child card $own-hand.append-child card
@ -85,6 +84,7 @@
unless new-state.player-state-json == state.player-state-json unless new-state.player-state-json == state.player-state-json
apply-state$ new-state.player-state apply-state$ new-state.player-state
state := new-state state := new-state
window.state = state
), 1000 ), 1000
mouse-x = mouse-y = 0 mouse-x = mouse-y = 0
document document
@ -104,4 +104,10 @@
| \t => | \t =>
if current-mouse-node?.has-attribute \data-index if current-mouse-node?.has-attribute \data-index
fetch "./fade/#{current-mouse-node.get-attribute \data-index}" fetch "./fade/#{current-mouse-node.get-attribute \data-index}"
| \y =>
if current-mouse-node?.has-attribute \data-index
fetch "./fade_bottom/#{current-mouse-node.get-attribute \data-index}"
| ' ' =>
if current-mouse-node?.has-attribute \data-index
fetch "./play/#{current-mouse-node.get-attribute \data-index}"
)! )!

View File

@ -89,3 +89,7 @@ aside {
.my-turn #border { .my-turn #border {
background-color: #0ff2; background-color: #0ff2;
} }
#play {
flex-grow: 1;
}