Skip to content

Commit

Permalink
Add pistol and rifle json in item editor
Browse files Browse the repository at this point in the history
  • Loading branch information
snipercup committed Jan 23, 2024
1 parent 1a06644 commit 160ec24
Show file tree
Hide file tree
Showing 15 changed files with 244 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Defaults/Mobs/mob_corpse.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
[ext_resource type="Script" path="res://Scripts/container.gd" id="1_4celg"]
[ext_resource type="Texture2D" uid="uid://cy56wx4qynp3m" path="res://Textures/enemy.png" id="2_pvjek"]
[ext_resource type="Script" path="res://addons/gloot/core/inventory_grid_stacked.gd" id="3_131gg"]
[ext_resource type="Resource" uid="uid://bvrl0obu5ejqq" path="res://ItemProtosets.tres" id="4_ehn4b"]
[ext_resource type="Resource" uid="uid://b1tngttyk4w2s" path="res://ItemProtosets.tres" id="4_ehn4b"]

[sub_resource type="SphereShape3D" id="SphereShape3D_0pnwx"]
radius = 0.2
Expand Down
48 changes: 47 additions & 1 deletion ItemProtosets.tres
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[gd_resource type="Resource" script_class="ItemProtoset" load_steps=2 format=3 uid="uid://bvrl0obu5ejqq"]
[gd_resource type="Resource" script_class="ItemProtoset" load_steps=2 format=3 uid="uid://b1tngttyk4w2s"]

[ext_resource type="Script" path="res://addons/gloot/core/item_protoset.gd" id="1_o35lu"]

Expand Down Expand Up @@ -53,5 +53,51 @@ json_data = "[
\"stack_size\": \"1\",
\"weight\": \"0.25\",
\"width\": \"1\"
},
{
\"Ranged\": {
\"firing_speed\": \"0.25\",
\"range\": \"1000\",
\"recoil\": \"20\",
\"reload_speed\": \"2.5\",
\"spread\": \"5\",
\"sway\": \"5\",
\"used_ammo\": \"9mm\",
\"used_magazine\": \"pistol_magazine\",
\"used_skill\": \"short_guns\"
},
\"description\": \"A standard issue pistol that uses 9mm ammunition\",
\"height\": \"2\",
\"id\": \"pistol_9mm\",
\"image\": \"./Mods/Core/Items/pistol_64.png\",
\"max_stack_size\": \"1\",
\"name\": \"Pistol 9mm\",
\"sprite\": \"pistol_64.png\",
\"stack_size\": \"1\",
\"weight\": \"2\",
\"width\": \"2\"
},
{
\"Ranged\": {
\"firing_speed\": \"0.1\",
\"range\": \"1000\",
\"recoil\": \"15\",
\"reload_speed\": \"2.5\",
\"spread\": \"8\",
\"sway\": \"5\",
\"used_ammo\": \"9mm\",
\"used_magazine\": \"pistol_magazine\",
\"used_skill\": \"short_guns\"
},
\"description\": \"A standard issue rifle that uses 9mm ammunition\",
\"height\": \"2\",
\"id\": \"rifle_m4a1\",
\"image\": \"./Mods/Core/Items/rifle_128_64.png\",
\"max_stack_size\": \"1\",
\"name\": \"M4a1 rifle\",
\"sprite\": \"rifle_128_64.png\",
\"stack_size\": \"1\",
\"weight\": \"4\",
\"width\": \"4\"
}
]"
46 changes: 46 additions & 0 deletions Mods/Core/Items/Items.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,51 @@
"stack_size": "1",
"weight": "0.25",
"width": "1"
},
{
"Ranged": {
"firing_speed": "0.25",
"range": "1000",
"recoil": "20",
"reload_speed": "2.5",
"spread": "5",
"sway": "5",
"used_ammo": "9mm",
"used_magazine": "pistol_magazine",
"used_skill": "short_guns"
},
"description": "A standard issue pistol that uses 9mm ammunition",
"height": "2",
"id": "pistol_9mm",
"image": "./Mods/Core/Items/pistol_64.png",
"max_stack_size": "1",
"name": "Pistol 9mm",
"sprite": "pistol_64.png",
"stack_size": "1",
"weight": "2",
"width": "2"
},
{
"Ranged": {
"firing_speed": "0.1",
"range": "1000",
"recoil": "15",
"reload_speed": "2.5",
"spread": "8",
"sway": "5",
"used_ammo": "9mm",
"used_magazine": "pistol_magazine",
"used_skill": "short_guns"
},
"description": "A standard issue rifle that uses 9mm ammunition",
"height": "2",
"id": "rifle_m4a1",
"image": "./Mods/Core/Items/rifle_128_64.png",
"max_stack_size": "1",
"name": "M4a1 rifle",
"sprite": "rifle_128_64.png",
"stack_size": "1",
"weight": "4",
"width": "4"
}
]
Binary file added Mods/Core/Items/pistol_64.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
34 changes: 34 additions & 0 deletions Mods/Core/Items/pistol_64.png.import
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
[remap]

