ref[protocol]: use strict syntax to refactor GdScript generation

This commit is contained in:
godotg
2025-04-06 11:59:41 +08:00
parent 90626c9d78
commit 62cf2bf019
4 changed files with 6 additions and 7 deletions
@@ -1,4 +1,4 @@
const ProtocolManager = preload("res://zfoogd/ProtocolManager.gd")
const ProtocolManager = preload("./ProtocolManager.gd")
const EMPTY: String = ""
@@ -4,9 +4,6 @@ ${protocol_field_definition}
func protocolId() -> int:
return ${protocol_id}
func get_class_name() -> String:
return "${protocol_name}"
func _to_string() -> String:
const jsonTemplate = "${protocol_json}"
var params = [${protocol_to_string}]
@@ -1,17 +1,17 @@
class ${protocol_name}Registration:
func write(buffer: ByteBuffer, packet: Object):
func write(buffer: ByteBuffer, packet: ${protocol_name}):
if (packet == null):
buffer.writeInt(0)
return
${protocol_write_serialization}
pass
func read(buffer: ByteBuffer):
func read(buffer: ByteBuffer) -> ${protocol_name}:
var length = buffer.readInt()
if (length == 0):
return null
var beforeReadIndex = buffer.getReadOffset()
var packet = buffer.newInstance(${protocol_id})
var packet: ${protocol_name} = buffer.newInstance(${protocol_id})
${protocol_read_deserialization}
if (length > 0):
buffer.setReadOffset(beforeReadIndex + length)
@@ -1,3 +1,5 @@
class_name ${protocol_name}
${protocol_imports}
${protocol_class}