Skip to content

Commit

Permalink
added level checker plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
themangomago committed Apr 11, 2021
1 parent d347e95 commit 228fd84
Show file tree
Hide file tree
Showing 7 changed files with 197 additions and 2 deletions.
1 change: 1 addition & 0 deletions Src/Menu/Menu.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ margin_bottom = 328.0
label = "Exit"

[node name="Settings" type="Control" parent="."]
visible = false
anchor_right = 1.0
anchor_bottom = 1.0
__meta__ = {
Expand Down
2 changes: 1 addition & 1 deletion Src/_Autoloads/Global.gd
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
extends Node

# Version
const GAME_VERSION = 0.3
const GAME_VERSION = 0.5
const CONFIG_VERSION = 1 # Used for config migration

# Debug Options
Expand Down
73 changes: 73 additions & 0 deletions addons/LevelChecker/LevelChecker.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
tool
extends Control
class_name LevelChecker

var options = []

var parserNameToken = ""
var parserNameTokenLine = 0
var parserFindings = []

# Called when the node enters the scene tree for the first time.
func _ready():
_on_UpdateList_button_up()


func createFinding(token: String, findLine: int, findLineText: String):
parserFindings.append({"token": token, "findLine": findLine, "findLineText": findLineText})


func interpretLine(idx: int, line: String):
if line.begins_with("[node name="):
#New Token found - Replace old
line = line.right(12)
var end = line.find("\"",0)
line = line.substr(0, end)
parserNameToken = line
parserNameTokenLine = idx
elif line.begins_with("position"):
#Parse Position
if line.find(".", 20) != -1:
#Found
createFinding(parserNameToken, idx, line.right(20).trim_suffix(")"))

func updateFindings():
$OptionButton/TextEdit.text = ""
for line in parserFindings:
$OptionButton/TextEdit.text += str(line.findLine) + ": " + line.token + " -> " + line.findLineText + "\n"


func _on_Scan_button_up():
parserFindings = []
var activeFileId = $OptionButton.selected
var file = File.new()
file.open("res://Src/Levels/" + options[activeFileId], File.READ)

var lineIdx = 1
while not file.eof_reached():
interpretLine(lineIdx, file.get_line())
lineIdx += 1

file.close()
updateFindings()


func _on_UpdateList_button_up():
var dir = Directory.new()

if dir.open("res://Src/Levels/") == OK:
$OptionButton.clear()
options = []

dir.list_dir_begin(true)
var file_name = dir.get_next()
while file_name != "":
if not dir.current_is_dir():
if file_name.get_extension() == "tscn":
options.append(file_name)
$OptionButton.add_item(file_name, options.size() - 1)
file_name = dir.get_next()
dir.close()

func _on_FixFindings_button_up():
pass # Replace with function body.
75 changes: 75 additions & 0 deletions addons/LevelChecker/LevelChecker.tscn
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
[gd_scene load_steps=2 format=2]

[ext_resource path="res://addons/LevelChecker/LevelChecker.gd" type="Script" id=1]

[node name="LevelChecker" type="WindowDialog"]
margin_left = 8.0
margin_top = 24.0
margin_right = 648.0
margin_bottom = 504.0
script = ExtResource( 1 )

[node name="Panel" type="Panel" parent="."]
anchor_right = 1.0
anchor_bottom = 1.0
__meta__ = {
"_edit_use_anchors_": false
}

[node name="Label" type="Label" parent="."]
margin_left = 24.0
margin_top = 16.0
margin_right = 64.0
margin_bottom = 47.0
text = "Pixel Position Scan
"
__meta__ = {
"_edit_use_anchors_": false
}

[node name="OptionButton" type="OptionButton" parent="."]
margin_left = 24.0
margin_top = 40.0
margin_right = 296.0
margin_bottom = 64.0
text = "HQ_Level.tscn"
items = [ "HQ_Level.tscn", null, false, 0, null, "Level1.tscn", null, false, 1, null, "Level10.tscn", null, false, 2, null, "Level18.tscn", null, false, 3, null, "Level19.tscn", null, false, 4, null, "Level2.tscn", null, false, 5, null, "Level3.tscn", null, false, 6, null, "Level4.tscn", null, false, 7, null, "Level5.tscn", null, false, 8, null, "Level6.tscn", null, false, 9, null, "Level7.tscn", null, false, 10, null, "Level8.tscn", null, false, 11, null, "Level9.tscn", null, false, 12, null, "LevelX.tscn", null, false, 13, null, "TestLevel.tscn", null, false, 14, null ]
selected = 0
__meta__ = {
"_edit_use_anchors_": false
}

[node name="Scan" type="Button" parent="OptionButton"]
margin_left = 400.0
margin_right = 448.0
margin_bottom = 24.0
text = "Scan Selected"
__meta__ = {
"_edit_use_anchors_": false
}

[node name="UpdateList" type="Button" parent="OptionButton"]
margin_left = 280.0
margin_right = 383.0
margin_bottom = 24.0
text = "Update List"
__meta__ = {
"_edit_use_anchors_": false
}

[node name="FixFindings" type="Button" parent="OptionButton"]
margin_left = 512.0
margin_right = 560.0
margin_bottom = 24.0
text = "Fix Findings"
__meta__ = {
"_edit_use_anchors_": false
}

[node name="TextEdit" type="TextEdit" parent="OptionButton"]
margin_top = 32.0
margin_right = 600.0
margin_bottom = 280.0
[connection signal="button_up" from="OptionButton/Scan" to="." method="_on_Scan_button_up"]
[connection signal="button_up" from="OptionButton/UpdateList" to="." method="_on_UpdateList_button_up"]
[connection signal="button_up" from="OptionButton/FixFindings" to="." method="_on_FixFindings_button_up"]
27 changes: 27 additions & 0 deletions addons/LevelChecker/LevelCheckerPlugin.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
tool
extends EditorPlugin
class_name LevelCheckerPlugin

signal editor_visible

const editor_scn: PackedScene = preload("res://addons/LevelChecker/LevelChecker.tscn")
var editor: Control = editor_scn.instance()


func _enter_tree() -> void:
add_tool_menu_item("LevelChecker", self, "_callback")


func _exit_tree() -> void:
remove_tool_menu_item("LevelChecker")
editor.free()


func _callback(_u):
print("callback")
add_child(editor)
editor.popup()




7 changes: 7 additions & 0 deletions addons/LevelChecker/plugin.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[plugin]

name="LevelChecker"
description="LevelChecker Tool"
author="mago"
version="1.0"
script="LevelCheckerPlugin.gd"
14 changes: 13 additions & 1 deletion project.godot
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,16 @@ _global_script_classes=[ {
"language": "GDScript",
"path": "res://Src/HideOuts/HideOutBase.gd"
}, {
"base": "Control",
"class": "LevelChecker",
"language": "GDScript",
"path": "res://addons/LevelChecker/LevelChecker.gd"
}, {
"base": "EditorPlugin",
"class": "LevelCheckerPlugin",
"language": "GDScript",
"path": "res://addons/LevelChecker/LevelCheckerPlugin.gd"
}, {
"base": "MinigameSpawner",
"class": "LightMinigameSpawner",
"language": "GDScript",
Expand Down Expand Up @@ -153,6 +163,8 @@ _global_script_class_icons={
"DoorWall": "",
"Guard": "",
"HideOutBase": "",
"LevelChecker": "",
"LevelCheckerPlugin": "",
"LightMinigameSpawner": "",
"Lights": "",
"LockpickMinigameSpawner": "",
Expand Down Expand Up @@ -208,7 +220,7 @@ window/stretch/aspect="keep"

[editor_plugins]

enabled=PoolStringArray( "DialogueEditor", "quentincaffeino-console" )
enabled=PoolStringArray( "DialogueEditor", "LevelChecker", "quentincaffeino-console" )

[importer_defaults]

Expand Down

0 comments on commit 228fd84

Please sign in to comment.