-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add a supported version number * basic setup for new api * updated to api 3 * add depth distinction by color
- Loading branch information
1 parent
0604f37
commit c2fd5ef
Showing
7 changed files
with
260 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,181 @@ | ||
# gdlint: ignore=max-public-methods | ||
extends Node | ||
|
||
# use these variables in your extension to access the api | ||
var general := GeneralAPI.new() | ||
var menu := MenuAPI.new() | ||
var dialog := DialogAPI.new() | ||
var panel := PanelAPI.new() | ||
var theme := ThemeAPI.new() | ||
var tools := ToolAPI.new() | ||
var project := ProjectAPI.new() | ||
var signals := SignalsAPI.new() | ||
|
||
|
||
# The Api Methods Start Here | ||
func get_api_version() -> int: | ||
# Returns the api version of pixelorama | ||
return 2 | ||
|
||
|
||
class GeneralAPI: | ||
# Version And Config | ||
func get_pixelorama_version() -> String: | ||
# Returns the version of pixelorama | ||
return "0.11.0" | ||
|
||
func get_config_file() -> ConfigFile: | ||
# config_file contains all the settings (Brushes, sizes, preferences, etc...) | ||
return ConfigFile.new() | ||
|
||
# Nodes | ||
func get_global(): | ||
# Returns the Global autoload used by pixelorama | ||
pass | ||
|
||
func get_extensions_node() -> Node: | ||
# Returns the Extensions Node (the parent of the extension's Main.tscn) | ||
return Node.new() | ||
|
||
func get_canvas(): | ||
# Returns the canvas | ||
pass | ||
|
||
|
||
class MenuAPI: | ||
enum { FILE, EDIT, SELECT, IMAGE, VIEW, WINDOW, HELP } | ||
|
||
func add_menu_item(menu_type: int, item_name: String, item_metadata, item_id := -1) -> int: | ||
# item_metadata is usually a popup node you want to appear when you click the item_name | ||
# that popup should also have an (menu_item_clicked) function inside it's script | ||
# "item_idx" of the added entry is returned | ||
return 0 | ||
|
||
func remove_menu_item(menu_type: int, item_idx: int) -> void: | ||
# removes an entry at "item_idx" from the menu_type (FILE, EDIT, SELECT, IMAGE, VIEW, WINDOW, HELP) | ||
pass | ||
|
||
|
||
class DialogAPI: | ||
func show_error(text: String) -> void: | ||
# shows an alert dialog with the given "text" | ||
# useful for displaying messages like "Incompatible API" etc... | ||
pass | ||
|
||
func get_dialogs_parent_node() -> Node: | ||
# returns the node that is the parent of the dialog used in pixelorama | ||
return Node.new() | ||
|
||
func dialog_open(open: bool) -> void: | ||
# Tell pixelorama that a dialog is being opened | ||
pass | ||
|
||
|
||
class PanelAPI: | ||
func set_tabs_visible(visible: bool) -> void: | ||
# sets the visibility of tabs | ||
pass | ||
|
||
func get_tabs_visible() -> bool: | ||
# get the visibility of tabs | ||
return false | ||
|
||
func add_node_as_tab(node: Node) -> void: | ||
# Adds a "node" as a tab | ||
pass | ||
|
||
func remove_node_from_tab(node: Node) -> void: | ||
# Removes the "node" from the DockableContainer | ||
pass | ||
|
||
|
||
class ThemeAPI: | ||
func add_theme(theme: Theme) -> void: | ||
# Adds a theme | ||
pass | ||
|
||
func find_theme_index(theme: Theme) -> int: | ||
# Returns index of a theme in preferences | ||
return 0 | ||
|
||
func get_theme() -> Theme: | ||
# Returns the current theme | ||
return Theme.new() | ||
|
||
func set_theme(idx: int) -> bool: | ||
# Sets a theme located at a given "idx" in preferences | ||
# If theme set successfully then return true, else false | ||
return false | ||
|
||
func remove_theme(theme: Theme) -> void: | ||
# Remove a theme from preferences | ||
pass | ||
|
||
|
||
class ToolAPI: | ||
# Tool methods | ||
func add_tool( | ||
tool_name: String, | ||
display_name: String, | ||
shortcut: String, | ||
scene: PackedScene, | ||
extra_hint := "", | ||
extra_shortucts := [], | ||
layer_types: PoolIntArray = [] | ||
) -> void: | ||
# Adds a tool with the above detail | ||
pass | ||
|
||
func remove_tool(tool_name: String) -> void: | ||
# Removes a tool with name "tool_name" | ||
# and assign Pencil as left tool, Eraser as right tool | ||
pass | ||
|
||
|
||
class ProjectAPI: | ||
func get_current_project(): | ||
# Returns the current project (type: Project) | ||
pass | ||
|
||
func get_current_cel_info() -> Dictionary: | ||
# As there are more than one types of cel in Pixelorama, | ||
# An extension may try to use a GroupCel as a PixelCel (if it doesn't know the difference) | ||
# So it's encouraged to use this function to access cels | ||
|
||
# type can be "GroupCel", "PixelCel", "Cel3D", and "BaseCel" | ||
return {"cel": null, "type": ""} | ||
|
||
func get_cel_info_at(project, frame: int, layer: int) -> Dictionary: | ||
# frames from left to right, layers from bottom to top | ||
# frames/layers start at "0" | ||
# and end at (project.frames.size() - 1) and (project.layers.size() - 1) respectively | ||
return {"cel": null, "type": ""} | ||
|
||
|
||
class SignalsAPI: | ||
# Global signals | ||
func connect_project_changed(target: Object, method: String): | ||
return | ||
|
||
func disconnect_project_changed(target: Object, method: String): | ||
return | ||
|
||
func connect_cel_changed(target: Object, method: String): | ||
return | ||
|
||
func disconnect_cel_changed(target: Object, method: String): | ||
return | ||
|
||
# Tool Signal | ||
func connect_tool_color_changed(target: Object, method: String): | ||
return | ||
|
||
func disconnect_tool_color_changed(target: Object, method: String): | ||
return | ||
|
||
# updater signals | ||
func connect_current_cel_texture_changed(target: Object, method: String): | ||
return | ||
|
||
func disconnect_current_cel_texture_changed(target: Object, method: String): | ||
return |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,74 @@ | ||
extends Node2D | ||
|
||
var _voxelorama_root_node: Node | ||
onready var extensions_api = get_node("/root/ExtensionsApi") | ||
|
||
var users :int = 1 | ||
|
||
|
||
func _ready() -> void: | ||
if extensions_api: | ||
_voxelorama_root_node = extensions_api.get_extensions_node().get_node("Voxelorama") | ||
_voxelorama_root_node = ExtensionsApi.general.get_extensions_node().get_node("Voxelorama") | ||
# immediately update if another tool is drawing | ||
|
||
|
||
func _draw() -> void: | ||
if !extensions_api: | ||
return | ||
|
||
var project = extensions_api.get_current_project() | ||
var project = ExtensionsApi.project.get_current_project() | ||
var size: Vector2 = project.size | ||
var cel: Reference = project.frames[project.current_frame].cels[project.current_layer] | ||
var image: Image = cel.image | ||
if !cel.has_meta("VoxelDepth"): | ||
return | ||
var depth_array: Array = cel.get_meta("VoxelDepth") | ||
|
||
var font: Font = extensions_api.get_theme().default_font | ||
var font: Font = ExtensionsApi.theme.get_theme().default_font | ||
draw_set_transform(position, rotation, Vector2(0.05, 0.05)) | ||
image.lock() | ||
for x in range(size.x): | ||
for y in range(size.y): | ||
if image.get_pixel(x, y).a == 0: | ||
continue | ||
var depth_str := str(depth_array[x][y]) | ||
draw_string(font, Vector2(x, y) * 20 + Vector2.DOWN * 16, depth_str) | ||
draw_string( | ||
font, Vector2(x, y) * 20 + Vector2.DOWN * 16, depth_str, get_color(depth_array[x][y]) | ||
) | ||
image.unlock() | ||
draw_set_transform(position, rotation, scale) | ||
|
||
|
||
func get_color(depth: float): | ||
var weight = 0 | ||
var color_a := Color.red | ||
var color_b := Color.white | ||
if depth > 0 and depth <= 5: | ||
weight = (depth - 1) /5.0 | ||
color_a = Color.white | ||
color_b = Color.blue | ||
|
||
if depth > 5 and depth <= 10: | ||
weight = (depth - 6)/25.0 | ||
color_a = Color.blue | ||
color_b = Color.green | ||
|
||
if depth > 10 and depth <= 15: | ||
weight = (depth - 11)/25.0 | ||
color_a = Color.green | ||
color_b = Color.yellow | ||
|
||
if depth > 15 and depth <= 20: | ||
weight = (depth - 16)/25.0 | ||
color_a = Color.yellow | ||
color_b = Color.orange | ||
|
||
if depth > 20 and depth <= 25: | ||
weight = (depth - 26)/25.0 | ||
color_a = Color.orange | ||
color_b = Color.red | ||
|
||
# values larger than 25 onward are in red | ||
return color_a.linear_interpolate(color_b, weight) | ||
|
||
|
||
func request_deletion(): | ||
users -= 1 | ||
print(users) | ||
if users == 0: # no one is using this node | ||
queue_free() | ||
# Else there are still active tool using this node so DENIED |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.