Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Combo demo #24

Open
wants to merge 20 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
9 changes: 9 additions & 0 deletions combo-demo/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@

# Godot-specific ignores
.import/
export.cfg
export_presets.cfg

# Mono-specific ignores
.mono/
data_*/
31 changes: 31 additions & 0 deletions combo-demo/Game.tscn
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
[gd_scene load_steps=4 format=2]

[ext_resource path="res://player/Player.tscn" type="PackedScene" id=1]
[ext_resource path="res://hills_night_blue.png" type="Texture" id=2]

[sub_resource type="RectangleShape2D" id=1]
extents = Vector2( 29, 556.5 )

[node name="Game" type="Node2D"]

[node name="Background" type="Sprite" parent="."]
position = Vector2( 959, 463 )
texture = ExtResource( 2 )

[node name="Boundaries" type="Node2D" parent="."]

[node name="WallLeft" type="StaticBody2D" parent="Boundaries"]

[node name="CollisionShape2D" type="CollisionShape2D" parent="Boundaries/WallLeft"]
position = Vector2( -30, 546.5 )
shape = SubResource( 1 )

[node name="WallRight" type="StaticBody2D" parent="Boundaries"]
position = Vector2( 1979, 0 )

[node name="CollisionShape2D" type="CollisionShape2D" parent="Boundaries/WallRight"]
position = Vector2( -30, 546.5 )
shape = SubResource( 1 )

[node name="Player" parent="." instance=ExtResource( 1 )]
position = Vector2( 937, 1045 )
21 changes: 21 additions & 0 deletions combo-demo/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2022 GDQuest

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
9 changes: 9 additions & 0 deletions combo-demo/addons/ColorPickerPresets/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@

# Godot-specific ignores
.import/
export.cfg
export_presets.cfg

# Mono-specific ignores
.mono/
data_*/
23 changes: 23 additions & 0 deletions combo-demo/addons/ColorPickerPresets/ColorPickerPresets.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
tool
extends EditorPlugin

const PRESETS_FILENAME := 'presets.hex'


func _enter_tree() -> void:
var presets := PoolColorArray()
var presets_raw := PoolStringArray()
var presets_file := File.new()
var presets_path: String = get_script().resource_path.get_base_dir().plus_file(PRESETS_FILENAME)

if presets_file.open(presets_path, File.READ) == OK:
presets_raw = presets_file.get_as_text().split("\n")
presets_file.close()

for hex in presets_raw:
if hex.is_valid_html_color():
presets.push_back(Color(hex))

get_editor_interface().get_editor_settings().set_project_metadata(
"color_picker", "presets", presets
)
21 changes: 21 additions & 0 deletions combo-demo/addons/ColorPickerPresets/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2021 Răzvan C. Rădulescu

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
40 changes: 40 additions & 0 deletions combo-demo/addons/ColorPickerPresets/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Godot ColorPicker Presets

Reads a color presets hex file in the addon local directory, called `presets.hex`. It adds the colors to the editor ColorPicker for quick access.

This repository includes a `presets.hex` file as an example. It's the [Pear36 color palette](https://lospec.com/palette-list/pear36) and you can directly download it from lospec.

![lospec download](./readme/lospec-download.png)

Follow the format of placing one hex color value per line:

```
5e315b
8c3f5d
ba6156
etc.
```

## ✗ WARNING

The addon:

1. Doesn't check the length of the color palette/file.
1. Skips malformed text lines without warning. It uses the ones it can convert to `Color`.
1. Overwrites the _ColorPicker_ presets whenever you reopen the project or re-enable the addon.

## ✓ Install

1. Make a new folder at `res://addons/ColorPickerPresets/`.
1. Copy the contents of this repository into `res://addons/ColorPickerPresets/`.
1. Replace `res://addons/ColorPickerPresets/presets.hex` with your prefered version.
1. Enable the addon from `Project > Project Settings... > Plugins`.
1. Profit.

![install project settings](./readme/install-project-settings.png)

## Where do I find the presets?

They'll be available in the editor _ColorPicker_.

