Compare commits
6 Commits
523502c89d
...
2ee8c16731
Author | SHA1 | Date |
---|---|---|
jkpete | 2ee8c16731 | 2 months ago |
jkpete | 89c2c7cd3e | 2 months ago |
jkpete | 670d07b391 | 2 months ago |
jkpete | df2bc47ee6 | 3 months ago |
jkpete | cc79a0a53f | 4 months ago |
jkpete | de6073356c | 4 months ago |
41 changed files with 972 additions and 145 deletions
@ -0,0 +1,112 @@
@@ -0,0 +1,112 @@
|
||||
[gd_scene load_steps=19 format=3 uid="uid://05atvgqt8tku"] |
||||
|
||||
[ext_resource type="Texture2D" uid="uid://ss8dh8aaqc4w" path="res://Example/Action3D/SkyBox/lakeside.jpg" id="1_akq3m"] |
||||
[ext_resource type="Texture2D" uid="uid://31r216hix0wk" path="res://icon.svg" id="2_b66wh"] |
||||
[ext_resource type="Script" path="res://Example/Action3D/Script/ActionPlayer.cs" id="2_c0s4j"] |
||||
[ext_resource type="Script" path="res://Example/Action3D/Script/ActionCamera.cs" id="3_ue0e3"] |
||||
|
||||
[sub_resource type="PanoramaSkyMaterial" id="PanoramaSkyMaterial_hbme1"] |
||||
panorama = ExtResource("1_akq3m") |
||||
|
||||
[sub_resource type="Sky" id="Sky_qmmlv"] |
||||
sky_material = SubResource("PanoramaSkyMaterial_hbme1") |
||||
|
||||
[sub_resource type="Environment" id="Environment_dusyb"] |
||||
background_mode = 2 |
||||
sky = SubResource("Sky_qmmlv") |
||||
glow_enabled = true |
||||
fog_light_color = Color(0.152941, 0.168627, 0.196078, 1) |
||||
fog_density = 0.05 |
||||
fog_aerial_perspective = 1.0 |
||||
fog_height = 0.5 |
||||
fog_height_density = 0.4 |
||||
adjustment_brightness = 1.91 |
||||
|
||||
[sub_resource type="BoxShape3D" id="BoxShape3D_hm8uo"] |
||||
size = Vector3(60, 1, 60) |
||||
|
||||
[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_c0bvn"] |
||||
albedo_texture = ExtResource("2_b66wh") |
||||
|
||||
[sub_resource type="BoxMesh" id="BoxMesh_2gv65"] |
||||
material = SubResource("StandardMaterial3D_c0bvn") |
||||
size = Vector3(60, 1, 60) |
||||
|
||||
[sub_resource type="BoxShape3D" id="BoxShape3D_4jggu"] |
||||
|
||||
[sub_resource type="BoxShape3D" id="BoxShape3D_7005m"] |
||||
|
||||
[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_byd0k"] |
||||
albedo_color = Color(0, 0.219608, 0.176471, 1) |
||||
|
||||
[sub_resource type="BoxMesh" id="BoxMesh_h3y2r"] |
||||
|
||||
[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_r4ehu"] |
||||
albedo_color = Color(0.517647, 0.886275, 0.807843, 1) |
||||
rim_enabled = true |
||||
rim_tint = 0.48 |
||||
|
||||
[sub_resource type="BoxMesh" id="BoxMesh_3o4en"] |
||||
material = SubResource("StandardMaterial3D_r4ehu") |
||||
size = Vector3(0.5, 0.5, 0.5) |
||||
|
||||
[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_dv57j"] |
||||
albedo_color = Color(0.294118, 0.294118, 0.294118, 1) |
||||
metallic = 1.0 |
||||
metallic_specular = 1.0 |
||||
|
||||
[sub_resource type="BoxMesh" id="BoxMesh_iv7ly"] |
||||
material = SubResource("StandardMaterial3D_dv57j") |
||||
size = Vector3(0.6, 0.6, 0.6) |
||||
|
||||
[node name="MainGame" type="Node3D"] |
||||
|
||||
[node name="WorldEnvironment" type="WorldEnvironment" parent="."] |
||||
environment = SubResource("Environment_dusyb") |
||||
|
||||
[node name="DirectionalLight3D" type="DirectionalLight3D" parent="."] |
||||
transform = Transform3D(0.642788, -0.383022, 0.663414, 0, 0.866025, 0.5, -0.766044, -0.321394, 0.55667, 0, 0, 0) |
||||
shadow_enabled = true |
||||
|
||||
[node name="Ground" type="StaticBody3D" parent="."] |
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -1.01419, 0) |
||||
|
||||
[node name="CollisionShape3D" type="CollisionShape3D" parent="Ground"] |
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -0.00709915, 0.117098, -0.180923) |
||||
shape = SubResource("BoxShape3D_hm8uo") |
||||
|
||||
[node name="MeshInstance3D" type="MeshInstance3D" parent="Ground"] |
||||
mesh = SubResource("BoxMesh_2gv65") |
||||
|
||||
[node name="Area3D" type="Area3D" parent="."] |
||||
visible = false |
||||
|
||||
[node name="CollisionShape3D" type="CollisionShape3D" parent="Area3D"] |
||||
shape = SubResource("BoxShape3D_4jggu") |
||||
|
||||
[node name="Pivot" type="Node3D" parent="."] |
||||
script = ExtResource("3_ue0e3") |
||||
|
||||
[node name="Camera3D" type="Camera3D" parent="Pivot"] |
||||
transform = Transform3D(1, 0, 0, 0, 0.976296, 0.21644, 0, -0.21644, 0.976296, 0, 1, 2) |
||||
|
||||
[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) |
||||
shape = SubResource("BoxShape3D_7005m") |
||||
|
||||
[node name="Body" type="MeshInstance3D" parent="Player"] |
||||
material_override = SubResource("StandardMaterial3D_byd0k") |
||||
mesh = SubResource("BoxMesh_h3y2r") |
||||
|
||||
[node name="Head" type="MeshInstance3D" parent="Player/Body"] |
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.75, 0) |
||||
mesh = SubResource("BoxMesh_3o4en") |
||||
|
||||
[node name="Hair" type="MeshInstance3D" parent="Player/Body"] |
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.8, 0.15) |
||||
mesh = SubResource("BoxMesh_iv7ly") |
@ -0,0 +1,46 @@
@@ -0,0 +1,46 @@
|
||||
using Godot; |
||||
using System; |
||||
|
||||
public partial class ActionCamera : Node3D |
||||
{ |
||||
[Export] |
||||
public float Speed { get; set; } = 4; |
||||
private Vector3 _targetRotation = Vector3.Zero; |
||||
// Called when the node enters the scene tree for the first time. |
||||
public override void _Ready() |
||||
{ |
||||
} |
||||
|
||||
// Called every frame. 'delta' is the elapsed time since the previous frame. |
||||
public override void _Process(double delta) |
||||
{ |
||||
} |
||||
|
||||
public override void _PhysicsProcess(double delta) |
||||
{ |
||||
if (Input.IsActionPressed("camera_up")) |
||||
{ |
||||
_targetRotation.X -= Speed*(float)delta; |
||||
} |
||||
if (Input.IsActionPressed("camera_down")) |
||||
{ |
||||
_targetRotation.X += Speed*(float)delta; |
||||
} |
||||
if (Input.IsActionPressed("camera_left")) |
||||
{ |
||||
_targetRotation.Y += Speed*(float)delta; |
||||
} |
||||
if (Input.IsActionPressed("camera_right")) |
||||
{ |
||||
_targetRotation.Y -= Speed*(float)delta; |
||||
} |
||||
if (_targetRotation.X>30*Mathf.Pi/180) |
||||
{ |
||||
_targetRotation.X = 30*Mathf.Pi/180; |
||||
} |
||||
if (_targetRotation.X<-30*Mathf.Pi/180){ |
||||
_targetRotation.X = -30*Mathf.Pi/180; |
||||
} |
||||
this.Rotation = this.Rotation.Lerp(_targetRotation,Speed*(float)delta) ; |
||||
} |
||||
} |
@ -0,0 +1,69 @@
@@ -0,0 +1,69 @@
|
||||
using Godot; |
||||
using System; |
||||
|
||||
namespace EGFramework.Examples.Action3D{ |
||||
public partial class ActionPlayer : CharacterBody3D |
||||
{ |
||||
[Export] |
||||
public float Speed { get; set; } = 14; |
||||
[Export] |
||||
public float JumpSpeed { set; get; } = 15; |
||||
[Export] |
||||
public float FallAcceleration { get; set; } = 75; |
||||
|
||||
public float FallSpeed { get; set; } = 0; |
||||
|
||||
private Vector3 _targetVelocity = Vector3.Zero; |
||||
|
||||
public Node3D CameraPivot { set; get; } |
||||
// Called when the node enters the scene tree for the first time. |
||||
public override void _Ready() |
||||
{ |
||||
CameraPivot = this.GetNode<Node3D>("../Pivot"); |
||||
} |
||||
|
||||
// Called every frame. 'delta' is the elapsed time since the previous frame. |
||||
public override void _Process(double delta) |
||||
{ |
||||
} |
||||
|
||||
public override void _PhysicsProcess(double delta) |
||||
{ |
||||
// We create a local variable to store the input direction. |
||||
var direction = Vector3.Zero; |
||||
|
||||
direction.X = Input.GetAxis("move_left", "move_right"); |
||||
direction.Z = Input.GetAxis("move_forward", "move_back"); |
||||
|
||||
|
||||
if (direction.Length() > 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); |
||||
} |
||||
// direction.Rotated(Vector3.Up, CameraPivot.Rotation.Y); |
||||
// Ground velocity |
||||
_targetVelocity.X = direction.X * Speed; |
||||
_targetVelocity.Z = direction.Z * Speed; |
||||
|
||||
if (!IsOnFloor()) // If in the air, fall towards the floor. Literally gravity |
||||
{ |
||||
// GD.Print(FallSpeed); |
||||
FallSpeed -= FallAcceleration * (float)delta; |
||||
_targetVelocity.Y += FallSpeed; |
||||
}else{ |
||||
if (Input.IsActionPressed("jump")) |
||||
{ |
||||
_targetVelocity.Y = 0.1f; |
||||
FallSpeed = JumpSpeed; |
||||
} |
||||
} |
||||
|
||||
this.Velocity = _targetVelocity; |
||||
MoveAndSlide(); |
||||
CameraPivot.Position = this.Position; |
||||
} |
||||
} |
||||
} |
After Width: | Height: | Size: 4.1 MiB |
@ -0,0 +1,35 @@
@@ -0,0 +1,35 @@
|
||||
[remap] |
||||
|
||||
importer="texture" |
||||
type="CompressedTexture2D" |
||||
uid="uid://ss8dh8aaqc4w" |
||||
path.s3tc="res://.godot/imported/lakeside.jpg-33a4031d53286dbc1f7dd66477cda464.s3tc.ctex" |
||||
metadata={ |
||||
"imported_formats": ["s3tc_bptc"], |
||||
"vram_texture": true |
||||
} |
||||
|
||||
[deps] |
||||
|
||||
source_file="res://Example/Action3D/SkyBox/lakeside.jpg" |
||||
dest_files=["res://.godot/imported/lakeside.jpg-33a4031d53286dbc1f7dd66477cda464.s3tc.ctex"] |
||||
|
||||
[params] |
||||
|
||||
compress/mode=2 |
||||
compress/high_quality=false |
||||
compress/lossy_quality=0.7 |
||||
compress/hdr_compression=1 |
||||
compress/normal_map=0 |
||||
compress/channel_pack=0 |
||||
mipmaps/generate=true |
||||
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=0 |
@ -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 = "" |
@ -0,0 +1,17 @@
@@ -0,0 +1,17 @@
|
||||
[remap] |
||||
|
||||
importer="csv_translation" |
||||
type="Translation" |
||||
uid="uid://dhb625wmjnlwy" |
||||
|
||||
[deps] |
||||
|
||||
files=["res://Example/SystemExamples/ItemList/ItemList.en.translation", "res://Example/SystemExamples/ItemList/ItemList.es.translation", "res://Example/SystemExamples/ItemList/ItemList.ja.translation"] |
||||
|
||||
source_file="res://Example/SystemExamples/ItemList/ItemList.CSV" |
||||
dest_files=["res://Example/SystemExamples/ItemList/ItemList.en.translation", "res://Example/SystemExamples/ItemList/ItemList.es.translation", "res://Example/SystemExamples/ItemList/ItemList.ja.translation"] |
||||
|
||||
[params] |
||||
|
||||
compress=true |
||||
delimiter=0 |
@ -0,0 +1,3 @@
@@ -0,0 +1,3 @@
|
||||
{ |
||||
|
||||
} |
@ -0,0 +1,5 @@
@@ -0,0 +1,5 @@
|
||||
keys,en,es,ja |
||||
GREET,"Hello, friend!","Hola, amigo!",こんにちは |
||||
ASK,How are you?,Cómo está?,元気ですか |
||||
BYE,Goodbye,Adiós,さようなら |
||||
QUOTE,"""Hello"" said the man.","""Hola"" dijo el hombre.",「こんにちは」男は言いました |
@ -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") |
@ -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(); |
||||
} |
||||
} |
||||
} |
@ -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(); |
||||
} |
||||
} |
@ -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) |
||||
{ |
||||
} |
||||
} |
@ -0,0 +1,102 @@
@@ -0,0 +1,102 @@
|
||||
using Godot; |
||||
using LiteDB; |
||||
using System; |
||||
using System.IO; |
||||
|
||||
namespace EGFramework.Examples.Test{ |
||||
public partial class EGSaveTest : Node,IEGFramework |
||||
{ |
||||
public override void _Ready() |
||||
{ |
||||
base._Ready(); |
||||
this.EGSave().OpenUserPath(); |
||||
// GD.Print(ProjectSettings.GlobalizePath("res://SaveData/Default.json")); |
||||
// GD.Print(ProjectSettings.GlobalizePath("user://SaveData/Default.json")); |
||||
// GD.Print(Path.GetDirectoryName(ProjectSettings.GlobalizePath("res://SaveData/Default.json"))); |
||||
// TestLiteDB(); |
||||
} |
||||
|
||||
public void TestSqlite(){ |
||||
// string result = this.EGSqlite().CreateTable<SqliteBackpackItem>(); |
||||
this.EGSqlite().SaveData(new SqliteBackpackItem{ |
||||
ItemID = 10, |
||||
ItemCount = 1, |
||||
BackpackID = 1, |
||||
}); |
||||
GD.Print(this.EGSqlite().ExceptionMsg); |
||||
// var properties = typeof(SqliteBackpackItem).GetFields(); |
||||
// Godot.GD.Print(properties.Count() + " Readed "); |
||||
} |
||||
|
||||
public void TestLiteDB(){ |
||||
// 打开数据库 (如果不存在自动创建) |
||||
using(var db = new LiteDatabase("SaveData/MyData.db")) |
||||
{ |
||||
// 获取一个集合 (如果不存在创建) |
||||
LiteCollection<Customer> col = (LiteCollection<Customer>)db.GetCollection<Customer>("customers"); |
||||
GD.Print(col); |
||||
|
||||
// // 创建新顾客实例 |
||||
// var customer = new Customer |
||||
// { |
||||
// Id = 200, |
||||
// Name = "Alexander King", |
||||
// Phones = new string[] { "8000-0000", "9000-0000" }, |
||||
// IsActive = true |
||||
// }; |
||||
// // 插入新顾客文档 (Id 自增) |
||||
// for (int i = 0; i < 10000; i++) |
||||
// { |
||||
// customer.Id ++; |
||||
// col.Insert(customer); |
||||
// } |
||||
// // 更新集合中的一个文档 |
||||
// customer.Name = "Joana Doe"; |
||||
// col.Update(customer); |
||||
// // 使用文档的 Name 属性为文档建立索引 |
||||
// col.EnsureIndex(x => x.Name); |
||||
// 使用 LINQ 查询文档 |
||||
// var results = col.Find(x => x.Name.StartsWith("Al")); |
||||
// GD.Print("Find:"+results.Count()); |
||||
// string ids = ""; |
||||
// foreach(var item in results){ |
||||
// ids += "["+item.Id.ToString()+"]"; |
||||
|
||||
// } |
||||
// GD.Print(ids); |
||||
// // 让我们创建在电话号码字段上创建一个索引 (使用表达式). 它是一个多键值索引 |
||||
// //col.EnsureIndex(x => x.Phones, "$.Phones[*]"); |
||||
// col.EnsureIndex(x => x.Phones); |
||||
// // 现在我们可以查询电话号码 |
||||
// var r = col.FindOne(x => x.Phones.Contains("8888-5555"));\ |
||||
|
||||
// Test Other |
||||
// ILiteCollection<SqliteBackpackItem> col = db.GetCollection<SqliteBackpackItem>("SqliteBackpackItem"); |
||||
// var item = new SqliteBackpackItem{ |
||||
// ItemID = 10, |
||||
// ItemCount = 1, |
||||
// BackpackID = 1, |
||||
// }; |
||||
// for (int i = 0; i < 100; i++) |
||||
// { |
||||
// col.Insert(item); |
||||
// } |
||||
} |
||||
} |
||||
|
||||
} |
||||
public struct SqliteBackpackItem{ |
||||
public int Id { get; set; } |
||||
public int ItemID { get; set; } |
||||
public int ItemCount { get; set; } |
||||
public int BackpackID { get; set; } |
||||
} |
||||
|
||||
public class Customer |
||||
{ |
||||
public int Id { get; set; } |
||||
public string Name { get; set; } |
||||
public string[] Phones { get; set; } |
||||
public bool IsActive { get; set; } |
||||
} |
||||
} |
@ -0,0 +1,49 @@
@@ -0,0 +1,49 @@
|
||||
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,IEGSaveObject |
||||
{ |
||||
|
||||
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 void InitSaveFile(string path) |
||||
{ |
||||
//throw new NotImplementedException(); |
||||
} |
||||
|
||||
public void SetObject<TObject>(string objectKey , TObject obj) |
||||
{ |
||||
throw new NotImplementedException(); |
||||
} |
||||
|
||||
public TObject GetObject<TObject>(string objectKey) where TObject : new() |
||||
{ |
||||
throw new NotImplementedException(); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,15 @@
@@ -0,0 +1,15 @@
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Linq; |
||||
using System.Threading.Tasks; |
||||
|
||||
namespace EGFramework |
||||
{ |
||||
public class EGCsv : EGModule |
||||
{ |
||||
public override void Init() |
||||
{ |
||||
|
||||
} |
||||
} |
||||
} |
@ -0,0 +1,67 @@
@@ -0,0 +1,67 @@
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.IO; |
||||
using System.Linq; |
||||
using System.Threading.Tasks; |
||||
using Newtonsoft.Json; |
||||
using Newtonsoft.Json.Linq; |
||||
|
||||
namespace EGFramework |
||||
{ |
||||
public class EGJsonSave : IEGSave,IEGSaveObject |
||||
{ |
||||
private string DefaultPath { set; get; } |
||||
private JObject _SaveObject; |
||||
private JObject SaveObject{ |
||||
get { |
||||
if(_SaveObject == null){ |
||||
InitSaveFile(DefaultPath); |
||||
} |
||||
return _SaveObject; |
||||
} |
||||
} |
||||
|
||||
/// <summary> |
||||
/// Init a new save data file or load an other file with json suffix, if you want to load other save data, please use this function to reload; |
||||
/// </summary> |
||||
public void InitSaveFile(string path) |
||||
{ |
||||
DefaultPath = path; |
||||
if(!File.Exists(path)){ |
||||
if (!Directory.Exists(DefaultPath)) |
||||
{ |
||||
Directory.CreateDirectory(Path.GetDirectoryName(DefaultPath)); |
||||
File.WriteAllText(DefaultPath,"{}"); |
||||
}else if(!File.Exists(DefaultPath)){ |
||||
File.WriteAllText(DefaultPath,"{}"); |
||||
} |
||||
} |
||||
using (StreamReader reader = File.OpenText(path)) |
||||
{ |
||||
_SaveObject = (JObject)JToken.ReadFrom(new JsonTextReader(reader)); |
||||
} |
||||
} |
||||
|
||||
public void SetObject<TObject>(string objectKey,TObject obj) |
||||
{ |
||||
if(SaveObject.ContainsKey(typeof(TObject).ToString())){ |
||||
SaveObject[typeof(TObject).ToString()] = JToken.FromObject(obj); |
||||
}else{ |
||||
SaveObject.Add(typeof(TObject).ToString(),JToken.FromObject(obj)); |
||||
} |
||||
File.WriteAllText(DefaultPath,JsonConvert.SerializeObject(SaveObject,Formatting.Indented)); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// Get data from file, if your data is not in file, then throw an exception. |
||||
/// </summary> |
||||
public TObject GetObject<TObject>(string objectKey) where TObject : new() |
||||
{ |
||||
if(!SaveObject.ContainsKey(typeof(TObject).ToString())){ |
||||
throw new Exception("Key not found!"); |
||||
} |
||||
TObject data = SaveObject[typeof(TObject).ToString()].ToObject<TObject>(); |
||||
return data; |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,16 @@
@@ -0,0 +1,16 @@
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Linq; |
||||
using System.Threading.Tasks; |
||||
using LiteDB; |
||||
|
||||
namespace EGFramework |
||||
{ |
||||
public class EGLiteDB : EGModule |
||||
{ |
||||
public override void Init() |
||||
{ |
||||
// throw new NotImplementedException(); |
||||
} |
||||
} |
||||
} |
@ -1,122 +1,103 @@
@@ -1,122 +1,103 @@
|
||||
using System; |
||||
using System.IO; |
||||
using System.Collections.Generic; |
||||
using Newtonsoft.Json; |
||||
using Newtonsoft.Json.Linq; |
||||
using Godot; |
||||
|
||||
namespace EGFramework |
||||
{ |
||||
public interface IEGSave{ |
||||
void SetDataToFile<TData>(TData data); |
||||
TData GetDataByFile<TData>() where TData : class,new(); |
||||
void InitSaveData(string fileName); |
||||
public enum TypeEGSave{ |
||||
Json = 0, |
||||
Bson = 1, |
||||
Byte = 2, |
||||
XML = 3 |
||||
} |
||||
public enum TypeDBSave{ |
||||
Csv = 0, |
||||
Sqlite = 1, |
||||
LiteDB = 2, |
||||
} |
||||
public class EGSave : EGModule,IEGSave |
||||
{ |
||||
private string DefaultSaveFile = "Default"; |
||||
private string DefaultSaveFolder = "SaveData"; |
||||
private JObject _SaveObject; |
||||
private JObject SaveObject{ |
||||
get { |
||||
if(_SaveObject == null){ |
||||
InitSaveObject(); |
||||
} |
||||
return _SaveObject; |
||||
} |
||||
} |
||||
|
||||
public EGSave(){ |
||||
public class EGSave : EGModule |
||||
{ |
||||
#region About Godot File's PATH |
||||
// Godot's Path has res:// and user:// |
||||
// UserPath is used for every platform such as android. |
||||
// You can use ProjectSettings.GlobalizePath("") to convert a "local" path like res://path/to/file.txt to an absolute OS path. |
||||
#endregion |
||||
|
||||
} |
||||
/// <summary> |
||||
/// if you want to define default save data file name, please use "this.RegisterModule(new EGSave("FileName"))"in your architecture code(Init function); |
||||
/// </summary> |
||||
/// <param name="fileName"></param> |
||||
public EGSave(string fileName){ |
||||
this.DefaultSaveFile = fileName; |
||||
} |
||||
private Dictionary<string,IEGSaveData> DataBaseFiles = new Dictionary<string,IEGSaveData>(); |
||||
private Dictionary<string,IEGSaveObject> ObjectFiles = new Dictionary<string,IEGSaveObject>(); |
||||
public EGSave() {} |
||||
public override void Init() |
||||
{ |
||||
if (!Directory.Exists(DefaultSaveFolder)) |
||||
{ |
||||
Directory.CreateDirectory(DefaultSaveFolder); |
||||
File.WriteAllText(DefaultSaveFolder + "/" + DefaultSaveFile + ".json","{}"); |
||||
}else if(!File.Exists(DefaultSaveFolder + "/" + DefaultSaveFile + ".json")){ |
||||
File.WriteAllText(DefaultSaveFolder + "/" + DefaultSaveFile + ".json","{}"); |
||||
LoadObjectFile("Default/SaveData.json".GetGodotUserPath(),TypeEGSave.Json); |
||||
} |
||||
|
||||
public void LoadDataFile(string path,TypeDBSave type){ |
||||
switch(type){ |
||||
case TypeDBSave.Csv: |
||||
break; |
||||
default: |
||||
break; |
||||
} |
||||
} |
||||
|
||||
private void InitSaveObject(){ |
||||
using (StreamReader reader = File.OpenText(DefaultSaveFolder + "/" + DefaultSaveFile + ".json")) |
||||
{ |
||||
_SaveObject = (JObject)JToken.ReadFrom(new JsonTextReader(reader)); |
||||
public void LoadObjectFile(string path,TypeEGSave type){ |
||||
switch(type){ |
||||
case TypeEGSave.Json: |
||||
EGJsonSave newJsonFile = new EGJsonSave(); |
||||
newJsonFile.InitSaveFile(path); |
||||
ObjectFiles.Add(path, newJsonFile); |
||||
break; |
||||
default: |
||||
break; |
||||
} |
||||
} |
||||
|
||||
/// <summary> |
||||
/// Push SaveObject data set to file |
||||
/// </summary> |
||||
public void SaveToFile(){ |
||||
SaveToFile(DefaultSaveFile); |
||||
public void SetObject<TObject>(string path,string objectKey,TObject obj){ |
||||
ObjectFiles[path].SetObject(objectKey,obj); |
||||
} |
||||
private void SaveToFile(string fileName){ |
||||
File.WriteAllText(DefaultSaveFolder + "/" + fileName + ".json",JsonConvert.SerializeObject(SaveObject,Formatting.Indented)); |
||||
public TObject GetObject<TObject>(string path,string key) where TObject : new(){ |
||||
return ObjectFiles[path].GetObject<TObject>(key); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// Push data to SaveObject object cache, this function will not save data to file, if you hope not to IO operation frequently, you can use this with SaveToFile. |
||||
/// </summary> |
||||
/// <param name="data"></param> |
||||
/// <typeparam name="TData"></typeparam> |
||||
public void SetData<TData>(TData data){ |
||||
//SaveObject = JObject.FromObject(data); |
||||
if(SaveObject.ContainsKey(typeof(TData).ToString())){ |
||||
SaveObject[typeof(TData).ToString()] = JToken.FromObject(data); |
||||
}else{ |
||||
SaveObject.Add(typeof(TData).ToString(),JToken.FromObject(data)); |
||||
} |
||||
} |
||||
//------------------------------------------------------------------------------// |
||||
|
||||
/// <summary> |
||||
/// Get data from file, if your data is not in file, then get null. |
||||
/// </summary> |
||||
/// <typeparam name="TData"></typeparam> |
||||
public TData GetDataByFile<TData>() where TData : class,new(){ |
||||
if(!SaveObject.ContainsKey(typeof(TData).ToString())){ |
||||
return null; |
||||
} |
||||
TData data = SaveObject[typeof(TData).ToString()].ToObject<TData>(); |
||||
return data; |
||||
#region Default Json Operation |
||||
public void SetObjectToJson<TObject>(TObject obj){ |
||||
ObjectFiles["Default/SaveData.json"].SetObject(typeof(TObject).ToString(),obj); |
||||
} |
||||
public TObject GetObjectFromJson<TObject>() where TObject : new(){ |
||||
return ObjectFiles["Default/SaveData.json"].GetObject<TObject>(typeof(TObject).ToString()); |
||||
} |
||||
#endregion |
||||
|
||||
/// <summary> |
||||
/// Save data to file |
||||
/// </summary> |
||||
/// <param name="data">your any type of data</param> |
||||
/// <typeparam name="TData"></typeparam> |
||||
public void SetDataToFile<TData>(TData data) |
||||
{ |
||||
SetData(data); |
||||
SaveToFile(); |
||||
//------------------------------------------------------------------------------// |
||||
|
||||
|
||||
public void OpenResPath(){ |
||||
OS.ShellOpen("".GetGodotResPath()); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// Init a new save data file or load an other file with json suffix, if you want to load other save data, please use this function to reload; |
||||
/// </summary> |
||||
/// <param name="fileName"></param> |
||||
public void InitSaveData(string fileName) |
||||
{ |
||||
DefaultSaveFile = fileName; |
||||
if(!File.Exists(DefaultSaveFolder + "/" + DefaultSaveFile + ".json")){ |
||||
File.WriteAllText(DefaultSaveFolder + "/" + DefaultSaveFile + ".json","{}"); |
||||
} |
||||
InitSaveObject(); |
||||
public void OpenUserPath(){ |
||||
OS.ShellOpen("".GetGodotUserPath()); |
||||
} |
||||
} |
||||
|
||||
|
||||
} |
||||
|
||||
public static class CanGetEGSaveExtension{ |
||||
public static EGSave EGSave(this IEGFramework self){ |
||||
return EGArchitectureImplement.Interface.GetModule<EGSave>(); |
||||
return self.GetModule<EGSave>(); |
||||
} |
||||
|
||||
public static string GetGodotResPath(this string absPath){ |
||||
return ProjectSettings.GlobalizePath("res://"+absPath); |
||||
} |
||||
|
||||
public static string GetGodotUserPath(this string absPath){ |
||||
return ProjectSettings.GlobalizePath("user://"+absPath); |
||||
} |
||||
|
||||
} |
||||
} |
@ -0,0 +1,23 @@
@@ -0,0 +1,23 @@
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Linq; |
||||
using System.Threading.Tasks; |
||||
|
||||
namespace EGFramework |
||||
{ |
||||
public interface IEGSave{ |
||||
void InitSaveFile(string path); |
||||
} |
||||
|
||||
public interface IEGSaveObject{ |
||||
void SetObject<TObject>(string objectKey,TObject obj); |
||||
TObject GetObject<TObject>(string objectKey) where TObject : new(); |
||||
} |
||||
|
||||
// |
||||
public interface IEGSaveData{ |
||||
void SetData<TData>(TData data,string dataKey,int id); |
||||
TData GetData<TData>(string dataKey,int id) where TData : new(); |
||||
IList<TData> QueryData<TData>(string dataKey,string sql) where TData : new(); |
||||
} |
||||
} |
@ -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 |
@ -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 = "重新载入" |
@ -0,0 +1,7 @@
@@ -0,0 +1,7 @@
|
||||
[plugin] |
||||
|
||||
name="ItemImporter" |
||||
description="a csv ItemImporter" |
||||
author="jkpete" |
||||
version="" |
||||
script="ToolItemImporter.cs" |
Loading…
Reference in new issue