First commit 🎉
This commit is contained in:
commit
43ea213f9b
728 changed files with 37080 additions and 0 deletions
237
addons/popochiu/editor/factories/factory_base_popochiu_obj.gd
Normal file
237
addons/popochiu/editor/factories/factory_base_popochiu_obj.gd
Normal file
|
@ -0,0 +1,237 @@
|
|||
extends RefCounted
|
||||
|
||||
const BASE_STATE_TEMPLATE := "res://addons/popochiu/engine/templates/%s_state_template.gd"
|
||||
const BASE_SCRIPT_TEMPLATE := "res://addons/popochiu/engine/templates/%s_template.gd"
|
||||
const BASE_SCENE_PATH := "res://addons/popochiu/engine/objects/%s/popochiu_%s.tscn"
|
||||
const EMPTY_SCRIPT := "res://addons/popochiu/engine/templates/empty_script_template.gd"
|
||||
|
||||
# The following variables are setup on creation Names variants and name parameter passed to the
|
||||
# create method.
|
||||
var _path_template := "" # always set by child class
|
||||
var _snake_name := ""
|
||||
var _pascal_name := ""
|
||||
var _path_base := ""
|
||||
var _path_scene = ""
|
||||
var _path_resource = ""
|
||||
var _path_state = ""
|
||||
var _path_script := ""
|
||||
# The following variables are setup by the sub-class constructor to define the type of object to be
|
||||
# processed
|
||||
# TODO: reduce this to just "type", too much redundancy
|
||||
var _type := -1
|
||||
var _type_label := ""
|
||||
var _type_target := ""
|
||||
var _type_method: Callable
|
||||
# The following variables are references to the elements generated for the creation of the new
|
||||
# Popochiu object, such as resources, scenes, scripts, state scripts, etc
|
||||
var _scene: Node
|
||||
var _resource: Resource
|
||||
var _state_resource: Resource
|
||||
var _script: Resource
|
||||
|
||||
|
||||
#region Public #####################################################################################
|
||||
func get_obj_scene() -> Node:
|
||||
return _scene
|
||||
|
||||
|
||||
func get_snake_name() -> String:
|
||||
return _snake_name
|
||||
|
||||
|
||||
func get_obj_resource() -> Resource:
|
||||
return _resource
|
||||
|
||||
|
||||
func get_state_resource() -> Resource:
|
||||
return _state_resource
|
||||
|
||||
|
||||
func get_obj_script() -> Resource:
|
||||
return _script
|
||||
|
||||
|
||||
func get_scene_path() -> String:
|
||||
return _path_scene
|
||||
|
||||
|
||||
func get_type() -> int:
|
||||
return _type
|
||||
|
||||
|
||||
func get_type_method() -> Callable:
|
||||
return _type_method
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
#region Private ####################################################################################
|
||||
func _setup_name(obj_name: String) -> void:
|
||||
_pascal_name = obj_name.to_pascal_case()
|
||||
_snake_name = obj_name.to_snake_case()
|
||||
_path_base = _path_template % [_snake_name, _snake_name]
|
||||
_path_script = _path_base + ".gd"
|
||||
_path_state = _path_base + "_state.gd"
|
||||
_path_resource = _path_base + ".tres"
|
||||
_path_scene = _path_base + ".tscn"
|
||||
|
||||
|
||||
func _create_obj_folder() -> int:
|
||||
# TODO: Remove created files if the creation process failed.
|
||||
if DirAccess.make_dir_recursive_absolute(_path_base.get_base_dir()) != OK:
|
||||
PopochiuUtils.print_error(
|
||||
"Could not create %s directory: %s" %
|
||||
[_path_base.get_base_dir(), _pascal_name]
|
||||
)
|
||||
return ResultCodes.ERR_CANT_CREATE_OBJ_FOLDER
|
||||
return ResultCodes.SUCCESS
|
||||
|
||||
|
||||
func _create_state_resource() -> int:
|
||||
var state_template: Script = load(
|
||||
BASE_STATE_TEMPLATE % _type_label
|
||||
).duplicate()
|
||||
|
||||
if ResourceSaver.save(state_template, _path_state) != OK:
|
||||
PopochiuUtils.print_error(
|
||||
"Could not create %s state script: %s" %
|
||||
[_type_label, _pascal_name]
|
||||
)
|
||||
return ResultCodes.FAILURE
|
||||
|
||||
_state_resource = load(_path_state).new()
|
||||
_state_resource.script_name = _pascal_name
|
||||
_state_resource.scene = _path_scene
|
||||
_state_resource.resource_name = _pascal_name
|
||||
|
||||
if ResourceSaver.save(_state_resource, _path_resource) != OK:
|
||||
PopochiuUtils.print_error(
|
||||
"Could not create state resource for %s: %s" %
|
||||
[_type_label, _pascal_name]
|
||||
)
|
||||
return ResultCodes.ERR_CANT_CREATE_OBJ_STATE
|
||||
|
||||
return ResultCodes.SUCCESS
|
||||
|
||||
|
||||
func _copy_script_template() -> int:
|
||||
var _script: Script = load(
|
||||
BASE_SCRIPT_TEMPLATE % _type_label
|
||||
).duplicate()
|
||||
|
||||
if ResourceSaver.save( _script, _path_script) != OK:
|
||||
PopochiuUtils.print_error(
|
||||
"Could not create %s script: %s" %
|
||||
[_type_label, _path_script]
|
||||
)
|
||||
return ResultCodes.ERR_CANT_CREATE_OBJ_SCRIPT
|
||||
|
||||
return ResultCodes.SUCCESS
|
||||
|
||||
|
||||
## Create the script for the object based on the template of its type.
|
||||
func _create_script_from_template() -> int:
|
||||
var script_template_file = FileAccess.open(
|
||||
BASE_SCRIPT_TEMPLATE % _type_label, FileAccess.READ
|
||||
)
|
||||
|
||||
if script_template_file == null:
|
||||
PopochiuUtils.print_error(
|
||||
"Could not read script template from %s" %
|
||||
[BASE_SCRIPT_TEMPLATE % _type_label]
|
||||
)
|
||||
return ResultCodes.ERR_CANT_OPEN_OBJ_SCRIPT_TEMPLATE
|
||||
|
||||
var new_code: String = script_template_file.get_as_text()
|
||||
script_template_file.close()
|
||||
|
||||
new_code = new_code.replace(
|
||||
"%s_state_template" % _type_label,
|
||||
"%s_%s_state" % [_type_label, _snake_name]
|
||||
)
|
||||
new_code = new_code.replace(
|
||||
"Data = null",
|
||||
'Data = load("%s.tres")' % _path_base
|
||||
)
|
||||
new_code = new_code.replace("PopochiuUtils.e", "E")
|
||||
|
||||
_script = load(EMPTY_SCRIPT).duplicate()
|
||||
_script.source_code = new_code
|
||||
|
||||
if ResourceSaver.save( _script, _path_script) != OK:
|
||||
PopochiuUtils.print_error(
|
||||
"Could not create %s script: %s" %
|
||||
[_type_label, _path_script]
|
||||
)
|
||||
return ResultCodes.ERR_CANT_CREATE_OBJ_SCRIPT
|
||||
|
||||
return ResultCodes.SUCCESS
|
||||
|
||||
|
||||
func _save_obj_scene(obj: Node) -> int:
|
||||
var packed_scene: PackedScene = PackedScene.new()
|
||||
packed_scene.pack(obj)
|
||||
if ResourceSaver.save(packed_scene, _path_scene) != OK:
|
||||
PopochiuUtils.print_error(
|
||||
"Could not create %s: %s" %
|
||||
[_type_label, _path_script]
|
||||
)
|
||||
return ResultCodes.ERR_CANT_SAVE_OBJ_SCENE
|
||||
# Load the scene to be get by the calling code
|
||||
# Instancing the created .tscn file fixes #58
|
||||
_scene = (load(_path_scene) as PackedScene).instantiate(PackedScene.GEN_EDIT_STATE_INSTANCE)
|
||||
|
||||
return ResultCodes.SUCCESS
|
||||
|
||||
|
||||
func _save_obj_resource(obj: Resource) -> int:
|
||||
if ResourceSaver.save(obj, _path_resource) != OK:
|
||||
PopochiuUtils.print_error(
|
||||
"Could not create %s: %s" %
|
||||
[_type_label, _pascal_name]
|
||||
)
|
||||
return ResultCodes.ERR_CANT_SAVE_OBJ_RESOURCE
|
||||
|
||||
# Load the resource to be get by the calling code
|
||||
_resource = load(_path_resource)
|
||||
|
||||
return ResultCodes.SUCCESS
|
||||
|
||||
|
||||
## Makes a copy of the base scene for the object (e.g. popochiu_room.tscn,
|
||||
## popochiu_inventory_item.tscn, popochiu_prop.tscn).
|
||||
func _load_obj_base_scene() -> Node:
|
||||
var obj = (
|
||||
load(BASE_SCENE_PATH % [_type_label, _type_label]) as PackedScene
|
||||
).instantiate(PackedScene.GEN_EDIT_STATE_MAIN_INHERITED)
|
||||
|
||||
# The script is assigned first so that other properties will not be
|
||||
# overwritten by that assignment.
|
||||
if _script != null:
|
||||
obj.set_script(load(_path_script))
|
||||
|
||||
return obj
|
||||
|
||||
|
||||
func _add_resource_to_popochiu() -> void:
|
||||
# Add the created obj to Popochiu's correct list
|
||||
var resource := ResourceLoader.load(_path_resource)
|
||||
if PopochiuResources.set_data_value(
|
||||
_type_target,
|
||||
resource.script_name,
|
||||
resource.resource_path
|
||||
) != OK:
|
||||
PopochiuUtils.print_error(
|
||||
"Could not add the created %s to Popochiu: %s" %
|
||||
[_type_label, _pascal_name]
|
||||
)
|
||||
return
|
||||
|
||||
# Add the object to the proper singleton
|
||||
PopochiuResources.update_autoloads(true)
|
||||
|
||||
# Update the related list in the dock
|
||||
PopochiuEditorHelper.signal_bus.main_object_added.emit(_type, _pascal_name)
|
||||
|
||||
|
||||
#endregion
|
|
@ -0,0 +1 @@
|
|||
uid://dsauwqcvbelb1
|
|
@ -0,0 +1,98 @@
|
|||
class_name PopochiuRoomObjFactory
|
||||
extends "res://addons/popochiu/editor/factories/factory_base_popochiu_obj.gd"
|
||||
|
||||
const CHILD_VISIBLE_IN_ROOM_META = "_popochiu_obj_factory_child_visible_in_room_"
|
||||
|
||||
# The following variable is setup by the sub-class constructor to
|
||||
# define the holder node for the new room object (Props, Hotspots, etc)
|
||||
var _obj_room_group := ""
|
||||
# The following variables are setup by the _setup_room method
|
||||
var _room: Node2D = null
|
||||
var _room_path := ""
|
||||
var _room_dir := ""
|
||||
|
||||
|
||||
#region Public #####################################################################################
|
||||
func get_group() -> String:
|
||||
return _obj_room_group
|
||||
|
||||
|
||||
func create_from(node: Node, room: PopochiuRoom) -> int:
|
||||
_setup_room(room)
|
||||
_setup_name(node.name)
|
||||
|
||||
var param := _get_param(node)
|
||||
param.room = room
|
||||
param.obj_name = node.name
|
||||
param.is_visible = node.visible
|
||||
param.should_setup_room_and_name = false
|
||||
param.should_add_to_room = false
|
||||
param.should_create_script = !FileAccess.file_exists(_path_script)
|
||||
|
||||
return call("create", param)
|
||||
|
||||
|
||||
func get_new_instance() -> PopochiuRoomObjFactory:
|
||||
return new()
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
#region Private ####################################################################################
|
||||
func _setup_room(room: PopochiuRoom) -> void:
|
||||
_room = room
|
||||
_room_path = _room.scene_file_path
|
||||
_room_dir = _room_path.get_base_dir()
|
||||
# Adding room path to room object path template
|
||||
_path_template = _room_dir + _path_template
|
||||
|
||||
|
||||
# This function adds a child to the new object scene
|
||||
# marking it as "visible in room scene"
|
||||
func _add_visible_child(child: Node) -> void:
|
||||
child.set_meta(CHILD_VISIBLE_IN_ROOM_META, true)
|
||||
_scene.add_child(child)
|
||||
|
||||
|
||||
func _add_resource_to_room() -> void:
|
||||
# Add the newly created obj to its room
|
||||
_room.get_node(_obj_room_group).add_child(_scene)
|
||||
|
||||
# Set the ownership for the node plus all it's children
|
||||
# (this address colliders, polygons, etc)
|
||||
_scene.owner = _room
|
||||
for child in _scene.get_children():
|
||||
if child.has_meta(CHILD_VISIBLE_IN_ROOM_META):
|
||||
child.owner = _room
|
||||
child.remove_meta(CHILD_VISIBLE_IN_ROOM_META)
|
||||
|
||||
# Center the object on the scene
|
||||
_scene.position = Vector2(
|
||||
ProjectSettings.get_setting(PopochiuResources.DISPLAY_WIDTH),
|
||||
ProjectSettings.get_setting(PopochiuResources.DISPLAY_HEIGHT)
|
||||
) / 2.0
|
||||
|
||||
# Save the room scene (it's open in the editor)
|
||||
EditorInterface.save_scene()
|
||||
|
||||
|
||||
func _get_param(_node: Node) -> PopochiuRoomObjFactoryParam:
|
||||
return PopochiuRoomObjFactoryParam.new()
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
#region Subclass ###################################################################################
|
||||
class PopochiuRoomObjFactoryParam extends RefCounted:
|
||||
var obj_name: String
|
||||
var room: PopochiuRoom
|
||||
var is_visible := true
|
||||
var should_setup_room_and_name := true
|
||||
var should_create_script := true
|
||||
var should_add_to_room := true
|
||||
## Property used to store the vectors stored in the [member CollisionPolygon2D.polygon] for
|
||||
## [PopochiuProp], [PopochiuHotspot], and [PopochiuRegion].
|
||||
var interaction_polygon := PackedVector2Array()
|
||||
|
||||
|
||||
#endregion
|
|
@ -0,0 +1 @@
|
|||
uid://ch67numd388l
|
|
@ -0,0 +1,64 @@
|
|||
extends "res://addons/popochiu/editor/factories/factory_base_popochiu_obj.gd"
|
||||
class_name PopochiuCharacterFactory
|
||||
|
||||
#region Godot ######################################################################################
|
||||
func _init() -> void:
|
||||
_type = PopochiuResources.Types.CHARACTER
|
||||
_type_label = "character"
|
||||
_type_target = "characters"
|
||||
_path_template = PopochiuResources.CHARACTERS_PATH.path_join("%s/character_%s")
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
#region Public #####################################################################################
|
||||
func create(obj_name: String, is_pc := false) -> int:
|
||||
# If everything goes well, this won't change.
|
||||
var result_code := ResultCodes.SUCCESS
|
||||
|
||||
# Setup the class variables that depends on the object name
|
||||
_setup_name(obj_name)
|
||||
|
||||
# Create the folder
|
||||
result_code = _create_obj_folder()
|
||||
if result_code != ResultCodes.SUCCESS: return result_code
|
||||
|
||||
# Create the state Resource and a script
|
||||
# so devs can add extra properties to that state
|
||||
result_code = _create_state_resource()
|
||||
if result_code != ResultCodes.SUCCESS: return result_code
|
||||
|
||||
# Create the script populating the template with the right references
|
||||
result_code = _create_script_from_template()
|
||||
if result_code != ResultCodes.SUCCESS: return result_code
|
||||
|
||||
# ---- LOCAL CODE ------------------------------------------------------------------------------
|
||||
# Create the instance
|
||||
var new_obj: PopochiuCharacter = _load_obj_base_scene()
|
||||
|
||||
new_obj.name = "Character" + _pascal_name
|
||||
new_obj.script_name = _pascal_name
|
||||
new_obj.description = _pascal_name.capitalize()
|
||||
new_obj.cursor = PopochiuResources.CURSOR_TYPE.TALK
|
||||
|
||||
if PopochiuConfig.is_pixel_art_textures():
|
||||
new_obj.get_node("Sprite2D").texture_filter = CanvasItem.TEXTURE_FILTER_NEAREST
|
||||
# ---- END OF LOCAL CODE -----------------------------------------------------------------------
|
||||
|
||||
# Save the scene (.tscn)
|
||||
result_code = _save_obj_scene(new_obj)
|
||||
if result_code != ResultCodes.SUCCESS: return result_code
|
||||
|
||||
# Add the object to Popochiu dock list, plus open it in the editor
|
||||
_add_resource_to_popochiu()
|
||||
|
||||
# ---- LOCAL CODE ------------------------------------------------------------------------------
|
||||
# Set as PC
|
||||
if is_pc:
|
||||
PopochiuEditorHelper.signal_bus.pc_changed.emit(new_obj.script_name)
|
||||
# ---- END OF LOCAL CODE -----------------------------------------------------------------------
|
||||
|
||||
return result_code
|
||||
|
||||
|
||||
#endregion
|
|
@ -0,0 +1 @@
|
|||
uid://dstbnm6v0t6ot
|
49
addons/popochiu/editor/factories/factory_popochiu_dialog.gd
Normal file
49
addons/popochiu/editor/factories/factory_popochiu_dialog.gd
Normal file
|
@ -0,0 +1,49 @@
|
|||
extends "res://addons/popochiu/editor/factories/factory_base_popochiu_obj.gd"
|
||||
class_name PopochiuDialogFactory
|
||||
|
||||
#region Godot ######################################################################################
|
||||
func _init() -> void:
|
||||
_type = PopochiuResources.Types.DIALOG
|
||||
_type_label = "dialog"
|
||||
_type_target = "dialogs"
|
||||
_path_template = PopochiuResources.DIALOGS_PATH.path_join("%s/dialog_%s")
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
#region Public #####################################################################################
|
||||
func create(obj_name: String) -> int:
|
||||
# If everything goes well, this won't change.
|
||||
var result_code := ResultCodes.SUCCESS
|
||||
|
||||
# Setup the class variables that depends on the object name
|
||||
_setup_name(obj_name)
|
||||
|
||||
# Create the folder
|
||||
result_code = _create_obj_folder()
|
||||
if result_code != ResultCodes.SUCCESS: return result_code
|
||||
|
||||
# Create the script
|
||||
result_code = _copy_script_template()
|
||||
if result_code != ResultCodes.SUCCESS: return result_code
|
||||
|
||||
# ---- LOCAL CODE ------------------------------------------------------------------------------
|
||||
# Create the resource (dialogs are not scenes)
|
||||
var new_obj := PopochiuDialog.new()
|
||||
new_obj.set_script(load(_path_script))
|
||||
|
||||
new_obj.script_name = _pascal_name
|
||||
new_obj.resource_name = _pascal_name
|
||||
# ---- END OF LOCAL CODE -----------------------------------------------------------------------
|
||||
|
||||
# Save resource (dialogs are not scenes)
|
||||
result_code = _save_obj_resource(new_obj)
|
||||
if result_code != ResultCodes.SUCCESS: return result_code
|
||||
|
||||
# Add the object to Popochiu dock list, plus open it in the editor
|
||||
_add_resource_to_popochiu()
|
||||
|
||||
return result_code
|
||||
|
||||
|
||||
#endregion
|
|
@ -0,0 +1 @@
|
|||
uid://ddk6pykrms2tq
|
|
@ -0,0 +1,76 @@
|
|||
class_name PopochiuHotspotFactory
|
||||
extends PopochiuRoomObjFactory
|
||||
|
||||
|
||||
#region Godot ######################################################################################
|
||||
func _init() -> void:
|
||||
_type = PopochiuResources.Types.HOTSPOT
|
||||
_type_label = "hotspot"
|
||||
_type_method = PopochiuEditorHelper.is_hotspot
|
||||
_obj_room_group = "Hotspots"
|
||||
_path_template = "/hotspots/%s/hotspot_%s"
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
#region Public #####################################################################################
|
||||
func create(param: PopochiuHotspotFactoryParam) -> int:
|
||||
# If everything goes well, this won't change.
|
||||
var result_code := ResultCodes.SUCCESS
|
||||
|
||||
if param.should_setup_room_and_name:
|
||||
_setup_room(param.room)
|
||||
_setup_name(param.obj_name)
|
||||
|
||||
# Create the folder
|
||||
result_code = _create_obj_folder()
|
||||
if result_code != ResultCodes.SUCCESS: return result_code
|
||||
|
||||
# Create the script
|
||||
if param.should_create_script:
|
||||
result_code = _copy_script_template()
|
||||
if result_code != ResultCodes.SUCCESS: return result_code
|
||||
|
||||
# ---- LOCAL CODE ------------------------------------------------------------------------------
|
||||
# Create the instance
|
||||
var new_obj: PopochiuHotspot = _load_obj_base_scene()
|
||||
|
||||
new_obj.set_script(ResourceLoader.load(_path_script))
|
||||
|
||||
new_obj.name = _pascal_name
|
||||
new_obj.script_name = _pascal_name
|
||||
new_obj.description = _snake_name.capitalize()
|
||||
new_obj.cursor = PopochiuResources.CURSOR_TYPE.ACTIVE
|
||||
new_obj.interaction_polygon = param.interaction_polygon
|
||||
|
||||
# Save the hotspot scene (.tscn) and put it into _scene class property
|
||||
result_code = _save_obj_scene(new_obj)
|
||||
if result_code != ResultCodes.SUCCESS: return result_code
|
||||
# ---- END OF LOCAL CODE -----------------------------------------------------------------------
|
||||
|
||||
if param.should_add_to_room:
|
||||
# Add the object to its room
|
||||
_add_resource_to_room()
|
||||
|
||||
return result_code
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
#region Private ####################################################################################
|
||||
func _get_param(node: Node) -> PopochiuRoomObjFactoryParam:
|
||||
var param := PopochiuHotspotFactoryParam.new()
|
||||
param.is_interactive = node.clickable
|
||||
# TODO: Remove this line once the last gizmos PR is merged
|
||||
param.interaction_polygon = node.interaction_polygon
|
||||
return param
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
#region Subclass ###################################################################################
|
||||
class PopochiuHotspotFactoryParam extends PopochiuRoomObjFactory.PopochiuRoomObjFactoryParam:
|
||||
var is_interactive := true
|
||||
|
||||
|
||||
#endregion
|
|
@ -0,0 +1 @@
|
|||
uid://bcnd7an67ulyf
|
|
@ -0,0 +1,60 @@
|
|||
extends "res://addons/popochiu/editor/factories/factory_base_popochiu_obj.gd"
|
||||
class_name PopochiuInventoryItemFactory
|
||||
|
||||
#region Godot ######################################################################################
|
||||
func _init() -> void:
|
||||
_type = PopochiuResources.Types.INVENTORY_ITEM
|
||||
_type_label = "inventory_item"
|
||||
_type_target = "inventory_items"
|
||||
_path_template = PopochiuResources.INVENTORY_ITEMS_PATH.path_join("%s/inventory_item_%s")
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
#region Public #####################################################################################
|
||||
func create(obj_name: String) -> int:
|
||||
# If everything goes well, this won't change.
|
||||
var result_code := ResultCodes.SUCCESS
|
||||
|
||||
# Setup the class variables that depends on the object name
|
||||
_setup_name(obj_name)
|
||||
|
||||
# Create the folder
|
||||
result_code = _create_obj_folder()
|
||||
if result_code != ResultCodes.SUCCESS: return result_code
|
||||
|
||||
# Create the state Resource and a script
|
||||
# so devs can add extra properties to that state
|
||||
result_code = _create_state_resource()
|
||||
if result_code != ResultCodes.SUCCESS: return result_code
|
||||
|
||||
# Create the script populating the template with the right references
|
||||
result_code = _create_script_from_template()
|
||||
if result_code != ResultCodes.SUCCESS: return result_code
|
||||
|
||||
# ---- LOCAL CODE ------------------------------------------------------------------------------
|
||||
# Create the instance
|
||||
var new_obj: PopochiuInventoryItem = _load_obj_base_scene()
|
||||
|
||||
new_obj.name = "Item" + _pascal_name
|
||||
new_obj.script_name = _pascal_name
|
||||
new_obj.description = _pascal_name.capitalize()
|
||||
new_obj.cursor = PopochiuResources.CURSOR_TYPE.USE
|
||||
new_obj.size_flags_vertical = new_obj.SIZE_SHRINK_CENTER
|
||||
|
||||
if PopochiuConfig.is_pixel_art_textures():
|
||||
new_obj.texture_filter = CanvasItem.TEXTURE_FILTER_NEAREST
|
||||
|
||||
# ---- END OF LOCAL CODE -----------------------------------------------------------------------
|
||||
|
||||
# Save the scene (.tscn)
|
||||
result_code = _save_obj_scene(new_obj)
|
||||
if result_code != ResultCodes.SUCCESS: return result_code
|
||||
|
||||
# Add the object to Popochiu dock list, plus open it in the editor
|
||||
_add_resource_to_popochiu()
|
||||
|
||||
return result_code
|
||||
|
||||
|
||||
#endregion
|
|
@ -0,0 +1 @@
|
|||
uid://bym4xs81a2ph4
|
44
addons/popochiu/editor/factories/factory_popochiu_marker.gd
Normal file
44
addons/popochiu/editor/factories/factory_popochiu_marker.gd
Normal file
|
@ -0,0 +1,44 @@
|
|||
class_name PopochiuMarkerFactory
|
||||
extends PopochiuRoomObjFactory
|
||||
|
||||
#region Godot ######################################################################################
|
||||
func _init() -> void:
|
||||
_type = PopochiuResources.Types.MARKER
|
||||
_type_label = "marker"
|
||||
_type_method = PopochiuEditorHelper.is_marker
|
||||
_obj_room_group = "Markers"
|
||||
_path_template = "/markers/%s/marker_%s"
|
||||
|
||||
|
||||
#endregion
|
||||
#region Public #####################################################################################
|
||||
func create(param: PopochiuRoomObjFactoryParam) -> int:
|
||||
# If everything goes well, this won't change.
|
||||
var result_code := ResultCodes.SUCCESS
|
||||
|
||||
if param.should_setup_room_and_name:
|
||||
_setup_room(param.room)
|
||||
_setup_name(param.obj_name)
|
||||
|
||||
# Create the folder
|
||||
result_code = _create_obj_folder()
|
||||
if result_code != ResultCodes.SUCCESS: return result_code
|
||||
|
||||
# ---- LOCAL CODE ------------------------------------------------------------------------------
|
||||
# Create the instance
|
||||
var new_obj: Marker2D = Marker2D.new()
|
||||
new_obj.name = _pascal_name
|
||||
|
||||
# Save the marker scene (.tscn) and put it into _scene class property
|
||||
result_code = _save_obj_scene(new_obj)
|
||||
if result_code != ResultCodes.SUCCESS: return result_code
|
||||
# ---- END OF LOCAL CODE -----------------------------------------------------------------------
|
||||
|
||||
if param.should_add_to_room:
|
||||
# Add the object to its room
|
||||
_add_resource_to_room()
|
||||
|
||||
return result_code
|
||||
|
||||
|
||||
#endregion
|
|
@ -0,0 +1 @@
|
|||
uid://ckjo1lcmxjlh6
|
86
addons/popochiu/editor/factories/factory_popochiu_prop.gd
Normal file
86
addons/popochiu/editor/factories/factory_popochiu_prop.gd
Normal file
|
@ -0,0 +1,86 @@
|
|||
class_name PopochiuPropFactory
|
||||
extends PopochiuRoomObjFactory
|
||||
|
||||
|
||||
#region Godot ######################################################################################
|
||||
func _init() -> void:
|
||||
_type = PopochiuResources.Types.PROP
|
||||
_type_label = "prop"
|
||||
_type_method = PopochiuEditorHelper.is_prop
|
||||
_obj_room_group = "Props"
|
||||
_path_template = "/props/%s/prop_%s"
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
#region Public #####################################################################################
|
||||
func create(param: PopochiuPropFactoryParam) -> int:
|
||||
# If everything goes well, this won't change.
|
||||
var result_code := ResultCodes.SUCCESS
|
||||
|
||||
if param.should_setup_room_and_name:
|
||||
_setup_room(param.room)
|
||||
_setup_name(param.obj_name)
|
||||
|
||||
# Create the folder
|
||||
result_code = _create_obj_folder()
|
||||
if result_code != ResultCodes.SUCCESS: return result_code
|
||||
|
||||
# Create the script (if the prop is interactive)
|
||||
if param.should_create_script:
|
||||
result_code = _copy_script_template()
|
||||
if result_code != ResultCodes.SUCCESS: return result_code
|
||||
|
||||
# ---- LOCAL CODE ------------------------------------------------------------------------------
|
||||
# Create the instance
|
||||
var new_obj: PopochiuProp = _load_obj_base_scene()
|
||||
|
||||
new_obj.set_script(ResourceLoader.load(_path_script))
|
||||
|
||||
new_obj.name = _pascal_name
|
||||
new_obj.script_name = _pascal_name
|
||||
new_obj.description = _snake_name.capitalize()
|
||||
new_obj.cursor = PopochiuResources.CURSOR_TYPE.ACTIVE
|
||||
new_obj.clickable = param.is_interactive
|
||||
new_obj.visible = param.is_visible
|
||||
new_obj.interaction_polygon = param.interaction_polygon
|
||||
|
||||
if PopochiuConfig.is_pixel_art_textures():
|
||||
new_obj.get_node("Sprite2D").texture_filter = CanvasItem.TEXTURE_FILTER_NEAREST
|
||||
|
||||
if _snake_name in ["bg", "background"]:
|
||||
new_obj.baseline =\
|
||||
-ProjectSettings.get_setting(PopochiuResources.DISPLAY_HEIGHT) / 2.0
|
||||
new_obj.z_index = -1
|
||||
|
||||
# Save the scene (.tscn) and put it into _scene class property
|
||||
result_code = _save_obj_scene(new_obj)
|
||||
if result_code != ResultCodes.SUCCESS: return result_code
|
||||
# ---- END OF LOCAL CODE -----------------------------------------------------------------------
|
||||
|
||||
if param.should_add_to_room:
|
||||
# Add the object to its room
|
||||
_add_resource_to_room()
|
||||
|
||||
return result_code
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
#region Private ####################################################################################
|
||||
func _get_param(node: Node) -> PopochiuRoomObjFactoryParam:
|
||||
var param := PopochiuPropFactoryParam.new()
|
||||
param.is_interactive = node.clickable
|
||||
# TODO: Remove this line once the last gizmos PR is merged
|
||||
param.interaction_polygon = node.interaction_polygon
|
||||
return param
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
#region Subclass ###################################################################################
|
||||
class PopochiuPropFactoryParam extends PopochiuRoomObjFactory.PopochiuRoomObjFactoryParam:
|
||||
var is_interactive := false
|
||||
|
||||
|
||||
#endregion
|
|
@ -0,0 +1 @@
|
|||
uid://b8ajrxi1mp5up
|
71
addons/popochiu/editor/factories/factory_popochiu_region.gd
Normal file
71
addons/popochiu/editor/factories/factory_popochiu_region.gd
Normal file
|
@ -0,0 +1,71 @@
|
|||
class_name PopochiuRegionFactory
|
||||
extends PopochiuRoomObjFactory
|
||||
|
||||
#region Godot ######################################################################################
|
||||
func _init() -> void:
|
||||
_type = PopochiuResources.Types.REGION
|
||||
_type_label = "region"
|
||||
_type_method = PopochiuEditorHelper.is_region
|
||||
_obj_room_group = "Regions"
|
||||
_path_template = "/regions/%s/region_%s"
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
#region Public #####################################################################################
|
||||
func create(param: PopochiuRoomObjFactoryParam) -> int:
|
||||
# If everything goes well, this won't change.
|
||||
var result_code := ResultCodes.SUCCESS
|
||||
|
||||
if param.should_setup_room_and_name:
|
||||
_setup_room(param.room)
|
||||
_setup_name(param.obj_name)
|
||||
|
||||
# Create the folder
|
||||
result_code = _create_obj_folder()
|
||||
if result_code != ResultCodes.SUCCESS: return result_code
|
||||
|
||||
# Create the script
|
||||
if param.should_create_script:
|
||||
result_code = _copy_script_template()
|
||||
if result_code != ResultCodes.SUCCESS: return result_code
|
||||
|
||||
# ---- LOCAL CODE ------------------------------------------------------------------------------
|
||||
# Create the instance
|
||||
var new_obj: PopochiuRegion = _load_obj_base_scene()
|
||||
new_obj.set_script(ResourceLoader.load(_path_script))
|
||||
new_obj.name = _pascal_name
|
||||
new_obj.script_name = _pascal_name
|
||||
new_obj.description = _snake_name.capitalize()
|
||||
new_obj.interaction_polygon = param.interaction_polygon
|
||||
|
||||
# Save the scene (.tscn) and put it into _scene class property
|
||||
result_code = _save_obj_scene(new_obj)
|
||||
if result_code != ResultCodes.SUCCESS: return result_code
|
||||
# ---- END OF LOCAL CODE -----------------------------------------------------------------------
|
||||
|
||||
if param.should_add_to_room:
|
||||
# Add the object to its room
|
||||
_add_resource_to_room()
|
||||
|
||||
return result_code
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
#region Private ####################################################################################
|
||||
func _get_param(node: Node) -> PopochiuRoomObjFactoryParam:
|
||||
var param := PopochiuRegionFactoryParam.new()
|
||||
param.interaction_polygon = node.interaction_polygon
|
||||
|
||||
return param
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
#region Subclass ###################################################################################
|
||||
class PopochiuRegionFactoryParam extends PopochiuRoomObjFactory.PopochiuRoomObjFactoryParam:
|
||||
var should_create_interaction_polygon := true
|
||||
|
||||
|
||||
#endregion
|
|
@ -0,0 +1 @@
|
|||
uid://dphtxosh168sb
|
63
addons/popochiu/editor/factories/factory_popochiu_room.gd
Normal file
63
addons/popochiu/editor/factories/factory_popochiu_room.gd
Normal file
|
@ -0,0 +1,63 @@
|
|||
extends "res://addons/popochiu/editor/factories/factory_base_popochiu_obj.gd"
|
||||
class_name PopochiuRoomFactory
|
||||
|
||||
#region Godot ######################################################################################
|
||||
func _init() -> void:
|
||||
_type = PopochiuResources.Types.ROOM
|
||||
_type_label = "room"
|
||||
_type_target = "rooms"
|
||||
_path_template = PopochiuResources.ROOMS_PATH.path_join("%s/room_%s")
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
#region Public #####################################################################################
|
||||
func create(obj_name: String, set_as_main := false) -> int:
|
||||
# If everything goes well, this won't change.
|
||||
var result_code := ResultCodes.SUCCESS
|
||||
|
||||
# Setup the class variables that depends on the object name
|
||||
_setup_name(obj_name)
|
||||
|
||||
# Create the folder
|
||||
result_code = _create_obj_folder()
|
||||
if result_code != ResultCodes.SUCCESS: return result_code
|
||||
|
||||
# Create the state Resource and a script
|
||||
# so devs can add extra properties to that state
|
||||
result_code = _create_state_resource()
|
||||
if result_code != ResultCodes.SUCCESS: return result_code
|
||||
|
||||
# Create the script populating the template with the right references
|
||||
result_code = _create_script_from_template()
|
||||
if result_code != ResultCodes.SUCCESS: return result_code
|
||||
|
||||
# ---- LOCAL CODE ------------------------------------------------------------------------------
|
||||
# Create the instance
|
||||
var new_obj: PopochiuRoom = _load_obj_base_scene()
|
||||
|
||||
new_obj.name = "Room" + _pascal_name
|
||||
new_obj.script_name = _pascal_name
|
||||
new_obj.width = ProjectSettings.get_setting(PopochiuResources.DISPLAY_WIDTH)
|
||||
new_obj.height = ProjectSettings.get_setting(PopochiuResources.DISPLAY_HEIGHT)
|
||||
# ---- END OF LOCAL CODE -----------------------------------------------------------------------
|
||||
|
||||
# Save the scene (.tscn)
|
||||
result_code = _save_obj_scene(new_obj)
|
||||
if result_code != ResultCodes.SUCCESS: return result_code
|
||||
|
||||
# Add the object to Popochiu dock list, plus open it in the editor
|
||||
_add_resource_to_popochiu()
|
||||
|
||||
# ---- LOCAL CODE ------------------------------------------------------------------------------
|
||||
# Set as main room
|
||||
# Changed _set_as_main_check.pressed to _set_as_main_check.button_pressed
|
||||
# in order to fix #56
|
||||
if set_as_main:
|
||||
PopochiuEditorHelper.signal_bus.main_scene_changed.emit(_scene.scene_file_path)
|
||||
# ---- END OF LOCAL CODE -----------------------------------------------------------------------
|
||||
|
||||
return result_code
|
||||
|
||||
|
||||
#endregion
|
|
@ -0,0 +1 @@
|
|||
uid://b7kd0q631qqt6
|
|
@ -0,0 +1,94 @@
|
|||
class_name PopochiuWalkableAreaFactory
|
||||
extends PopochiuRoomObjFactory
|
||||
|
||||
|
||||
#region Godot ######################################################################################
|
||||
func _init() -> void:
|
||||
_type = PopochiuResources.Types.WALKABLE_AREA
|
||||
_type_label = "walkable_area"
|
||||
_type_method = PopochiuEditorHelper.is_walkable_area
|
||||
_obj_room_group = "WalkableAreas"
|
||||
_path_template = "/walkable_areas/%s/walkable_area_%s"
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
#region Public #####################################################################################
|
||||
func create(param: PopochiuWalkableAreaFactoryParam) -> int:
|
||||
# If everything goes well, this won't change.
|
||||
var result_code := ResultCodes.SUCCESS
|
||||
|
||||
if param.should_setup_room_and_name:
|
||||
_setup_room(param.room)
|
||||
_setup_name(param.obj_name)
|
||||
|
||||
# Create the folder
|
||||
result_code = _create_obj_folder()
|
||||
if result_code != ResultCodes.SUCCESS: return result_code
|
||||
|
||||
# Create the script
|
||||
if param.should_create_script:
|
||||
result_code = _copy_script_template()
|
||||
if result_code != ResultCodes.SUCCESS: return result_code
|
||||
|
||||
# ---- LOCAL CODE ------------------------------------------------------------------------------
|
||||
# Create the instance
|
||||
var new_obj: PopochiuWalkableArea = _load_obj_base_scene()
|
||||
|
||||
new_obj.set_script(ResourceLoader.load(_path_script))
|
||||
|
||||
new_obj.name = _pascal_name
|
||||
new_obj.script_name = _pascal_name
|
||||
new_obj.description = _snake_name.capitalize()
|
||||
|
||||
# Find the NavigationRegion2D for the WA and populate it with a default rectangle polygon
|
||||
var perimeter := new_obj.find_child("Perimeter")
|
||||
var polygon := NavigationPolygon.new()
|
||||
polygon.add_outline(PackedVector2Array([
|
||||
Vector2(-10, -10), Vector2(10, -10), Vector2(10, 10), Vector2(-10, 10)
|
||||
]))
|
||||
NavigationServer2D.bake_from_source_geometry_data(
|
||||
polygon, NavigationMeshSourceGeometryData2D.new()
|
||||
)
|
||||
polygon.agent_radius = 0.0
|
||||
perimeter.navigation_polygon = polygon
|
||||
|
||||
if not param.navigation_polygon.is_empty():
|
||||
new_obj.interaction_polygon = param.navigation_polygon
|
||||
new_obj.clear_and_bake(perimeter.navigation_polygon)
|
||||
|
||||
# Show the WA perimeter, depending on user prefs
|
||||
perimeter.visible = PopochiuEditorConfig.get_editor_setting(
|
||||
PopochiuEditorConfig.GIZMOS_ALWAYS_SHOW_WA
|
||||
)
|
||||
|
||||
# Save the scene (.tscn) and put it into _scene class property
|
||||
result_code = _save_obj_scene(new_obj)
|
||||
if result_code != ResultCodes.SUCCESS: return result_code
|
||||
# ---- END OF LOCAL CODE -----------------------------------------------------------------------
|
||||
|
||||
if param.should_add_to_room:
|
||||
# Add the object to its room
|
||||
_add_resource_to_room()
|
||||
|
||||
return result_code
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
#region Private ####################################################################################
|
||||
func _get_param(node: Node) -> PopochiuRoomObjFactoryParam:
|
||||
var param := PopochiuWalkableAreaFactoryParam.new()
|
||||
param.navigation_polygon = node.interaction_polygon
|
||||
|
||||
return param
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
#region Subclass ###################################################################################
|
||||
class PopochiuWalkableAreaFactoryParam extends PopochiuRoomObjFactory.PopochiuRoomObjFactoryParam:
|
||||
var navigation_polygon := []
|
||||
|
||||
|
||||
#endregion
|
|
@ -0,0 +1 @@
|
|||
uid://c66i7vwbgxym8
|
Loading…
Add table
Add a link
Reference in a new issue