gdquest-demos / godot-3-demos

Dozens of free and open source demos for the Godot game engine, version 3. Head to the link below for newer demos for Godot 4+
https://github.com/gdquest-demos/
MIT License
1.85k stars 981 forks source link

Remove all enum names #41

Closed NathanLovato closed 5 years ago

NathanLovato commented 5 years ago

As mentioned in #33, in Godot 3.1, you must access named enums starting with their identifier or you'll get an error.

As there are many demos here, I think we should remove all enum names and test every project individually to see if it imports and runs in 3.1.

Steps

seanbone commented 5 years ago

There's only 6 files containing multiple enums:

Godot-engine-tutorial-demos$ ack -c -l enum | grep ":2"
2018/07-30-2018-multiplayer-high-level-api/outlines/multiplayer-outline-part-2.md:2
2018/06-28-UI-lifebar-counter-code/start/actors/player/weapon/sword.gd:2
2018/06-28-UI-lifebar-counter-code/end/actors/player/weapon/sword.gd:2
2018/04-24-finite-state-machine/player/weapon/sword.gd:2
2017/start/05-How to create a tileset/Player.gd:2
2017/final/01-Custom camera/Player.gd:2
seanbone commented 5 years ago

As for pattern replacement, the following regex should do the trick:

sed -ri 's/enum ([A-Za-z0-9_]+) \{([A-Za-z0-9_\, ]+)\}/enum \{\2\}/g;' myfile.txt

And this one-liner will find every file with exactly one occurrence of enum:

ack -cl "enum" | ack ":1" | sed -r "s/(.+):1/\1/"

Finally, this monstrosity will edit the contents of each file (see my fork):

ack -cl "enum" | ack ":1" | sed -r "s/(.+):1/\1/" | while read in; do sed -ri 's/enum ([A-Za-z0-9_]+) \{([A-Za-z0-9_\, ]+)\}/enum \{\2\}/g;' "$in"; done
seanbone commented 5 years ago

Enough for today. Tomorrow I'll fix up the files with two occurrences, then look into automated testing.

NathanLovato commented 5 years ago

Thank you so much :) ♥ Thanks a lot for sharing the commands as well: I'll use them as a base to update the Godot course as well!

seanbone commented 5 years ago

No problem! I've been having fun. Never really used scripts this way (not for anything useful, anyway), so it's been a learning experience. I've added a simple bash script to open each project file in turn, and check for error messages. The option -v will make it also print Godot's output for projects with errors. Probably not the cleanest, as I'm not that familiar with Godot's CLI (or bash scripting, for that matter).

On a side note, for reference - to open each project in turn, (re)generating import files:

ack -g "\.godot" | while read in; do timeout 5 godot -e "$in"; done
seanbone commented 5 years ago

Note: the script works by using timeout 1 godot "path/to/project/" to open each project for one second, records STDOUT and STDERR, and checks them for the word "ERROR" (case-insensitive). As such, some errors may not be detected (e.g. if an error only happens after a certain player interaction). There's also a bunch of other (unrelated to enums) errors being picked up, and a few "no main scene defined" errors.

seanbone commented 5 years ago

Ok, so I've fixed up the files with errors relating to enums. The script still reports errors on 15 projects. 8 of those are Error: Can't run project: no main scene defined., which I assume is because of the tutorial format. The rest are miscellaneous unrelated (I believe) errors:

$ ./checkerrors.sh -v
Error found in: 2018/03-16-camera-2d-rig/end

OpenGL ES 3.0 Renderer: GeForce GTX 1060 6GB/PCIe/SSE2
SCRIPT ERROR: GDScript::reload: Parse Error: No constructor of 'Vector2' matches the signature 'Vector2(var)'.
   At: res://characters/camera/grid-snapper.gd:36.
ERROR: reload: Method/Function Failed, returning: ERR_PARSE_ERROR
   At: modules/gdscript/gdscript.cpp:580.

**********************************************************

Error found in: 2018/06-09-grid-based-movement

OpenGL ES 3.0 Renderer: GeForce GTX 1060 6GB/PCIe/SSE2
SCRIPT ERROR: GDScript::reload: Parse Error: Expected a constant expression.
   At: res://pawns/pawn.gd:4.
ERROR: reload: Method/Function Failed, returning: ERR_PARSE_ERROR
   At: modules/gdscript/gdscript.cpp:580.
SCRIPT ERROR: GDScript::reload: Parse Error: Script not fully loaded (cyclic preload?): res://pawns/pawn.gd
   At: res://pawns/actor.gd:1.
ERROR: reload: Method/Function Failed, returning: ERR_PARSE_ERROR
   At: modules/gdscript/gdscript.cpp:580.
SCRIPT ERROR: GDScript::reload: Parse Error: Expected a constant expression.
   At: res://pawns/pawn.gd:4.
ERROR: reload: Method/Function Failed, returning: ERR_PARSE_ERROR
   At: modules/gdscript/gdscript.cpp:580.

**********************************************************

Error found in: 2018/05-09-screen-sizes-example

OpenGL ES 3.0 Renderer: GeForce GTX 1060 6GB/PCIe/SSE2
WARNING: _update_root_rect: Font oversampling does not work in 'Viewport' stretch mode, only '2D'.
   At: scene/main/scene_tree.cpp:1241.
SCRIPT ERROR: GDScript::reload: Parse Error: Expected a constant expression.
   At: res://scripts/EnemySpawner.gd:4.
ERROR: reload: Method/Function Failed, returning: ERR_PARSE_ERROR
   At: modules/gdscript/gdscript.cpp:580.

**********************************************************

Error found in: 2019/05-27-firebase-highscore/end

OpenGL ES 3.0 Renderer: GeForce GTX 1060 6GB/PCIe/SSE2
SCRIPT ERROR: _on_HTTPRequest_request_completed: Invalid cast: could not convert value to 'Dictionary'.
   At: res://Highscores.gd:24.

**********************************************************

Error found in: 2019/01-07-first-3d-game/end

OpenGL ES 3.0 Renderer: GeForce GTX 1060 6GB/PCIe/SSE2
ERROR: create_from_image: Condition ' p_image.is_null() ' is true.
   At: scene/resources/texture.cpp:192.

**********************************************************

Error found in: 2017/final/17-Attack demo with Heartbeast/start

OpenGL ES 3.0 Renderer: GeForce GTX 1060 6GB/PCIe/SSE2
ERROR: get_node: Node not found: AttackTimer
   At: scene/main/node.cpp:1382.
ERROR: get_node: Node not found: AttackTimer
   At: scene/main/node.cpp:1382.
ERROR: get_node: Node not found: AttackTimer
   At: scene/main/node.cpp:1382.

**********************************************************

Error found in: 2017/final/17-Attack demo with Heartbeast/end

OpenGL ES 3.0 Renderer: GeForce GTX 1060 6GB/PCIe/SSE2
ERROR: get_node: Node not found: AttackTimer
   At: scene/main/node.cpp:1382.
ERROR: get_node: Node not found: AttackTimer
   At: scene/main/node.cpp:1382.
ERROR: get_node: Node not found: AttackTimer
   At: scene/main/node.cpp:1382.

**********************************************************

Found 15 files with errors.
NathanLovato commented 5 years ago

Amazing! Please open a PR anytime :)