mirror of
https://github.com/lihop/godot-xterm.git
synced 2025-05-04 04:14:22 +02:00
Add asciicast importer
This commit is contained in:
parent
55544de93e
commit
ffa8561865
11 changed files with 199 additions and 77 deletions
69
addons/godot_xterm/import_plugins/asciicast_import_plugin.gd
Normal file
69
addons/godot_xterm/import_plugins/asciicast_import_plugin.gd
Normal file
|
@ -0,0 +1,69 @@
|
|||
tool
|
||||
extends EditorImportPlugin
|
||||
|
||||
const Asciicast = preload("res://addons/godot_xterm/resources/asciicast.gd")
|
||||
|
||||
|
||||
func get_importer_name():
|
||||
return "godot_xterm"
|
||||
|
||||
|
||||
func get_visible_name():
|
||||
return "asciicast"
|
||||
|
||||
|
||||
func get_recognized_extensions():
|
||||
return ["cast"]
|
||||
|
||||
|
||||
func get_save_extension():
|
||||
return "res"
|
||||
|
||||
|
||||
func get_resource_type():
|
||||
return "Animation"
|
||||
|
||||
|
||||
func get_import_options(preset):
|
||||
return []
|
||||
|
||||
|
||||
func get_preset_count():
|
||||
return 0
|
||||
|
||||
|
||||
func import(source_file, save_path, options, r_platform_variant, r_gen_files):
|
||||
var file = File.new()
|
||||
var err = file.open(source_file, File.READ)
|
||||
if err != OK:
|
||||
return err
|
||||
|
||||
var header = file.get_line()
|
||||
|
||||
var asciicast = Asciicast.new()
|
||||
|
||||
asciicast.add_track(Animation.TYPE_METHOD, 0)
|
||||
asciicast.track_set_path(0, ".")
|
||||
|
||||
var time: float
|
||||
|
||||
while not file.eof_reached():
|
||||
var line = file.get_line()
|
||||
if line == "":
|
||||
continue
|
||||
|
||||
var p = JSON.parse(line)
|
||||
if typeof(p.result) != TYPE_ARRAY:
|
||||
continue
|
||||
|
||||
time = p.result[0]
|
||||
var event_type: String = p.result[1]
|
||||
var event_data: PoolByteArray = p.result[2].to_utf8()
|
||||
|
||||
if event_type == "o":
|
||||
asciicast.track_insert_key(0, time, {"method": "write",
|
||||
"args": [event_data]})
|
||||
|
||||
asciicast.length = time
|
||||
|
||||
return ResourceSaver.save("%s.%s" % [save_path, get_save_extension()], asciicast)
|
|
@ -1,16 +0,0 @@
|
|||
extends Node
|
||||
|
||||
|
||||
# Declare member variables here. Examples:
|
||||
# var a = 2
|
||||
# var b = "text"
|
||||
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready():
|
||||
pass # Replace with function body.
|
||||
|
||||
|
||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
#func _process(delta):
|
||||
# pass
|
|
@ -2,7 +2,16 @@ tool
|
|||
extends EditorPlugin
|
||||
|
||||
|
||||
var asciicast_import_plugin
|
||||
|
||||
|
||||
func _enter_tree():
|
||||
asciicast_import_plugin = preload("res://addons/godot_xterm/import_plugins/asciicast_import_plugin.gd").new()
|
||||
add_import_plugin(asciicast_import_plugin)
|
||||
|
||||
var asciicast_script = preload("res://addons/godot_xterm/resources/asciicast.gd")
|
||||
add_custom_type("Asciicast", "Animation", asciicast_script, null)
|
||||
|
||||
var terminal_script = preload("res://addons/godot_xterm/nodes/terminal/terminal.gdns")
|
||||
var terminal_icon = preload("res://addons/godot_xterm/nodes/terminal/terminal_icon.svg")
|
||||
add_custom_type("Terminal", "Control", terminal_script, terminal_icon)
|
||||
|
@ -13,5 +22,9 @@ func _enter_tree():
|
|||
|
||||
|
||||
func _exit_tree():
|
||||
remove_import_plugin(asciicast_import_plugin)
|
||||
asciicast_import_plugin = null
|
||||
|
||||
remove_custom_type("Asciicast")
|
||||
remove_custom_type("Terminal")
|
||||
remove_custom_type("Psuedoterminal")
|
||||
|
|
19
addons/godot_xterm/resources/asciicast.gd
Normal file
19
addons/godot_xterm/resources/asciicast.gd
Normal file
|
@ -0,0 +1,19 @@
|
|||
extends Animation
|
||||
|
||||
|
||||
signal data_written(data)
|
||||
signal data_read(data)
|
||||
|
||||
export(int) var version: int = 2
|
||||
# Initial terminal width (number of columns).
|
||||
export(int) var width: int
|
||||
# Initial terminal height (number of rows).
|
||||
export(int) var height: int
|
||||
|
||||
|
||||
func get_class() -> String:
|
||||
return "Asciicast"
|
||||
|
||||
|
||||
func is_class(name) -> bool:
|
||||
return name == get_class() or .is_class(name)
|
Loading…
Add table
Add a link
Reference in a new issue