importer="texture"
type="CompressedTexture2D"
uid="uid://hktpdnah1cbg"
path="res://.godot/imported/pistol_64.png-feaeec3d09921e141e026bd860429ada.ctex"
metadata={
"vram_texture": false
}

[deps]

source_file="res://Mods/Core/Items/pistol_64.png"
dest_files=["res://.godot/imported/pistol_64.png-feaeec3d09921e141e026bd860429ada.ctex"]

[params]

compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=false
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1
Binary file added Mods/Core/Items/rifle_128_64.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
34 changes: 34 additions & 0 deletions Mods/Core/Items/rifle_128_64.png.import
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
[remap]

importer="texture"
type="CompressedTexture2D"
uid="uid://iaxknyj2b5s2"
path="res://.godot/imported/rifle_128_64.png-b12f38a9f7ff52df43988cce360173b4.ctex"
metadata={
"vram_texture": false
}

[deps]

source_file="res://Mods/Core/Items/rifle_128_64.png"
dest_files=["res://.godot/imported/rifle_128_64.png-b12f38a9f7ff52df43988cce360173b4.ctex"]

[params]

compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=false
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ script = ExtResource("1_5v06u")
DamageNumberBox = NodePath("Ammo/DamageNumber")

[node name="Ammo" type="GridContainer" parent="."]
layout_mode = 0
size_flags_vertical = 3
columns = 2

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ value = 1.0
layout_mode = 2
text = "Type(s)"

[node name="TypesContainer" type="HBoxContainer" parent="VBoxContainer/TabContainer/Basic"]
[node name="TypesContainer" type="HFlowContainer" parent="VBoxContainer/TabContainer/Basic"]
layout_mode = 2

