Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Format GDScript files #337

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# This file contains a list of Git commit hashes that should be hidden from the
# regular Git history. Typically, this includes commits involving mass auto-formatting
# or other normalizations. Commit hashes *must* use the full 40-character notation.
# To apply the ignore list in your local Git client, you must run:
#
# git config blame.ignoreRevsFile .git-blame-ignore-revs
#
# This file is automatically used by github.com's blame view.

# Format GDScript files
fdc1edd4d231782b51c5ae2a1e4f4a027a370b9f
53 changes: 35 additions & 18 deletions game/addons/openvic-plugin/ReleaseExportEditorPlugin.gd
Original file line number Diff line number Diff line change
@@ -1,35 +1,42 @@
extends EditorExportPlugin

var _repo_hash : StringName = "0000000000000000000000000000000000000000"
var _repo_short_hash : StringName = "0000000"
var _repo_tag : StringName = "<tag missing>"
var _repo_release_name : StringName = "<release name missing>"
var _repo_hash: StringName = "0000000000000000000000000000000000000000"
var _repo_short_hash: StringName = "0000000"
var _repo_tag: StringName = "<tag missing>"
var _repo_release_name: StringName = "<release name missing>"


func _get_name():
return "OpenVic-ReleaseExportEditorPlugin"


func _export_file(path: String, type: String, features: PackedStringArray) -> void:
if path != "res://src/GIT_INFO.gd": return
var GitInfoScript : String = ""
if path != "res://src/GIT_INFO.gd":
return
var GitInfoScript: String = ""
_get_commit_long()
_get_commit_short()
_get_tag()
_get_release_name()
GitInfoScript = "class_name _GIT_INFO_\nextends RefCounted\n\n"
GitInfoScript += "const commit_hash : StringName = &\""+ _repo_hash +"\"\n"
GitInfoScript += "const short_hash : StringName = &\""+ _repo_short_hash +"\"\n"
GitInfoScript += "const tag : StringName = &\""+ _repo_tag +"\"\n"
GitInfoScript += "const release_name : StringName = &\""+ _repo_release_name +"\"\n"
GitInfoScript += 'const commit_hash : StringName = &"' + _repo_hash + '"\n'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why use ' here and " everywhere else?
Is it purely to avoid "?

GitInfoScript += 'const short_hash : StringName = &"' + _repo_short_hash + '"\n'
GitInfoScript += 'const tag : StringName = &"' + _repo_tag + '"\n'
GitInfoScript += 'const release_name : StringName = &"' + _repo_release_name + '"\n'
add_file(path, GitInfoScript.to_ascii_buffer(), false)
skip()


# Based on
# https://github.com/godotengine/godot/blob/6ef2f358c741c993b5cdc9680489e2c4f5da25cc/methods.py#L102-L133
# REQUIREMENTS:
# * UIFUN-298
var _cached_hash : StringName = &""
var _cached_hash: StringName = &""


func _get_commit_hash() -> StringName:
if not _cached_hash.is_empty(): return _cached_hash
if not _cached_hash.is_empty():
return _cached_hash

var git_hash := OS.get_environment("OPENVIC_COMMIT")
if not git_hash.is_empty():
Expand All @@ -44,7 +51,9 @@ func _get_commit_hash() -> StringName:
git_folder = module_folder.substr(8)

if FileAccess.file_exists(git_folder.path_join("HEAD")):
var head := FileAccess.open(git_folder.path_join("HEAD"), FileAccess.READ).get_line().strip_edges()
var head := (
FileAccess.open(git_folder.path_join("HEAD"), FileAccess.READ).get_line().strip_edges()
)
if head.begins_with("ref: "):
var ref := head.substr(5)
var parts := git_folder.split("/")
Expand All @@ -55,8 +64,11 @@ func _get_commit_hash() -> StringName:
if FileAccess.file_exists(head):
git_hash = FileAccess.open(head, FileAccess.READ).get_line().strip_edges()
elif FileAccess.file_exists(packedrefs):
for line in FileAccess.open(packedrefs, FileAccess.READ).get_as_text().split("\n", false):
if line.begins_with("#"): continue
for line in FileAccess.open(packedrefs, FileAccess.READ).get_as_text().split(
"\n", false
):
if line.begins_with("#"):
continue
var line_split := line.split(" ")
var line_hash := line_split[0]
var line_ref = line_split[1]
Expand All @@ -70,10 +82,11 @@ func _get_commit_hash() -> StringName:

return git_hash


# REQUIREMENTS:
# * UIFUN-296
func _try_get_tag() -> StringName:
var result : StringName = OS.get_environment("OPENVIC_TAG")
var result: StringName = OS.get_environment("OPENVIC_TAG")
if result.is_empty():
var git_output := []
if OS.execute("git", ["describe", "--tags", "--abbrev=0"], git_output) == -1:
Expand All @@ -82,30 +95,34 @@ func _try_get_tag() -> StringName:
result = git_output[0].trim_suffix("\n")
return result