![ColorPicker presets](./readme/colorpicker-presets.png)
9 changes: 9 additions & 0 deletions combo-demo/addons/ColorPickerPresets/plugin.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[plugin]

name="ColorPickerPresets"
description="Sets the editor color picker presets from
`presets.hex`, if it exists. The file is local to the
addon folder."
author="Răzvan Cosmin Rădulescu - razcore"
version="0.1"
script="ColorPickerPresets.gd"
11 changes: 11 additions & 0 deletions combo-demo/addons/ColorPickerPresets/presets.hex
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
090a20
171830
303049
4a4b63
928fb8
3dff6e
f5fafa
fff540
26c6f7
aa00ba
ff1852
17 changes: 17 additions & 0 deletions combo-demo/addons/rmsmartshape/LEGACY_vertex_properties.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
extends Reference
class_name RMS2D_VertexProperties

var texture_idx:int = 0
var flip:bool = false
var width:float = 1.0

func duplicate()->RMS2D_VertexProperties:
var _new = __new()
_new.texture_idx = texture_idx
_new.flip = flip
_new.width = width
return _new

# Workaround (class cannot reference itself)
func __new()->RMS2D_VertexProperties:
return get_script().new()
123 changes: 123 additions & 0 deletions combo-demo/addons/rmsmartshape/LEGACY_vertex_properties_array.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
extends Reference
class_name RMS2D_VertexPropertiesArray

var properties:Array = []

#############
# INTERFACE #
#############
"""
Returns true if changed
"""
func remove_point(idx:int)->bool:
assert(_is_array_index_in_range(properties, idx))
properties.remove(idx)
return true

"""
Returns true if changed
"""
func add_point(idx:int)->bool:
var new_point_idx = -1
if idx < 0:
properties.push_back(RMS2D_VertexProperties.new())
new_point_idx = properties.size() - 1
else:
assert(_is_array_index_in_range(properties, idx))
properties.insert(idx, RMS2D_VertexProperties.new())
new_point_idx = idx

var old_idx = new_point_idx - 1
properties[new_point_idx] = properties[old_idx].duplicate()
return true

"""
Returns true if changed
"""
func resize(new_size:int):
var old_size = properties.size()
var delta = new_size - old_size
if delta == 0:
return false
properties.resize(new_size)
if delta > 0:
for i in range(old_size-1, new_size, 1):
properties[i] = RMS2D_VertexProperties.new()
return true

"""
Returns true if changed
"""
func set_texture_idx(v:int, idx:int)->bool:
if not _is_array_index_in_range(properties, idx):
return false
properties[idx].texture_idx = v
return true

"""
Returns true if changed
"""
func set_flip(v:bool, idx:int)->bool:
if not _is_array_index_in_range(properties, idx):
return false
properties[idx].flip = v
return true

"""
Returns true if changed
"""
func set_width(v:float, idx:int)->bool:
if not _is_array_index_in_range(properties, idx):
return false
properties[idx].width = v
return true


#########
# GODOT #
#########
"""
Accepts either int or another instance of this class as a constructor argument
"""
func _init(arg):
if typeof(arg) == TYPE_INT:
__init_size(arg)
#elif arg is RMS2D_VertexPropertiesArray:
# __init_class(arg)
else:
assert(false)

func __init_size(_size):
for i in range(0, _size, 1):
properties.push_back(RMS2D_VertexProperties.new())

func __init_class(other):
for p in other.properties:
properties.push_back(p.duplicate())

###########
# GETTERS #
###########
func get_texture_idx(idx:int)->int:
if not _is_array_index_in_range(properties, idx):
return -1
return properties[idx].texture_idx

func get_flip(idx:int)->bool:
if not _is_array_index_in_range(properties, idx):
return false
return properties[idx].flip

func get_width(idx:int)->float:
if not _is_array_index_in_range(properties, idx):
return 1.0
return properties[idx].width


###########
# PRIVATE #
###########
func _is_array_index_in_range(a:Array, i:int)->bool:
if a.size() > i and i >= 0:
return true
return false
Loading