summaryrefslogtreecommitdiffstats
path: root/contrib/gen-meta.sh
diff options
context:
space:
mode:
authorLibravatarLarge Libravatar memdmp <memdmpmemewarenet>2025-01-13 16:54:34 +0100
committerLibravatarLarge Libravatar memdmp <memdmpmemewarenet>2025-01-13 16:54:34 +0100
commit6e3b3c8013e6d8814dbf70c854e55d062bedbdf4 (patch)
tree5b07a6d26c349293bc61a71a32d6e368fed11c4e /contrib/gen-meta.sh
downloadbibata-cursor-cli-6e3b3c8013e6d8814dbf70c854e55d062bedbdf4.tar.gz
bibata-cursor-cli-6e3b3c8013e6d8814dbf70c854e55d062bedbdf4.tar.bz2
bibata-cursor-cli-6e3b3c8013e6d8814dbf70c854e55d062bedbdf4.tar.lz
bibata-cursor-cli-6e3b3c8013e6d8814dbf70c854e55d062bedbdf4.zip

chore: initial commit

HEADmaster
Diffstat (limited to 'contrib/gen-meta.sh')
-rwxr-xr-xcontrib/gen-meta.sh145
1 files changed, 145 insertions, 0 deletions
diff --git a/contrib/gen-meta.sh b/contrib/gen-meta.sh
new file mode 100755
index 0000000..2f51e80
--- /dev/null
+++ b/contrib/gen-meta.sh
@@ -0,0 +1,145 @@
+#!/bin/bash
+# Generates usable metadata for the cursors, allowing them to be more easily processed
+# TODO: Rewite in Amber - https://amber-lang.com
+set -e
+
+source contrib/util.sh
+
+CANCER_PATH="$(realpath cancer-meta.toml)"
+CANCER="$(yq e -p toml -o json . "$CANCER_PATH")"
+get_meta_from_cancer() {
+ jq -Mc '.cursor[]' <<< "$CANCER" | while read cursor_json; do
+ if [[ "$(jq -Mc .id <<< "$cursor_json")" == "$1" ]]; then
+ echo -n "$cursor_json"
+ return 0
+ fi
+ done
+}
+
+cd cursors
+# Process metadata into usable files
+for type in ./*; do
+ type="$(sed 's|./||' <<< "$type")"
+ start "Processing CursorType($type)"
+ cd "$type"
+ for cursor in ./*; do
+ cursor="$(sed 's|./||' <<< "$cursor")"
+ if [[ -d "$cursor" ]]; then
+ cd "$cursor"
+ cursor_meta="./meta.json"
+ cursor_assets="./assets"
+ get_from_orig() {
+ jq -Mc "$1" "$cursor_meta"
+ }
+ get_from_orig_raw() {
+ jq -Mcr "$1" "$cursor_meta"
+ }
+
+ is_animated="$(get_from_orig .isAnimated)"
+ start "Processing Cursor(CursorType($type), name=$cursor, animated=$is_animated)"
+
+ if [[ "$is_animated" == "true" ]]; then
+ # Animated files tend to have lots of SVGs, resulting in us being unable to store the entire JSON object in memory
+ # This results in us getting an "Argument list too long" error - even though its not the arg list, but rather the env
+ # We solve this by placing the temporary storage on a real file on the filesystem
+ jsettempstorage "/tmp/_$(date)"
+ else
+ # Otherwise, we (dangerously!) assume the file will fit in env, and clear the temp storage.
+ jsettempstorage
+ fi
+
+ additional_meta="$(get_meta_from_cancer "$(get_from_orig .name)")"
+
+ jnew "./cursor.json"
+ jtransaction
+ jrun ".animated=$is_animated"
+ jrun ".id=$(get_from_orig .id)"
+ jrun ".name=$(get_from_orig .name)"
+ jrun ".aliases=$(jq -Mc 'if has("links") then .links else [] end' <<< "$additional_meta")"
+ jrun ".hot={}"
+ jrun ".hot.x=$(jq -Mc 'if has("x") then .x else 128 end' <<< "$additional_meta")"
+ jrun ".hot.y=$(jq -Mc 'if has("y") then .y else 128 end' <<< "$additional_meta")"
+ jrun ".platform_names={}"
+ jrun ".platform_names.windows=$(jq -Mc 'if has("winname") then .winname else null end' <<< "$additional_meta")"
+ jrun ".platform_names.xorg=$(jq -Mc 'if has("xname") then .xname else .id end' <<< "$additional_meta")"
+ jrun ".frames=[]"
+ idx=0
+ trx_ctr=1
+ while read node_id; do
+ url="$(jq -Mc ".urls[${idx}]" < "$cursor_meta")"
+ raw_node_id="$(jq -Mcr . <<< "$node_id")"
+ frame="$cursor_assets/$raw_node_id.svg"
+ [[ "$is_animated" == "true" ]] && start "Processing CursorFrame(Cursor(CursorType($type), name=$cursor, animated=$is_animated), frame=$raw_node_id)"
+ if [[ "$trx_ctr" == "1" ]]; then
+ jcommit
+ jtransaction
+ trx_ctr=32
+ else
+ ((trx_ctr=trx_ctr-1))
+ fi
+ jrun ".frames[$idx]={}"
+ jrun ".frames[$idx].idx=$idx"
+ jrun ".frames[$idx].id=$node_id"
+ jrun ".frames[$idx].url=$url"
+ jrun ".frames[$idx].delay=(if $node_id | contains(\":\") then $node_id | split(\":\") | .[0] | tonumber else 60 end)"
+ jrun ".frames[$idx].sha512=$(escape_str "$(sha512sum "$frame" | awk '{print $1}')")"
+ jsetasset "$(cat "$frame")" && jrun ".frames[$idx].svg=$(jgetassetref)"
+ [[ "$is_animated" == "true" ]] && complete "Finished $(_last | sed s/Pr/pr/)"
+ ((idx=idx+1))
+ done <<< "$(jq -Mc '.node_ids[]' "$cursor_meta")"
+ jrun ".frame_count=${idx}"
+ jcommit
+ jsave
+
+ # We're done with the file, let's empty the storage
+ jnew
+ # If we started using tmpfs, let's go back to in-memory storage
+ if [[ "$is_animated" == "true" ]]; then
+ jsettempstorage
+ fi
+
+ complete "Finished $(_last | sed s/Pr/pr/)"
+
+ cd ..
+ fi
+ done
+ complete "Finished $(_last | sed s/Pr/pr/)"
+ cd ..
+done
+# Process outputs into single file
+jsettempstorage "/tmp/_$(date)"
+jnew ../.cursors
+jtransaction
+jrun '.=[]'
+typeidx=0
+for type in ./*; do
+ type="$(sed 's|./||' <<< "$type")"
+ start "Bundle all CursorType($type)"
+ jrun ".[${typeidx}]={}"
+ jrun ".[${typeidx}].kind=$(escape_str "$type")"
+ jrun ".[${typeidx}].cursors=[]"
+ jcommit
+ jsave
+ trx_ctr=1
+ cd "$type"
+ for cursor in ./*; do
+ cursor="$(sed 's|./||' <<< "$cursor")"
+ if [[ -d "$cursor" ]]; then
+ start "Push Cursor(CursorType($type), name=$cursor, animated=null)"
+ cd "$cursor"
+ _jrun_file ".[${typeidx}].cursors += [$(jq -M . ./cursor.json)]"
+ cd ..
+ complete
+ fi
+ done
+ complete
+ jtransaction
+ cd ..
+ ((typeidx=typeidx+1))
+done
+jcommit
+jsave
+
+cd ..
+
+jq -Mc . .cursors > .cursors.min