Skip to content

Commit

Permalink
Merge pull request #1 from goostengine/grid-layer
Browse files Browse the repository at this point in the history
  • Loading branch information
Xrayez authored Sep 14, 2021
2 parents ac93194 + bbbb748 commit 3028f2f
Show file tree
Hide file tree
Showing 7 changed files with 118 additions and 5 deletions.
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ extension.

## List of plugins

| Plugin | Short description | Depends on |
| ------------------- | ------------------------------------------------ | -------------------------------------------- |
| GDScript Transpiler | Adds an editor interface for transpiling scripts | `gdscript_transpiler` module (experimental). |
| Plugin | Short description | Depends on |
| -------------------- | ------------------------------------------------- | ------------------------------------------- |
| `GridLayer` | Displays infinite grid at run-time. | `GridRect` class |
| `GDScriptTranspiler` | Adds an editor interface for transpiling scripts. | `gdscript_transpiler` module (experimental) |

## Compatibility

Expand Down
62 changes: 62 additions & 0 deletions addons/grid_layer/grid_layer.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
class_name GridLayer, "icon_grid_layer.svg" extends CanvasLayer
tool

# This class allows to display infinite grid at run-time, similarly to how
# editor displays grid with snapping is enabled in canvas editor.
# For example, when using Camera2D, the grid's origin offset and scale are
# going to be updated automatically.

func _init():
# Do not show grid on top, since we have transparent grid by default.
layer = -1


func _ready():
if not Engine.editor_hint:
return

# Instantiate a default GridRect with transparent background.
var grid = GridRect.new()
add_child(grid)
if get_parent():
if get_parent().filename:
grid.owner = get_parent()
else:
grid.owner = get_parent().owner

grid.origin_axes_visible = true

grid.anchor_right = 1.0
grid.anchor_bottom = 1.0
grid.margin_right = 0.0
grid.margin_bottom = 0.0

var bc = Color()
bc.a = 0.0 # Transparent by default.
grid.set("custom_colors/background", bc)
# Use default colors from GraphEdit.
grid.set("custom_colors/line_cell", grid.get_color("grid_minor", "GraphEdit"))
grid.set("custom_colors/line_division", grid.get_color("grid_major", "GraphEdit"))


func _process(_delta):
for idx in get_child_count():
var grid = get_child(idx)
if not grid is GridRect:
continue

grid.origin_offset = get_viewport().canvas_transform.origin
grid.origin_scale = get_viewport().canvas_transform.get_scale()


func _get_configuration_warning():
if not has_grid():
return "GridLayer must have at least one GridRect added as a child."
return ""


func has_grid():
for idx in get_child_count():
if get_child(idx) is GridRect:
return true
return false
2 changes: 2 additions & 0 deletions addons/grid_layer/grid_layer_plugin.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
tool
extends EditorPlugin
1 change: 1 addition & 0 deletions addons/grid_layer/icon_grid_layer.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
34 changes: 34 additions & 0 deletions addons/grid_layer/icon_grid_layer.svg.import
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
[remap]

importer="texture"
type="StreamTexture"
path="res://.import/icon_grid_layer.svg-4d36d2a91fa21a54de7ea7a412dae37f.stex"
metadata={
"vram_texture": false
}

[deps]

source_file="res://addons/grid_layer/icon_grid_layer.svg"
dest_files=[ "res://.import/icon_grid_layer.svg-4d36d2a91fa21a54de7ea7a412dae37f.stex" ]

[params]

compress/mode=0
compress/lossy_quality=0.7
compress/hdr_mode=0
compress/bptc_ldr=0
compress/normal_map=0
flags/repeat=0
flags/filter=true
flags/mipmaps=false
flags/anisotropic=false
flags/srgb=2
process/fix_alpha_border=true
process/premult_alpha=false
process/HDR_as_SRGB=false
process/invert_color=false
stream=false
size_limit=0
detect_3d=true
svg/scale=1.0
7 changes: 7 additions & 0 deletions addons/grid_layer/plugin.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[plugin]

name="GridLayer"
description="Display infinite grid at run-time"
author="Goost"
version="0.1"
script="grid_layer_plugin.gd"
10 changes: 8 additions & 2 deletions project.godot
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,15 @@ _global_script_classes=[ {
"class": "GoostImageTiling",
"language": "GDScript",
"path": "res://ports/image_tiling.gd"
}, {
"base": "CanvasLayer",
"class": "GridLayer",
"language": "GDScript",
"path": "res://addons/grid_layer/grid_layer.gd"
} ]
_global_script_class_icons={
"GoostImageTiling": ""
"GoostImageTiling": "",
"GridLayer": "res://addons/grid_layer/icon_grid_layer.svg"
}

[application]
Expand All @@ -25,4 +31,4 @@ config/icon="res://icon.png"

[editor_plugins]

enabled=PoolStringArray( "gdscript_transpiler" )
enabled=PoolStringArray( "res://addons/grid_layer/plugin.cfg" )

0 comments on commit 3028f2f

Please sign in to comment.