Looking at the code, is the issue the sprite_dir variable not being set?
It might be that the set_sprite_dir function is not working, because it is checking if the velocity is equal to vectors pointing at 90 degree angles with a length of 1, while velocity likely has a length higher than 1 and may be pointing in a different direction.
An easy fix is to make a class variable for storing the player’s input (something like input_direction, for example). Then you should be able to use the stored player input vector in set_sprite_dir, as it should not be effected by the movement of the player through the physics world and because it is not multiplied by speed or delta it should have a length of 1.
I do know if this is the issue or not, but storing the player's input and using that in set_sprite_dir should allow the code to set sprite_dir when the player moves in a single direction. You might need to make some small modifications to change the animation for diagonal movement though.
Hopefully this helps!
(Side note: Welcome to the forums!)
Edit: I should not write when I have not been properly caffeinated :lol: