This commit is contained in:
2026-01-21 23:40:20 +01:00
commit d1f8068081
478 changed files with 24902 additions and 0 deletions

View File

@@ -0,0 +1,23 @@
# Contributors
This addon, and the entirety of [netfox] is a shared effort of [Fox's Sake
Studio], and the community. The following is the list of community contributors
involved with netfox:
* Alberto Klocker <albertok@gmail.com>
* Bryan Lee <42545742+bryanmylee@users.noreply.github.com>
* Dustie <77035922+DustieDog@users.noreply.github.com>
* Jake Cattrall <krazyjakee@gmail.com>
* Jon Stevens <1030863+jonstvns@users.noreply.github.com>
* Joseph Michael Ware <9at25jnr3@mozmail.com>
* Nicolas Batty <nicolas.batty@gmail.com>
* Riordan-DC <44295008+Riordan-DC@users.noreply.github.com>
* Ryan Roden-Corrent <github@rcorre.net>
* TheYellowArchitect <dmalandris@uth.gr>
* TheYellowArchitect <hello@theyellowarchitect.com>
* gk98s <89647115+gk98s@users.noreply.github.com>
* zibetnu <9at25jnr3@mozmail.com>
[netfox]: https://github.com/foxssake/netfox
[Fox's Sake Studio]: https://github.com/foxssake/

View File

@@ -0,0 +1,18 @@
Copyright 2023 Gálffy Tamás
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

View File

@@ -0,0 +1,8 @@
# netfox.internals
Shared utilities for [netfox] addons. Not intended for standalone usage.
Instead, check out the other addons in the [netfox] repository.
[netfox]: https://github.com/foxssake/netfox

View File

@@ -0,0 +1,44 @@
extends Object
class_name _NetfoxEditorUtils
static func gather_properties(root: Node, callback_name: String, handler: Callable) -> Array[String]:
var result: Array[String] = []
var nodes: Array[Node] = root.find_children("*")
nodes.push_front(root)
for node in nodes:
if not node.has_method(callback_name):
continue
var readable_node_name := "\"%s\" (\"%s\")" % [node.name, root.get_path_to(node)]
if node.get(callback_name) == null:
result.push_back("Can't grab method \"%s\" from node %s! Is it a @tool?" % [callback_name, readable_node_name])
continue
var props = node.get(callback_name).call()
if not props is Array:
result.push_back("Node %s didn't return an array on calling \"%s\"" % [readable_node_name, callback_name])
continue
for prop in props:
if prop is String:
# Property is a string, meaning property path relative to node
handler.call(node, prop)
elif prop is Array and prop.size() >= 2:
# Property is a node-property tuple
var prop_node: Node = null
# Node can be a String, NodePath, or an actual Node
if prop[0] is String or prop[0] is NodePath:
prop_node = node.get_node(prop[0])
elif prop[0] is Node:
prop_node = prop[0]
else:
result.push_back("Node %s specified invalid node in \"%s\": %s" % [readable_node_name, callback_name, prop])
continue
handler.call(prop_node, prop[1])
else:
result.push_back("Node %s specified invalid property in \"%s\": %s" % [readable_node_name, callback_name, prop])
return result

View File

@@ -0,0 +1 @@
uid://0ohd4n5yjilb

View File

@@ -0,0 +1,66 @@
extends RefCounted
class_name _HistoryBuffer
# Maps ticks (int) to arbitrary data
var _buffer: Dictionary = {}
func get_snapshot(tick: int):
if _buffer.has(tick):
return _buffer[tick]
else:
return null
func set_snapshot(tick: int, data):
_buffer[tick] = data
func get_buffer() -> Dictionary:
return _buffer
func get_closest_tick(tick: int) -> int:
if _buffer.has(tick):
return tick
if _buffer.is_empty():
return -1
var earliest_tick = _buffer.keys().min()
if tick < earliest_tick:
return earliest_tick
var latest_tick = _buffer.keys().max()
if tick > latest_tick:
return latest_tick
return _buffer.keys() \
.filter(func (key): return key < tick) \
.max()
func get_history(tick: int):
var closest_tick = get_closest_tick(tick)
return _buffer.get(closest_tick)
func trim(earliest_tick_to_keep: int):
var ticks := _buffer.keys()
for tick in ticks:
if tick < earliest_tick_to_keep:
_buffer.erase(tick)
func clear():
_buffer.clear()
func size() -> int:
return _buffer.size()
func is_empty() -> bool:
return _buffer.is_empty()
func has(tick) -> bool:
return _buffer.has(tick)
func ticks() -> Array:
return _buffer.keys()
func erase(tick):
_buffer.erase(tick)

View File

@@ -0,0 +1 @@
uid://btuvvlw3jkx2e

View File

@@ -0,0 +1,146 @@
extends RefCounted
class_name _NetfoxLogger
enum {
LOG_MIN,
LOG_TRACE,
LOG_DEBUG,
LOG_INFO,
LOG_WARN,
LOG_ERROR,
LOG_MAX
}
const DEFAULT_LOG_LEVEL := LOG_DEBUG
static var log_level: int
static var module_log_level: Dictionary
static var _tags: Dictionary = {}
static var _ordered_tags: Array[Callable] = []
var module: String
var name: String
const level_prefixes: Array[String] = [
"",
"TRC",
"DBG",
"INF",
"WRN",
"ERR",
""
]
static func for_netfox(p_name: String) -> _NetfoxLogger:
return _NetfoxLogger.new("netfox", p_name)
static func for_noray(p_name: String) -> _NetfoxLogger:
return _NetfoxLogger.new("netfox.noray", p_name)
static func for_extras(p_name: String) -> _NetfoxLogger:
return _NetfoxLogger.new("netfox.extras", p_name)
static func make_setting(name: String) -> Dictionary:
return {
"name": name,
"value": DEFAULT_LOG_LEVEL,
"type": TYPE_INT,
"hint": PROPERTY_HINT_ENUM,
"hint_string": "All,Trace,Debug,Info,Warning,Error,None"
}
static func register_tag(tag: Callable, priority: int = 0) -> void:
# Save tag
if not _tags.has(priority):
_tags[priority] = [tag]
else:
_tags[priority].push_back(tag)
# Recalculate tag order
_ordered_tags.clear()
var prio_groups = _tags.keys()
prio_groups.sort()
for prio_group in prio_groups:
var tag_group = _tags[prio_group]
_ordered_tags.append_array(tag_group)
static func free_tag(tag: Callable) -> void:
for priority in _tags.keys():
var priority_group := _tags[priority] as Array
priority_group.erase(tag)
# NOTE: Arrays are passed as reference, no need to re-assign after modifying
if priority_group.is_empty():
_tags.erase(priority)
_ordered_tags.erase(tag)
static func _static_init():
log_level = ProjectSettings.get_setting("netfox/logging/log_level", DEFAULT_LOG_LEVEL)
module_log_level = {
"netfox": ProjectSettings.get_setting("netfox/logging/netfox_log_level", DEFAULT_LOG_LEVEL),
"netfox.noray": ProjectSettings.get_setting("netfox/logging/netfox_noray_log_level", DEFAULT_LOG_LEVEL),
"netfox.extras": ProjectSettings.get_setting("netfox/logging/netfox_extras_log_level", DEFAULT_LOG_LEVEL)
}
func _init(p_module: String, p_name: String):
module = p_module
name = p_name
func _check_log_level(level: int) -> bool:
var cmp_level = log_level
if level < cmp_level:
return false
if module_log_level.has(module):
var module_level = module_log_level.get(module)
return level >= module_level
return true
func _format_text(text: String, values: Array, level: int) -> String:
level = clampi(level, LOG_MIN, LOG_MAX)
var result := PackedStringArray()
result.append("[%s]" % [level_prefixes[level]])
for tag in _ordered_tags:
result.append("[%s]" % [tag.call()])
result.append("[%s::%s] " % [module, name])
if values.is_empty():
result.append(text)
else:
result.append(text % values)
return "".join(result)
func _log_text(text: String, values: Array, level: int):
if _check_log_level(level):
print(_format_text(text, values, level))
func trace(text: String, values: Array = []):
_log_text(text, values, LOG_TRACE)
func debug(text: String, values: Array = []):
_log_text(text, values, LOG_DEBUG)
func info(text: String, values: Array = []):
_log_text(text, values, LOG_INFO)
func warning(text: String, values: Array = []):
if _check_log_level(LOG_WARN):
var formatted_text = _format_text(text, values, LOG_WARN)
push_warning(formatted_text)
# Print so it shows up in the Output panel too
print(formatted_text)
func error(text: String, values: Array = []):
if _check_log_level(LOG_ERROR):
var formatted_text = _format_text(text, values, LOG_ERROR)
push_error(formatted_text)
# Print so it shows up in the Output panel too
print(formatted_text)

View File

@@ -0,0 +1 @@
uid://dp4rakv0drj1f

View File

@@ -0,0 +1,7 @@
[plugin]
name="netfox.internals"
description="Shared internals for netfox addons"
author="Tamas Galffy and contributors"
version="1.25.3"
script="plugin.gd"

View File

@@ -0,0 +1,34 @@
@tool
extends EditorPlugin
var SETTINGS = [
_NetfoxLogger.make_setting("netfox/logging/log_level")
]
func _enter_tree():
for setting in SETTINGS:
add_setting(setting)
func _exit_tree():
if ProjectSettings.get_setting("netfox/general/clear_settings", false):
for setting in SETTINGS:
remove_setting(setting)
func add_setting(setting: Dictionary):
if ProjectSettings.has_setting(setting.name):
return
ProjectSettings.set_setting(setting.name, setting.value)
ProjectSettings.set_initial_value(setting.name, setting.value)
ProjectSettings.add_property_info({
"name": setting.get("name"),
"type": setting.get("type"),
"hint": setting.get("hint", PROPERTY_HINT_NONE),
"hint_string": setting.get("hint_string", "")
})
func remove_setting(setting: Dictionary):
if not ProjectSettings.has_setting(setting.name):
return
ProjectSettings.clear(setting.name)

View File

@@ -0,0 +1 @@
uid://bvhj7f66i6yl4

View File

@@ -0,0 +1,34 @@
extends RefCounted
class_name _RingBuffer
var _data: Array
var _capacity: int
var _size: int = 0
var _head: int = 0
func _init(p_capacity: int):
_capacity = p_capacity
_data = []
_data.resize(p_capacity)
func push(item):
_data[_head] = item
_size += 1
_head = (_head + 1) % _capacity
func get_data() -> Array:
if _size < _capacity:
return _data.slice(0, _size)
else:
return _data
func size() -> int:
return _size
func is_empty() -> bool:
return _size == 0
func clear():
_size = 0
_head = 0

View File

@@ -0,0 +1 @@
uid://cmfbs3cx33lkw

View File

@@ -0,0 +1,64 @@
extends RefCounted
class_name _Set
var _data: Dictionary = {}
var _iterator_idx: int = -1
static func of(items: Array) -> _Set:
var result := _Set.new()
for item in items:
result.add(item)
return result
func add(value):
_data[value] = true
func has(value) -> bool:
return _data.has(value)
func size() -> int:
return _data.size()
func is_empty() -> bool:
return _data.is_empty()
func erase(value):
return _data.erase(value)
func clear():
_data.clear()
func values() -> Array:
return _data.keys()
func min():
return _data.keys().min()
func max():
return _data.keys().max()
func equals(other) -> bool:
if not other or not other is _Set:
return false
return values() == other.values()
func _to_string():
return "Set" + str(values())
func _iter_init(arg) -> bool:
_iterator_idx = 0
return _can_iterate()
func _iter_next(arg) -> bool:
_iterator_idx += 1
return _can_iterate()
func _iter_get(arg):
return _data.keys()[_iterator_idx]
func _can_iterate() -> bool:
if _data.is_empty() or _iterator_idx >= _data.size():
_iterator_idx = -1
return false
return true

View File

@@ -0,0 +1 @@
uid://bjvmp7eed1aj0