From aba651a9983e97a486e06e4a46a0aadb0820e6df Mon Sep 17 00:00:00 2001 From: IntegratedQuantum Date: Tue, 16 Apr 2024 13:50:40 +0200 Subject: [PATCH] Add a simple python script to check for common formatting errors (tabs and line endings) and fix existing problems. a step towards #315 --- README.md | 2 +- assets/cubyz/shaders/deferred_render_pass.fs | 1 - assets/cubyz/shaders/entity_vertex.vs | 4 +- assets/cubyz/shaders/graphics/Circle.fs | 2 +- assets/cubyz/shaders/graphics/graph.vs | 4 +- assets/cubyz/shaders/item_drop.fs | 2 +- assets/cubyz/shaders/item_drop.vs | 2 +- assets/cubyz/shaders/item_texture_post.fs | 2 +- format_check.py | 43 ++++++++++++++++++++ src/models.zig | 2 +- 10 files changed, 53 insertions(+), 11 deletions(-) create mode 100644 format_check.py diff --git a/README.md b/README.md index 8bfa0ac4..aa279f92 100644 --- a/README.md +++ b/README.md @@ -50,7 +50,7 @@ sudo apt install libgl-dev libasound2-dev libx11-dev libxcursor-dev libxrandr-de # Contributing ### Code -Try to follow the style of the existing code. `// TODO: Add a style guide`
+Try to follow the style of the existing code. The `check_format.py` file can be used to find violations of indentation and line endings. `// TODO: Add a full style guide`
If you have any more questions, you can ask them over on [Discord](https://discord.gg/XtqCRRG). ### Textures If you want to add new textures, make sure they fit the style of the game. diff --git a/assets/cubyz/shaders/deferred_render_pass.fs b/assets/cubyz/shaders/deferred_render_pass.fs index edd38cf5..654a16d7 100644 --- a/assets/cubyz/shaders/deferred_render_pass.fs +++ b/assets/cubyz/shaders/deferred_render_pass.fs @@ -1,6 +1,5 @@ #version 430 out vec4 fragColor; - in vec2 texCoords; uniform sampler2D color; diff --git a/assets/cubyz/shaders/entity_vertex.vs b/assets/cubyz/shaders/entity_vertex.vs index 6aa323f7..12793859 100644 --- a/assets/cubyz/shaders/entity_vertex.vs +++ b/assets/cubyz/shaders/entity_vertex.vs @@ -30,7 +30,7 @@ vec3 calcLight(int srgb) { void main() { vec4 mvPos = viewMatrix * vec4(position, 1); gl_Position = projectionMatrix * mvPos; - outTexCoord = texCoord; - mvVertexPos = mvPos.xyz; + outTexCoord = texCoord; + mvVertexPos = mvPos.xyz; outLight = calcLight(light); } \ No newline at end of file diff --git a/assets/cubyz/shaders/graphics/Circle.fs b/assets/cubyz/shaders/graphics/Circle.fs index 01a64b8e..26d3144c 100644 --- a/assets/cubyz/shaders/graphics/Circle.fs +++ b/assets/cubyz/shaders/graphics/Circle.fs @@ -7,7 +7,7 @@ in vec2 unitPosition; // Like smooth step, but with linear interpolation instead of s-curve. float linearstep(float edge0, float edge1, float x) { - return clamp((x - edge0) / (edge1 - edge0), 0.0, 1.0); + return clamp((x - edge0) / (edge1 - edge0), 0.0, 1.0); } void main(){ diff --git a/assets/cubyz/shaders/graphics/graph.vs b/assets/cubyz/shaders/graphics/graph.vs index 1a9d27cb..0abebc4e 100644 --- a/assets/cubyz/shaders/graphics/graph.vs +++ b/assets/cubyz/shaders/graphics/graph.vs @@ -14,8 +14,8 @@ layout(std430, binding = 5) buffer _data void main() { - float x = gl_VertexID; - float y = -data[(gl_VertexID+offset)%points]; + float x = gl_VertexID; + float y = -data[(gl_VertexID+offset)%points]; // Convert to opengl coordinates: vec2 position_percentage = (start + dimension*vec2(x/points, y))/screen; diff --git a/assets/cubyz/shaders/item_drop.fs b/assets/cubyz/shaders/item_drop.fs index a24c1cd9..616d7e19 100644 --- a/assets/cubyz/shaders/item_drop.fs +++ b/assets/cubyz/shaders/item_drop.fs @@ -204,7 +204,7 @@ void mainBlockDrop() { layout(std430, binding = 2) buffer _itemVoxelModels { - uint itemVoxelModels[]; + uint itemVoxelModels[]; }; uint getVoxel(uvec3 pos) { diff --git a/assets/cubyz/shaders/item_drop.vs b/assets/cubyz/shaders/item_drop.vs index 5891a130..f4043470 100644 --- a/assets/cubyz/shaders/item_drop.vs +++ b/assets/cubyz/shaders/item_drop.vs @@ -20,7 +20,7 @@ uniform float sizeScale; layout(std430, binding = 2) buffer _itemVoxelModels { - uint itemVoxelModels[]; + uint itemVoxelModels[]; }; #define modelSize 16 diff --git a/assets/cubyz/shaders/item_texture_post.fs b/assets/cubyz/shaders/item_texture_post.fs index 6f7eae46..863b9a0d 100644 --- a/assets/cubyz/shaders/item_texture_post.fs +++ b/assets/cubyz/shaders/item_texture_post.fs @@ -1,6 +1,6 @@ #version 430 out vec4 fragColor; - + in vec2 texCoords; uniform sampler2D color; diff --git a/format_check.py b/format_check.py new file mode 100644 index 00000000..cb13421a --- /dev/null +++ b/format_check.py @@ -0,0 +1,43 @@ +import os + +import sys + +directory = os.fsencode(".") + +fails = 0 + +for subdir, dirs, files in os.walk("."): + for file in files: + #print os.path.join(subdir, file) + filepath = subdir + os.sep + file + if filepath.startswith("./compiler"): continue + if filepath.startswith("./saves"): continue + if filepath.startswith("./serverAssets"): continue + if filepath.startswith("./zig-cache"): continue + + if filepath.endswith(".json") or filepath.endswith(".zig") or filepath.endswith(".py") or filepath.endswith(".zon") or filepath.endswith(".vs") or filepath.endswith(".fs") or filepath.endswith(".glsl"): + with open(filepath, "r") as f: + string = f.read() + line = 1 + lineStart = True + for i, c in enumerate(string): + if(c == '\r'): + print("Incorrect line ending \\r in file ", filepath, " in line ", line, ". Please configure your editor to use LF instead of CRLF.") + fails += 1 + elif(c == '\n'): + line += 1 + lineStart = True + elif(c == ' '): + if(lineStart): + print("Incorrect indentation in file ", filepath, " in line ", line, ". Please use tabs instead of spaces.") + fails += 1 + lineStart = False # avoid repeating this error multiple times + elif(c == '\t'): + continue + elif(lineStart): + lineStart = False + else: + continue +if(fails != 0): + sys.exit(1) +sys.exit(0) diff --git a/src/models.zig b/src/models.zig index 83d6081b..cafbfb2b 100644 --- a/src/models.zig +++ b/src/models.zig @@ -22,7 +22,7 @@ pub const QuadInfo = extern struct { }; fn approxEqAbs(x: Vec3f, y: Vec3f, tolerance: Vec3f) @Vector(3, bool) { - return @abs(x - y) <= tolerance; + return @abs(x - y) <= tolerance; } pub const Model = struct {