From 7c3e1fc9e950c66f53e3a57711ae47051627ea22 Mon Sep 17 00:00:00 2001 From: Seoxi Ryouko <3-Seoxi@users.noreply.git.starbit.dev> Date: Thu, 13 Feb 2025 06:45:01 -0600 Subject: [PATCH] =?UTF-8?q?Restructured=20frontend=20=F0=9F=92=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 8 ++++---- build | 4 ++-- src/main.rs | 10 +++++----- web/dynamic/card_back.png | Bin 0 -> 4524 bytes {static => web/dynamic}/cards.json | 0 {static => web/dynamic}/index.html | 6 +++++- {web-src => web/src}/script.ls | 16 +++++++++++----- {web-src => web/src}/style.scss | 4 ++++ 8 files changed, 31 insertions(+), 17 deletions(-) create mode 100644 web/dynamic/card_back.png rename {static => web/dynamic}/cards.json (100%) rename {static => web/dynamic}/index.html (77%) rename {web-src => web/src}/script.ls (87%) rename {web-src => web/src}/style.scss (97%) diff --git a/.gitignore b/.gitignore index 4d39247..773d297 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,6 @@ /target Rocket.toml -/static/script.js -/static/style.css -/static/style.css.map -/static/assets +/web/dynamic/script.js +/web/dynamic/style.css +/web/static + diff --git a/build b/build index acf28aa..e82efdd 100755 --- a/build +++ b/build @@ -1,5 +1,5 @@ #!/usr/bin/env bash -lsc -bc --no-header -o static/ web-src/script.ls || exit 1 -npx sass web-src/style.scss static/style.css || exit 2 +lsc --no-header -bco web/static/ web/src/script.ls || exit 1 +npx sass --no-source-map web/src/style.scss web/static/style.css || exit 2 rustfmt src/*.rs || exit 3 cargo $(basename $0) "${@:1}" diff --git a/src/main.rs b/src/main.rs index 8342ed8..c409826 100644 --- a/src/main.rs +++ b/src/main.rs @@ -238,14 +238,14 @@ fn rocket() -> _ { println!("B: {}", b_uuid); rocket::build() - .mount("/", FileServer::from(relative!("static/assets")).rank(0)) + .mount("/", FileServer::from(relative!("web/static")).rank(0)) .mount( - format!("/{}", a_uuid.hyphenated()), - FileServer::from(relative!("static")), + format!("/{}/", a_uuid.hyphenated()), + FileServer::from(relative!("web/dynamic")), ) .mount( - format!("/{}", b_uuid.hyphenated()), - FileServer::from(relative!("static")), + format!("/{}/", b_uuid.hyphenated()), + FileServer::from(relative!("web/dynamic")), ) .mount( "/", diff --git a/web/dynamic/card_back.png b/web/dynamic/card_back.png new file mode 100644 index 0000000000000000000000000000000000000000..1c3f544ca56fddc1d166c19d7fdd4373a6f4b147 GIT binary patch literal 4524 zcmeAS@N?(olHy`uVBq!ia0y~yV0y{Gz#_oG1{8_!Joa73pLdW=ac#@qFi$lGh69qij0_AjN`R~-%nS{l>Kr@PUX36>`N03^H7!eq2CA<#2~^(v^^5u<9l8!b#mTw!vcp1VqlQ{F5{ Sy%snM!{F)a=d#Wzp$Pzf+Mr+n literal 0 HcmV?d00001 diff --git a/static/cards.json b/web/dynamic/cards.json similarity index 100% rename from static/cards.json rename to web/dynamic/cards.json diff --git a/static/index.html b/web/dynamic/index.html similarity index 77% rename from static/index.html rename to web/dynamic/index.html index 43e2bc0..a4dc402 100644 --- a/static/index.html +++ b/web/dynamic/index.html @@ -11,13 +11,17 @@
+
diff --git a/web-src/script.ls b/web/src/script.ls similarity index 87% rename from web-src/script.ls rename to web/src/script.ls index 5143214..5fce680 100644 --- a/web-src/script.ls +++ b/web/src/script.ls @@ -34,7 +34,7 @@ img = document.create-element \img img.src = it img - const make-blank-card = -> make-card \assets/card_back.jpg + const make-blank-card = -> make-card \./card_back.png const gen-opponent-cards$ = -> diff = it - $opponent-hand.child-element-count switch @@ -50,7 +50,8 @@ player-state = JSON.parse player-state-json events-json = await fetch \/get_events .then (.text!) .catch err 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 hide-card$ = -> @@ -60,11 +61,8 @@ $view-card.style.opacity = 1 e.target.add-event-listener \mouseleave hide-card$ state = await get-state! - window.state = state const apply-state$ = -> 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 document.body.class-list.remove \my-turn if it.you != it.turn_player else @@ -75,6 +73,7 @@ card-data = cards[card-id] card = make-card card-data.jpg card.set-attribute \data-index index + card.set-attribute \data-text card-data.txt card.add-event-listener \mouseenter show-card$ card.set-attribute \data-png card-data.png $own-hand.append-child card @@ -85,6 +84,7 @@ unless new-state.player-state-json == state.player-state-json apply-state$ new-state.player-state state := new-state + window.state = state ), 1000 mouse-x = mouse-y = 0 document @@ -104,4 +104,10 @@ | \t => if current-mouse-node?.has-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}" )! diff --git a/web-src/style.scss b/web/src/style.scss similarity index 97% rename from web-src/style.scss rename to web/src/style.scss index b607020..dbc48db 100644 --- a/web-src/style.scss +++ b/web/src/style.scss @@ -89,3 +89,7 @@ aside { .my-turn #border { background-color: #0ff2; } + +#play { + flex-grow: 1; +}