Browse Source

add a example of Storage

master
jkpete 3 months ago
parent
commit
df2bc47ee6
  1. 2
      Example/Action3D/MainGame.tscn
  2. 4
      Example/Action3D/Script/ActionCamera.cs
  3. 19
      Example/Action3D/Script/ActionPlayer.cs
  4. 9
      Example/SystemExamples/ItemList/HPPotion.tres
  5. 12
      Example/SystemExamples/PlayerStorage/PlayerStorage.tscn
  6. 36
      Example/SystemExamples/PlayerStorage/Script/DataStorageItem.cs
  7. 23
      Example/SystemExamples/PlayerStorage/Script/InterfaceStorage.cs
  8. 19
      Example/SystemExamples/PlayerStorage/Script/ViewStorage.cs
  9. 2
      addons/EGFramework/Module/NodeExtension/EGCreate.cs
  10. 47
      addons/EGFramework/Module/SaveTools/EGByteSave.cs
  11. 54
      addons/Tools/ItemImporter/ToolItemImporter.cs
  12. 37
      addons/Tools/ItemImporter/ToolItemImporter.tscn
  13. 7
      addons/Tools/ItemImporter/plugin.cfg
  14. 4
      project.godot

2
Example/Action3D/MainGame.tscn

@ -92,6 +92,8 @@ transform = Transform3D(1, 0, 0, 0, 0.976296, 0.21644, 0, -0.21644, 0.976296, 0, @@ -92,6 +92,8 @@ transform = Transform3D(1, 0, 0, 0, 0.976296, 0.21644, 0, -0.21644, 0.976296, 0,
[node name="Player" type="CharacterBody3D" parent="."]
script = ExtResource("2_c0s4j")
JumpSpeed = 2.0
FallAcceleration = 9.8
[node name="CollisionShape3D" type="CollisionShape3D" parent="Player"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.0296049, -9.53674e-07, 0.00402832)

4
Example/Action3D/Script/ActionCamera.cs

@ -28,11 +28,11 @@ public partial class ActionCamera : Node3D @@ -28,11 +28,11 @@ public partial class ActionCamera : Node3D
}
if (Input.IsActionPressed("camera_left"))
{
_targetRotation.Y -= Speed*(float)delta;
_targetRotation.Y += Speed*(float)delta;
}
if (Input.IsActionPressed("camera_right"))
{
_targetRotation.Y += Speed*(float)delta;
_targetRotation.Y -= Speed*(float)delta;
}
if (_targetRotation.X>30*Mathf.Pi/180)
{

19
Example/Action3D/Script/ActionPlayer.cs

@ -5,9 +5,13 @@ namespace EGFramework.Examples.Action3D{ @@ -5,9 +5,13 @@ namespace EGFramework.Examples.Action3D{
public partial class ActionPlayer : CharacterBody3D
{
[Export]
public int Speed { get; set; } = 14;
public float Speed { get; set; } = 14;
[Export]
public int FallAcceleration { get; set; } = 75;
public float JumpSpeed { set; get; } = 15;
[Export]
public float FallAcceleration { get; set; } = 75;
public float FallSpeed { get; set; } = 0;
private Vector3 _targetVelocity = Vector3.Zero;
@ -34,7 +38,8 @@ namespace EGFramework.Examples.Action3D{ @@ -34,7 +38,8 @@ namespace EGFramework.Examples.Action3D{
if (direction.Length() > 0)
{
this.Rotation = new Vector3(0,CameraPivot.Rotation.Y,0);
// this.Rotation = new Vector3(0,CameraPivot.Rotation.Y,0);
this.GetNode<Node3D>("Body").Rotation = new Vector3(0,CameraPivot.Rotation.Y,0);
direction = direction.Normalized();
direction = direction.Rotated(Vector3.Up, CameraPivot.Rotation.Y);
}
@ -45,12 +50,14 @@ namespace EGFramework.Examples.Action3D{ @@ -45,12 +50,14 @@ namespace EGFramework.Examples.Action3D{
if (!IsOnFloor()) // If in the air, fall towards the floor. Literally gravity
{
// GD.Print("Fallen!");
_targetVelocity.Y -= FallAcceleration * (float)delta;
// GD.Print(FallSpeed);
FallSpeed -= FallAcceleration * (float)delta;
_targetVelocity.Y += FallSpeed;
}else{
if (Input.IsActionPressed("jump"))
{
_targetVelocity.Y += 10.0f;
_targetVelocity.Y = 0.1f;
FallSpeed = JumpSpeed;
}
}

9
Example/SystemExamples/ItemList/HPPotion.tres

@ -0,0 +1,9 @@ @@ -0,0 +1,9 @@
[gd_resource type="Resource" load_steps=2 format=3 uid="uid://bhsavl0d80s6j"]
[ext_resource type="Script" path="res://Example/SystemExamples/PlayerStorage/Script/DataStorageItem.cs" id="1_j773b"]
[resource]
script = ExtResource("1_j773b")
Id = 0
Name = ""
Info = ""

12
Example/SystemExamples/PlayerStorage/PlayerStorage.tscn

@ -0,0 +1,12 @@ @@ -0,0 +1,12 @@
[gd_scene load_steps=2 format=3 uid="uid://tee7nc525si7"]
[ext_resource type="Script" path="res://Example/SystemExamples/PlayerStorage/Script/ViewStorage.cs" id="1_goow2"]
[node name="PlayerStorage" type="Control"]
layout_mode = 3
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
script = ExtResource("1_goow2")

36
Example/SystemExamples/PlayerStorage/Script/DataStorageItem.cs

@ -0,0 +1,36 @@ @@ -0,0 +1,36 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Godot;
namespace EGFramework.Example.SystemExamples.PlayerStorage
{
public partial class DataStorageItem : Resource, IItem
{
[Export] public int Id { set; get; }
[Export] public string Name { set; get; }
[Export(PropertyHint.MultilineText)] public string Info { set; get; }
[Export] public Texture Icon { set; get; }
public Texture GetIcon()
{
throw new NotImplementedException();
}
public string GetInfo()
{
throw new NotImplementedException();
}
public int GetItemId()
{
throw new NotImplementedException();
}
public string GetName()
{
throw new NotImplementedException();
}
}
}

23
Example/SystemExamples/PlayerStorage/Script/InterfaceStorage.cs

@ -0,0 +1,23 @@ @@ -0,0 +1,23 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Godot;
namespace EGFramework.Example.SystemExamples.PlayerStorage
{
public interface IItem
{
public int GetItemId();
public string GetName();
public Texture GetIcon();
public string GetInfo();
}
public interface IBackPackItem : IItem{
public int GetCount();
}
public interface ICostItem: IItem {
public void OnCost();
}
}

19
Example/SystemExamples/PlayerStorage/Script/ViewStorage.cs

@ -0,0 +1,19 @@ @@ -0,0 +1,19 @@
using Godot;
using System;
using EGFramework;
public partial class ViewStorage : Node,IEGFramework
{
// Called when the node enters the scene tree for the first time.
public override void _Ready()
{
// this.GetModule<EGByteSave>().SaveToFile("nihao");
Variant result = this.GetModule<EGByteSave>().LoadFromFile();
GD.Print(result);
}
// Called every frame. 'delta' is the elapsed time since the previous frame.
public override void _Process(double delta)
{
}
}

2
addons/EGFramework/Module/NodeExtension/EGCreate.cs

@ -42,7 +42,7 @@ namespace EGFramework{ @@ -42,7 +42,7 @@ namespace EGFramework{
}
public static void Alert(this Node self,string alertMsg){
}
}
}

47
addons/EGFramework/Module/SaveTools/EGByteSave.cs

@ -0,0 +1,47 @@ @@ -0,0 +1,47 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Runtime.Serialization.Formatters.Binary;
using Godot;
namespace EGFramework
{
public class EGByteSave : EGModule//, IEGSave
{
public void SaveToFile(string content)
{
using var file = FileAccess.Open("user://save_game.dat", FileAccess.ModeFlags.Write);
Variant hp = 10;
file.StoreVar(hp);
Variant pos = new Vector2(100,100);
file.StoreVar(pos);
}
public Variant LoadFromFile()
{
using var file = FileAccess.Open("user://save_game.dat", FileAccess.ModeFlags.Read);
Variant content = file.GetVar();
Variant pos = file.GetVar();
return pos;
}
public override void Init()
{
}
// public TData GetDataByFile<TData>() where TData : class, new()
// {
// throw new NotImplementedException();
// }
// public void InitSaveData(string fileName)
// {
// throw new NotImplementedException();
// }
public void SetDataToFile<TData>(TData data)
{
}
}
}

54
addons/Tools/ItemImporter/ToolItemImporter.cs

@ -0,0 +1,54 @@ @@ -0,0 +1,54 @@
#if TOOLS
using Godot;
using System;
namespace EGFramework.Example.SystemExamples.PlayerStorage
{
[Tool]
public partial class ToolItemImporter : EditorPlugin
{
PackedScene MainPanel = ResourceLoader.Load<PackedScene>("res://addons/Tools/ItemImporter/ToolItemImporter.tscn");
Control MainPanelInstance;
public override void _EnterTree()
{
// Initialization of the plugin goes here.
MainPanelInstance = (Control)MainPanel.Instantiate();
// Add the main panel to the editor's main viewport.
EditorInterface.Singleton.GetEditorMainScreen().AddChild(MainPanelInstance);
// Hide the main panel. Very much required.
_MakeVisible(false);
}
public override void _ExitTree()
{
// Clean-up of the plugin goes here.
if (MainPanelInstance != null)
{
MainPanelInstance.QueueFree();
}
}
public override bool _HasMainScreen()
{
return true;
}
public override void _MakeVisible(bool visible)
{
if (MainPanelInstance != null)
{
MainPanelInstance.Visible = visible;
}
}
public override string _GetPluginName()
{
return "Tool Item Importer";
}
public override Texture2D _GetPluginIcon()
{
return EditorInterface.Singleton.GetEditorTheme().GetIcon("Node", "EditorIcons");
}
}
}
#endif

37
addons/Tools/ItemImporter/ToolItemImporter.tscn

@ -0,0 +1,37 @@ @@ -0,0 +1,37 @@
[gd_scene format=3 uid="uid://bglw1yht7w1kt"]
[node name="ToolItemImporter" type="Control"]
layout_mode = 3
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
[node name="Button" type="Button" parent="."]
layout_mode = 1
offset_right = 69.0
offset_bottom = 31.0
text = "导入CSV"
[node name="Button2" type="Button" parent="."]
layout_mode = 1
anchors_preset = 1
anchor_left = 1.0
anchor_right = 1.0
offset_left = -72.0
offset_bottom = 31.0
grow_horizontal = 0
text = "重新载入"
[node name="Button3" type="Button" parent="."]
layout_mode = 1
anchors_preset = 1
anchor_left = 1.0
anchor_right = 1.0
offset_left = -71.0
offset_top = 36.0
offset_right = 1.0
offset_bottom = 67.0
grow_horizontal = 0
text = "重新载入"

7
addons/Tools/ItemImporter/plugin.cfg

@ -0,0 +1,7 @@ @@ -0,0 +1,7 @@
[plugin]
name="ItemImporter"
description="a csv ItemImporter"
author="jkpete"
version=""
script="ToolItemImporter.cs"

4
project.godot

@ -20,6 +20,10 @@ config/icon="res://icon.svg" @@ -20,6 +20,10 @@ config/icon="res://icon.svg"
project/assembly_name="EGFramework"
[editor_plugins]
enabled=PackedStringArray("res://addons/Tools/ItemImporter/plugin.cfg")
[input]
move_forward={

Loading…
Cancel
Save