Skip to content

Commit

Permalink
Replaced ResourceWrappers for C# Resources
Browse files Browse the repository at this point in the history
Built custom Mono Godot Editor which fixes Issue godotengine/godot#37812 that previously required use of the ResourceWrapper class to fix.

Version: 3.4.2-stable

Added Commit: godotengine/godot@907e709

Related Pull Request: godotengine/godot#56300
  • Loading branch information
DwarfNinja committed Jan 6, 2022
1 parent 35232ca commit 9382639
Show file tree
Hide file tree
Showing 46 changed files with 226 additions and 463 deletions.
4 changes: 2 additions & 2 deletions Resources/Drop_Tables/ChestDropTable.tres
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[gd_resource type="Resource" load_steps=9 format=2]

[ext_resource path="res://Scripts/Resources/R_DropTable.gd" type="Script" id=1]
[ext_resource path="res://Scripts/Resources/R_DropTableEntry.gd" type="Script" id=2]
[ext_resource path="res://Scripts/Resources/R_DropTable.cs" type="Script" id=1]
[ext_resource path="res://Scripts/Resources/R_DropTableEntry.cs" type="Script" id=2]
[ext_resource path="res://Resources/Entities/Resources/Wood.tres" type="Resource" id=3]
[ext_resource path="res://Resources/Entities/Resources/GoldCoins.tres" type="Resource" id=4]
[ext_resource path="res://Resources/Entities/Resources/Iron.tres" type="Resource" id=5]
Expand Down
6 changes: 3 additions & 3 deletions Resources/Drop_Tables/ContainerDropTable.tres
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
[gd_resource type="Resource" load_steps=5 format=2]

[ext_resource path="res://Resources/Entities/Lootables/Chest.tres" type="Resource" id=1]
[ext_resource path="res://Scripts/Resources/R_DropTableEntry.gd" type="Script" id=2]
[ext_resource path="res://Scripts/Resources/R_DropTable.gd" type="Script" id=3]
[ext_resource path="res://Scenes/Interactables/Chest.tscn" type="PackedScene" id=1]
[ext_resource path="res://Scripts/Resources/R_DropTableEntry.cs" type="Script" id=2]
[ext_resource path="res://Scripts/Resources/R_DropTable.cs" type="Script" id=3]

[sub_resource type="Resource" id=1]
script = ExtResource( 2 )
Expand Down
10 changes: 5 additions & 5 deletions Resources/Drop_Tables/EnemiesDropTable.tres
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
[gd_resource type="Resource" load_steps=5 format=2]

[ext_resource path="res://Scripts/Resources/R_DropTable.gd" type="Script" id=1]
[ext_resource path="res://Scripts/Resources/R_DropTableEntry.gd" type="Script" id=2]
[ext_resource path="res://Scenes/KinematicBodies/Villager.tscn" type="PackedScene" id=3]
[ext_resource path="res://Scripts/Resources/R_DropTable.cs" type="Script" id=1]
[ext_resource path="res://Scenes/KinematicBodies/Villager.tscn" type="PackedScene" id=2]
[ext_resource path="res://Scripts/Resources/R_DropTableEntry.cs" type="Script" id=3]

[sub_resource type="Resource" id=1]
script = ExtResource( 2 )
Item = ExtResource( 3 )
script = ExtResource( 3 )
Item = ExtResource( 2 )
DropRate = 100

[resource]
Expand Down
8 changes: 4 additions & 4 deletions Resources/Entities/Craftables/Forge.tres
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

[ext_resource path="res://Sprites/Items/Forge-Item.png" type="Texture" id=1]
[ext_resource path="res://Sprites/UI/InventoryBar/HUD Forge.png" type="Texture" id=2]
[ext_resource path="res://Scripts/Resources/R_Craftable.gd" type="Script" id=3]
[ext_resource path="res://Scripts/Resources/R_Craftable.cs" type="Script" id=3]
[ext_resource path="res://Sprites/UI/CraftingTable/HUD CraftingTableButton Forge.png" type="Texture" id=4]
[ext_resource path="res://Sprites/Interactables/Craftables/Forge/Forge.png" type="Texture" id=5]

[resource]
script = ExtResource( 3 )
EntityType = 2
EntityType = 3
EntityName = "Forge"
ItemTexture = ExtResource( 1 )
HudTexture = ExtResource( 2 )
Expand All @@ -17,8 +17,8 @@ TileFootprint = Vector2( 2, 1 )
CollisionFootprint = Vector2( 38, 9 )
EntityTexture = ExtResource( 5 )
RequiredItems = {
Resource( "res://Resources/Entities/Resources/Iron.tres" ): 3,
Resource( "res://Resources/Entities/Resources/Wood.tres" ): 1
Resource( "res://Resources/Entities/Resources/Wood.tres" ): 1,
Resource( "res://Resources/Entities/Resources/Iron.tres" ): 3
}
BlueprintIcon = ExtResource( 4 )
PackedsceneString = "res://Scenes/Interactables/Craftables/Forge.tscn"
8 changes: 4 additions & 4 deletions Resources/Entities/Craftables/MiningRig.tres
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
[gd_resource type="Resource" load_steps=6 format=2]