func _get_commit_long():
var result := _get_commit_hash()
if not result.is_empty():
_repo_hash = result
print("Hash: " + _repo_hash)


# REQUIREMENTS:
# * UIFUN-300
func _get_commit_short():
var result := _get_commit_hash().substr(0,7)
var result := _get_commit_hash().substr(0, 7)
if not result.is_empty():
_repo_short_hash = result
print("Short Hash: " + _repo_short_hash)


func _get_tag():
var result := _try_get_tag()
if not result.is_empty():
_repo_tag = result
print("Tag: " + _repo_tag)


# REQUIREMENTS:
# * UIFUN-295
func _get_release_name():
var result : StringName = OS.get_environment("OPENVIC_RELEASE")
var result: StringName = OS.get_environment("OPENVIC_RELEASE")
if result.is_empty():
result = _try_get_tag()
if not result.is_empty():
Expand Down
5 changes: 4 additions & 1 deletion game/addons/openvic-plugin/openvic-plugin.gd
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
@tool
extends EditorPlugin

const ReleaseExportEditorPlugin := preload("res://addons/openvic-plugin/ReleaseExportEditorPlugin.gd")
const ReleaseExportEditorPlugin := preload(
"res://addons/openvic-plugin/ReleaseExportEditorPlugin.gd"
)
var release_export_editor_plugin := ReleaseExportEditorPlugin.new()


func _enter_tree() -> void:
add_export_plugin(release_export_editor_plugin)

Expand Down
9 changes: 4 additions & 5 deletions game/src/GIT_INFO.gd
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
class_name _GIT_INFO_
extends RefCounted


const commit_hash : StringName = &"0000000000000000000000000000000000000000"
const short_hash : StringName = &"0000000"
const tag : StringName = &"<tag missing>"
const release_name : StringName = &"<release name missing>"
const commit_hash: StringName = &"0000000000000000000000000000000000000000"
const short_hash: StringName = &"0000000"
const tag: StringName = &"<tag missing>"
const release_name: StringName = &"<release name missing>"
80 changes: 50 additions & 30 deletions game/src/Game/Autoload/Argument/ArgumentOption.gd
Original file line number Diff line number Diff line change
Expand Up @@ -2,63 +2,83 @@
class_name ArgumentOption
extends Resource

@export var name : StringName
@export var aliases : Array[StringName] = []
@export var type : Variant.Type :
get: return type
@export var name: StringName
@export var aliases: Array[StringName] = []
@export var type: Variant.Type:
get:
return type
set(v):
type = v
match v:
TYPE_BOOL: default_value = false
TYPE_INT: default_value = 0
TYPE_FLOAT: default_value = 0.0
TYPE_STRING: default_value = ""
TYPE_STRING_NAME: default_value = &""
TYPE_PACKED_STRING_ARRAY: default_value = PackedStringArray()
TYPE_COLOR: default_value = Color()
_: default_value = null
TYPE_BOOL:
default_value = false
TYPE_INT:
default_value = 0
TYPE_FLOAT:
default_value = 0.0
TYPE_STRING:
default_value = ""
TYPE_STRING_NAME:
default_value = &""
TYPE_PACKED_STRING_ARRAY:
default_value = PackedStringArray()
TYPE_COLOR:
default_value = Color()
_:
default_value = null
notify_property_list_changed()
var default_value : Variant
@export var description : String
var default_value: Variant
@export var description: String

func _init(_name := "", _type := TYPE_NIL, _description := "", default : Variant = null) -> void:

func _init(_name := "", _type := TYPE_NIL, _description := "", default: Variant = null) -> void:
name = _name
type = _type
if default != null and typeof(default) == type:
default_value = default
description = _description

func add_alias(alias : StringName) -> ArgumentOption:

func add_alias(alias: StringName) -> ArgumentOption:
aliases.append(alias)
return self


func get_type_string() -> StringName:
match type:
TYPE_NIL: return "null"
TYPE_BOOL: return "boolean"
TYPE_INT: return "integer"
TYPE_FLOAT: return "float"
TYPE_STRING, TYPE_STRING_NAME: return "string"
TYPE_PACKED_STRING_ARRAY: return "string array"
TYPE_COLOR: return "color"
TYPE_NIL:
return "null"
TYPE_BOOL:
return "boolean"
TYPE_INT:
return "integer"
TYPE_FLOAT:
return "float"
TYPE_STRING, TYPE_STRING_NAME:
return "string"
TYPE_PACKED_STRING_ARRAY:
return "string array"
TYPE_COLOR:
return "color"
return "<invalid type>"

func _get(property : StringName) -> Variant:
if property == "default_value": return default_value

func _get(property: StringName) -> Variant:
if property == "default_value":
return default_value
return null

func _set(property : StringName, value : Variant) -> bool:

func _set(property: StringName, value: Variant) -> bool:
if property == "default_value":
default_value = value
return true
return false


func _get_property_list() -> Array[Dictionary]:
var properties := [] as Array[Dictionary]

properties.append({
"name": "default_value",
"type": type
})
properties.append({"name": "default_value", "type": type})

return properties
Loading
Loading