Files
whale-town-front/addons/gut/one_to_many.gd
WhaleTown Developer c8e73bec59 fix: 修复聊天系统编译错误
- 修复 WebSocketManager/SocketIOClient 函数缩进错误
- 重命名 is_connected() 避免与 Object 基类冲突
- 修复 tscn 文件多余前导空格
- 修复测试文件 GUT 断言函数调用
- 添加 GUT 测试框架
2026-01-08 00:11:12 +08:00

44 lines
1.1 KiB
GDScript

# ------------------------------------------------------------------------------
# This datastructure represents a simple one-to-many relationship. It manages
# a dictionary of value/array pairs. It ignores duplicates of both the "one"
# and the "many".
# ------------------------------------------------------------------------------
var items = {}
# return the size of items or the size of an element in items if "one" was
# specified.
func size(one=null):
var to_return = 0
if(one == null):
to_return = items.size()
elif(items.has(one)):
to_return = items[one].size()
return to_return
# Add an element to "one" if it does not already exist
func add(one, many_item):
if(items.has(one)):
if(!items[one].has(many_item)):
items[one].append(many_item)
else:
items[one] = [many_item]
func clear():
items.clear()
func has(one, many_item):
var to_return = false
if(items.has(one)):
to_return = items[one].has(many_item)
return to_return
func to_s():
var to_return = ''
for key in items:
to_return += str(key, ": ", items[key], "\n")
return to_return