[ext_resource path="res://Scripts/Resources/R_Craftable.gd" type="Script" id=1]
[ext_resource path="res://Scripts/Resources/R_Craftable.cs" type="Script" id=1]
[ext_resource path="res://Sprites/UI/CraftingTable/HUD CraftingTableButton Miningrig.png" type="Texture" id=2]
[ext_resource path="res://Sprites/UI/InventoryBar/HUD MiningRig.png" type="Texture" id=3]
[ext_resource path="res://Sprites/Items/Placeholder-Item.png" type="Texture" id=4]
[ext_resource path="res://Sprites/Interactables/Craftables/MiningRig/MiningRig.png" type="Texture" id=5]

[resource]
script = ExtResource( 1 )
EntityType = 2
EntityType = 3
EntityName = "MiningRig"
ItemTexture = ExtResource( 4 )
HudTexture = ExtResource( 3 )
Expand All @@ -17,8 +17,8 @@ TileFootprint = Vector2( 2, 1 )
CollisionFootprint = Vector2( 32, 12 )
EntityTexture = ExtResource( 5 )
RequiredItems = {
Resource( "res://Resources/Entities/Resources/Iron.tres" ): 2,
Resource( "res://Resources/Entities/Resources/Wood.tres" ): 2
Resource( "res://Resources/Entities/Resources/Wood.tres" ): 2,
Resource( "res://Resources/Entities/Resources/Iron.tres" ): 2
}
BlueprintIcon = ExtResource( 2 )
PackedsceneString = "res://Scenes/Interactables/Craftables/MiningRig.tscn"
2 changes: 1 addition & 1 deletion Resources/Entities/Ladder.tres
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[gd_resource type="Resource" load_steps=3 format=2]

[ext_resource path="res://Scripts/Resources/R_Entity.gd" type="Script" id=1]
[ext_resource path="res://Scripts/Resources/R_Entity.cs" type="Script" id=1]
[ext_resource path="res://Sprites/Entities/Ladder.png" type="Texture" id=2]

[resource]
Expand Down
4 changes: 2 additions & 2 deletions Resources/Entities/Lootables/Chest.tres
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
[gd_resource type="Resource" load_steps=3 format=2]

[ext_resource path="res://Scripts/Resources/R_Entity.gd" type="Script" id=1]
[ext_resource path="res://Scripts/Resources/R_Entity.cs" type="Script" id=1]
[ext_resource path="res://Sprites/Interactables/Chest/Chest-Sheet.png" type="Texture" id=2]

[resource]
script = ExtResource( 1 )
EntityType = 1
EntityType = 2
EntityName = "Chest"
EntityTheme = 0
TileFootprint = Vector2( 1, 1 )
Expand Down
4 changes: 2 additions & 2 deletions Resources/Entities/Props/KitchenCounter.tres
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
[gd_resource type="Resource" load_steps=3 format=2]

[ext_resource path="res://Sprites/Entities/Kitchen_Counter.png" type="Texture" id=1]
[ext_resource path="res://Scripts/Resources/R_Entity.gd" type="Script" id=2]
[ext_resource path="res://Scripts/Resources/R_Entity.cs" type="Script" id=2]

[resource]
script = ExtResource( 2 )
EntityType = 3
EntityType = 4
EntityName = "KitchenCounter"
EntityTheme = 1
TileFootprint = Vector2( 3, 1 )
Expand Down
4 changes: 2 additions & 2 deletions Resources/Entities/Props/KitchenDrawer.tres
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
[gd_resource type="Resource" load_steps=3 format=2]

[ext_resource path="res://Scripts/Resources/R_Entity.gd" type="Script" id=1]
[ext_resource path="res://Scripts/Resources/R_Entity.cs" type="Script" id=1]
[ext_resource path="res://Sprites/Entities/Kitchen_Drawer.png" type="Texture" id=2]

[resource]
script = ExtResource( 1 )
EntityType = 3
EntityType = 4
EntityName = "KitchenDrawer"
EntityTheme = 1
TileFootprint = Vector2( 1, 1 )
Expand Down
4 changes: 2 additions & 2 deletions Resources/Entities/Props/WoodenDrawer.tres
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
[gd_resource type="Resource" load_steps=3 format=2]

[ext_resource path="res://Scripts/Resources/R_Entity.gd" type="Script" id=1]
[ext_resource path="res://Scripts/Resources/R_Entity.cs" type="Script" id=1]
[ext_resource path="res://Sprites/Entities/Wooden_Drawer.png" type="Texture" id=2]

