Create null nodes always
authorCameron Ball <cameron@moodle.com>
Tue, 2 Apr 2019 05:55:46 +0000 (13:55 +0800)
committerCameron Ball <cameron@moodle.com>
Tue, 2 Apr 2019 05:55:46 +0000 (13:55 +0800)
ScoreSync.sh

index 20d70ab..c1cf1a1 100755 (executable)
@@ -177,6 +177,8 @@ if [ "$1" = "push" ]; then
         # TODO: Technically these queries are not quite specific enough. They could find scores left by players other than the machine owner
         # but probably it's fine
         for fuck in "${!all_song_hashes[@]}"; do
+            # TODO: After the initial apply and push, running this a second time should result in way less shit in "fuck" - only stuff faved that session should be here
+            echo "$fuck"
             pathh=$(cat "${DIR}/${songs_file}" | grep $fuck | cut -sd / -f5,6 )
             pathh=$(echo $pathh | sed 's/`/\\\`/g')
             xmlstarlet_orphans_cmd="$xmlstarlet_orphans_cmd -i \"//SongScores//Song[@Dir=\\\"Songs/${pathh}/\\\"]//Steps//HighScore[1]//PercentDP\" \
@@ -325,7 +327,6 @@ if [ "$1" = "apply" ]; then
                     # so the next time apply runs, we know that they had already been copied over, and we don't have to run
                     # xmlstarlet again
 
-                    # TODO: This should only run when looking at the scores file for $me
                     # Then later on when we process the pranks, unset any hashes that turn out to have a score elsewhere
                     # before finally adding the null nodes
                     null_files[$(echo $i | cut -sd : -f1)]+="$person"
@@ -375,6 +376,11 @@ if [ "$1" = "apply" ]; then
                 done
                 if ! [ "${scores[${highest}:${i}]}" = "0.000000" ]; then
                     pranks["${i}"]+="${highest}:${scores[${highest}:${i}]}"
+
+                    # We found a score for this in someone else's scores file, a proper node will be made.
+                    if ! [ -z "${null_files[$hash]}" ]; then
+                        unset null_files["$hash"]
+                    fi
                     had_score=true
                 fi
             done
@@ -588,6 +594,30 @@ if [ "$1" = "apply" ]; then
         fi
     done
 
+    for nully in "${!null_files[@]}"; do
+        faver="${all_song_hashes[${nully}]}"
+
+        if [ "$faver" = "$me" ]; then
+            persons_folder="$faves_folder"
+        else
+            formatted_person="$(tr '[:lower:]' '[:upper:]' <<< ${faver:0:1})${faver:1}"
+            persons_folder=${external_favourite_naming_scheme/\%person\%/$formatted_person}
+        fi
+
+        path="$(echo ${hash_map[${nully}]} | cut -sd / -f2)"
+        path=$(echo $path | sed 's/&/\&amp;/g; s/</\&lt;/g; s/>/\&gt;/g; s/"/\&quot;/g; s/'"'"'/\&apos;/g')
+        song_path="Songs/${persons_folder}/${path}/"
+
+        empty_nodes="${empty_nodes}\n<Song Dir=\"$song_path\" >\
+             \n<Steps Difficulty=\"Challenge\" StepsType=\"dance-single\">\
+             \n<HighScoreList>\
+             \n<LastPlayed>1933-01-02</LastPlayed>\
+             \n<NumTimesPlayed>1</NumTimesPlayed>\
+             \n</HighScoreList>\
+             \n</Steps>\
+             \n</Song>"
+    done
+
     # blow away all existing nodes in the favourites folders, we will make them ourselves and append to the end of the file
     cmd="xmlstarlet ed -L ${xmlstarlet_deletes} \"${path_to_stats}\""
     $(eval "$cmd")