[node name="RangedWeaponCheck" type="CheckBox" parent="VBoxContainer/TabContainer/Basic/TypesContainer"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ grow_vertical = 2
script = ExtResource("1_cgvqr")

[node name="Magazine" type="GridContainer" parent="."]
layout_mode = 0
size_flags_vertical = 3
columns = 2

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ layout_mode = 2
text = "Magazine"

[node name="UsedMagazineTextEdit" type="TextEdit" parent="Ranged"]
custom_minimum_size = Vector2(0, 28)
layout_mode = 2
size_flags_horizontal = 3
size_flags_stretch_ratio = 0.9
Expand Down Expand Up @@ -100,6 +101,7 @@ layout_mode = 2
text = "Skill"

[node name="UsedSkillTextEdit" type="TextEdit" parent="Ranged"]
custom_minimum_size = Vector2(0, 28)
layout_mode = 2
size_flags_horizontal = 3
size_flags_stretch_ratio = 0.9
Expand Down
8 changes: 8 additions & 0 deletions Scripts/ItemAmmoEditor.gd
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,11 @@ extends Control
# Form elements
@export var DamageNumberBox: SpinBox = null

func get_properties() -> Dictionary:
return {
"damage": DamageNumberBox.get_line_edit().text
}

func set_properties(properties: Dictionary) -> void:
if properties.has("damage"):
DamageNumberBox.get_line_edit().text = properties["damage"]
24 changes: 23 additions & 1 deletion Scripts/ItemEditor.gd
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ extends Control
@export var StackSizeNumberBox: SpinBox = null
@export var MaxStackSizeNumberBox: SpinBox = null

@export var typesContainer: HBoxContainer = null
@export var typesContainer: HFlowContainer = null



Expand Down Expand Up @@ -72,6 +72,18 @@ func load_item_data() -> void:
if MaxStackSizeNumberBox != null and contentData.has("max_stack_size"):
MaxStackSizeNumberBox.get_line_edit().text = contentData["max_stack_size"]

# Loop through typesContainer children to load additional properties and set button_pressed
for i in range(typesContainer.get_child_count()):
var child = typesContainer.get_child(i)
if child is CheckBox:
var tabIndex = get_tab_by_title(child.text)
var tab = tabContainer.get_child(tabIndex)
if tab and tab.has_method("set_properties") and contentData.has(child.text):
tab.set_properties(contentData[child.text])
# Set button_pressed to true if contentData has the property
child.button_pressed = true
refresh_tab_visibility()

#The editor is closed, destroy the instance
#TODO: Check for unsaved changes
func _on_close_button_button_up() -> void:
Expand All @@ -92,6 +104,16 @@ func _on_save_button_button_up() -> void:
contentData["weight"] = WeightNumberBox.get_line_edit().text
contentData["stack_size"] = StackSizeNumberBox.get_line_edit().text
contentData["max_stack_size"] = MaxStackSizeNumberBox.get_line_edit().text

# Loop through typesContainer children to save additional properties
for i in range(typesContainer.get_child_count()):
var child = typesContainer.get_child(i)
# Check if the child is a CheckBox and its button_pressed is true
if child is CheckBox and child.button_pressed:
var tabIndex = get_tab_by_title(child.text)
var tab = tabContainer.get_child(tabIndex)
if tab and tab.has_method("get_properties"):
contentData[child.text] = tab.get_properties()
data_changed.emit()

#When the itemImageDisplay is clicked, the user will be prompted to select an image from
Expand Down
16 changes: 14 additions & 2 deletions Scripts/ItemMagazineEditor.gd
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,18 @@ extends Control


# Form elements
@export var ReloadSpeedNumberBox: SpinBox = null
@export var FiringSpeedNumberBox: SpinBox = null
@export var UsedAmmoTextEdit: TextEdit = null
@export var MaxAmmoNumberBox: SpinBox = null


func get_properties() -> Dictionary:
return {
"used_ammo": UsedAmmoTextEdit.text,
"max_ammo": MaxAmmoNumberBox.get_line_edit().text
}

func set_properties(properties: Dictionary) -> void:
if properties.has("used_ammo"):
UsedAmmoTextEdit.text = properties["used_ammo"]
if properties.has("max_ammo"):
MaxAmmoNumberBox.get_line_edit().text = properties["max_ammo"]
33 changes: 32 additions & 1 deletion Scripts/ItemRangedEditor.gd
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ extends Control
# This scene is intended to be used inside the item editor
# It is supposed to edit exactly one ranged weapon


# Ranged form elements
@export var UsedAmmoTextEdit: TextEdit = null
@export var UsedMagazineTextEdit: TextEdit = null
Expand All @@ -15,3 +14,35 @@ extends Control
@export var ReloadSpeedNumberBox: SpinBox = null
@export var FiringSpeedNumberBox: SpinBox = null

func get_properties() -> Dictionary:
return {
"used_ammo": UsedAmmoTextEdit.text,
"used_magazine": UsedMagazineTextEdit.text,
"range": RangeNumberBox.get_line_edit().text,
"spread": SpreadNumberBox.get_line_edit().text,
"sway": SwayNumberBox.get_line_edit().text,
"recoil": RecoilNumberBox.get_line_edit().text,
"used_skill": UsedSkillTextEdit.text,
"reload_speed": ReloadSpeedNumberBox.get_line_edit().text,
"firing_speed": FiringSpeedNumberBox.get_line_edit().text
}

func set_properties(properties: Dictionary) -> void:
if properties.has("used_ammo"):
UsedAmmoTextEdit.text = properties["used_ammo"]
if properties.has("used_magazine"):
UsedMagazineTextEdit.text = properties["used_magazine"]
if properties.has("range"):
RangeNumberBox.get_line_edit().text = properties["range"]
if properties.has("spread"):
SpreadNumberBox.get_line_edit().text = properties["spread"]
if properties.has("sway"):
SwayNumberBox.get_line_edit().text = properties["sway"]
if properties.has("recoil"):
RecoilNumberBox.get_line_edit().text = properties["recoil"]
if properties.has("used_skill"):
UsedSkillTextEdit.text = properties["used_skill"]
if properties.has("reload_speed"):
ReloadSpeedNumberBox.get_line_edit().text = properties["reload_speed"]
if properties.has("firing_speed"):
FiringSpeedNumberBox.get_line_edit().text = properties["firing_speed"]

0 comments on commit 160ec24

Please sign in to comment.