[resource]
script = ExtResource( 1 )
EntityType = 3
EntityType = 4
EntityName = "WoodenDrawer"
EntityTheme = 0
TileFootprint = Vector2( 1, 1 )
Expand Down
4 changes: 2 additions & 2 deletions Resources/Entities/Props/WoodenTable.tres
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
[gd_resource type="Resource" load_steps=3 format=2]

[ext_resource path="res://Scripts/Resources/R_Entity.gd" type="Script" id=1]
[ext_resource path="res://Scripts/Resources/R_Entity.cs" type="Script" id=1]
[ext_resource path="res://Sprites/Entities/Wooden_Table.png" type="Texture" id=2]

[resource]
script = ExtResource( 1 )
EntityType = 3
EntityType = 4
EntityName = "WoodenTable"
EntityTheme = 0
TileFootprint = Vector2( 2, 1 )
Expand Down
2 changes: 1 addition & 1 deletion Resources/Entities/Resources/GoldCoins.tres
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[gd_resource type="Resource" load_steps=3 format=2]

[ext_resource path="res://Scripts/Resources/R_Item.gd" type="Script" id=1]
[ext_resource path="res://Scripts/Resources/R_Item.cs" type="Script" id=1]
[ext_resource path="res://Sprites/Items/GoldCoins.png" type="Texture" id=2]

[resource]
Expand Down
2 changes: 1 addition & 1 deletion Resources/Entities/Resources/Iron.tres
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

[ext_resource path="res://Sprites/Items/Iron.png" type="Texture" id=1]
[ext_resource path="res://Sprites/UI/InventoryBar/HUDIron.png" type="Texture" id=2]
[ext_resource path="res://Scripts/Resources/R_Item.gd" type="Script" id=3]
[ext_resource path="res://Scripts/Resources/R_Item.cs" type="Script" id=3]

[resource]
script = ExtResource( 3 )
Expand Down
2 changes: 1 addition & 1 deletion Resources/Entities/Resources/Wood.tres
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

[ext_resource path="res://Sprites/UI/InventoryBar/HUDWood.png" type="Texture" id=1]
[ext_resource path="res://Sprites/Items/Wood.png" type="Texture" id=2]
[ext_resource path="res://Scripts/Resources/R_Item.gd" type="Script" id=3]
[ext_resource path="res://Scripts/Resources/R_Item.cs" type="Script" id=3]

[resource]
script = ExtResource( 3 )
Expand Down
2 changes: 1 addition & 1 deletion Resources/Villager.tres
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[gd_resource type="Resource" load_steps=3 format=2]

[ext_resource path="res://Sprites/KinematicBodies/Villager.png" type="Texture" id=1]
[ext_resource path="res://Scripts/Resources/R_AI.gd" type="Script" id=2]
[ext_resource path="res://Scripts/Resources/R_AI.cs" type="Script" id=2]

[resource]
script = ExtResource( 2 )
Expand Down
6 changes: 4 additions & 2 deletions Scenes/Interactables/Chest.tscn
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[gd_scene load_steps=9 format=2]
[gd_scene load_steps=10 format=2]

[ext_resource path="res://Sprites/Interactables/Chest/Chest-Sheet.png" type="Texture" id=1]
[ext_resource path="res://Resources/Entities/Lootables/Chest.tres" type="Resource" id=2]
[ext_resource path="res://Scripts/Classes/ContainerEntity.cs" type="Script" id=3]
[ext_resource path="res://Shaders/Materials/Outline.tres" type="Material" id=4]
[ext_resource path="res://Resources/Drop_Tables/ChestDropTable.tres" type="Resource" id=5]
Expand Down Expand Up @@ -45,7 +46,8 @@ tracks/0/keys = {
[node name="Chest" type="StaticBody2D"]
collision_layer = 8
script = ExtResource( 3 )
dropTableDefResource = ExtResource( 5 )
EntityDef = ExtResource( 2 )
dropTableDef = ExtResource( 5 )

[node name="EntitySprite" type="Sprite" parent="."]
material = ExtResource( 4 )
Expand Down
4 changes: 3 additions & 1 deletion Scenes/Worlds/Cave/Cave.tscn
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[gd_scene load_steps=19 format=2]
[gd_scene load_steps=20 format=2]

[ext_resource path="res://Resources/Entities/Craftables/MiningRig.tres" type="Resource" id=1]
[ext_resource path="res://Resources/Entities/Lootables/Chest.tres" type="Resource" id=2]
Expand All @@ -18,6 +18,7 @@
[ext_resource path="res://Scenes/KinematicBodies/Player.tscn" type="PackedScene" id=16]
[ext_resource path="res://Resources/Entities/Craftables/Forge.tres" type="Resource" id=17]
[ext_resource path="res://Resources/Entities/Ladder.tres" type="Resource" id=18]
[ext_resource path="res://Resources/Drop_Tables/ChestDropTable.tres" type="Resource" id=19]

[node name="Cave" type="Node2D"]
script = ExtResource( 8 )
Expand Down Expand Up @@ -59,6 +60,7 @@ position = Vector2( 80, 32 )
[node name="Chest" parent="YSort" instance=ExtResource( 15 )]
position = Vector2( 88, 128 )
EntityDef = ExtResource( 2 )
dropTableDef = ExtResource( 19 )

[node name="TileSelector" type="Sprite" parent="YSort"]
z_index = 1
Expand Down
18 changes: 7 additions & 11 deletions Scripts/Classes/ContainerEntity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@
public class ContainerEntity : InteractableEntity {

[Export]
private Resource dropTableDefResource;

private RW_DropTable dropTableDef;
private R_DropTable dropTableDef;

private PackedScene itemScene;
private AnimationPlayer animationPlayer;
Expand All @@ -24,8 +22,7 @@ public class ContainerEntity : InteractableEntity {

public override void _Ready() {
base._Ready();

dropTableDef = new RW_DropTable(dropTableDefResource);

itemScene = (PackedScene) ResourceLoader.Load("res://Scenes/Items/Item.tscn");
animationPlayer = (AnimationPlayer) GetNode("AnimationPlayer");
itemSpawnPosition = (Position2D) GetNode("ItemSpawnPosition");
Expand Down Expand Up @@ -54,7 +51,7 @@ private void DropItems() {
Array<Vector2> availableDirections = directionList.Duplicate();

foreach (int item in Enumerable.Range(1, GetRandomItemAmount())) {
RW_Item randomItemResource = SelectItemFromDropTable();
R_Item randomItemResource = SelectItemFromDropTable();

PickableItem randomItem = (PickableItem) itemScene.Instance();
randomItem.ItemDef = randomItemResource;
Expand All @@ -66,17 +63,17 @@ private void DropItems() {
}
}

private RW_Item SelectItemFromDropTable() {
Array<RW_DropTableEntry> dropTable = dropTableDef.DropTable;
private R_Item SelectItemFromDropTable() {
Array<R_DropTableEntry> dropTable = dropTableDef.DropTable;
int totalDropChance = 0;
int cumulativeDropChance = 0;

foreach (RW_DropTableEntry dropTableEntry in dropTable) {
foreach (R_DropTableEntry dropTableEntry in dropTable) {
totalDropChance += dropTableEntry.DropRate;
}

int rng = (int) randomNumberGenerator.Randi() % totalDropChance;
foreach (RW_DropTableEntry dropTableEntry in dropTable) {
foreach (R_DropTableEntry dropTableEntry in dropTable) {
cumulativeDropChance += dropTableEntry.DropRate;
//if the RNG is <= item cumulated total_drop_chance then drop that item
if (rng <= cumulativeDropChance) {
Expand All @@ -93,7 +90,6 @@ private Vector2 GetRandomDropDirection(Array<Vector2> availableDirectionList) {
availableDirectionList.RemoveAt(0);
return randomDirection;
}


private int GetRandomItemAmount() {
uint numberOfitems = randomNumberGenerator.Randi() % 3 + 2;
Expand Down
28 changes: 15 additions & 13 deletions Scripts/Classes/Entity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,17 @@
public class Entity : StaticBody2D {

[Export]
public Resource EntityDef {
get => entityDef?.Resource;
public R_Entity EntityDef {
get => entityDef;
set {
entityDef = value switch {
null => null,
RW_Entity entity => entity,
_ => new RW_Entity(value)
};
entityDef = value;
if (entityDef != null) {
SetEntity();
}
}
}

private RW_Entity entityDef;
private R_Entity entityDef;

[Export]
private Direction facing = Direction.Front;
Expand Down Expand Up @@ -47,6 +43,10 @@ public override void _Ready() {
throw new Exception("No entity_def defined in entity " + this + " with name: " + Name);
}
}

if (entityDef != null) {
SetEntity();
}
}

private void SetEntity() {
Expand All @@ -57,14 +57,16 @@ private void SetEntity() {
CalculateSpriteData();

switch (entityDef.EntityType) {
case RW_Item.Type.Prop:
SetSpriteFrames(1, 4);
break;
case RW_Item.Type.Lootable:
case R_Item.Type.Interactable:
return;
case R_Item.Type.Lootable:
SetSpriteFrames(3, 1);
break;
case RW_Item.Type.Craftable:
case R_Item.Type.Craftable:
return;
case R_Item.Type.Prop:
SetSpriteFrames(1, 4);
break;
default:
throw new ArgumentOutOfRangeException();
}
Expand Down
Loading

0 comments on commit 9382639

Please sign in to comment.