Skip to content
This repository has been archived by the owner on Feb 23, 2023. It is now read-only.

Commit

Permalink
compiler is done for now
Browse files Browse the repository at this point in the history
  • Loading branch information
mahdisml committed Sep 26, 2020
1 parent 4046e9a commit 7cd932f
Show file tree
Hide file tree
Showing 5 changed files with 185 additions and 13 deletions.
22 changes: 20 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,31 @@ DartGodot is a Dart language Game Framework for the Godot game engine.
DartGodot is still in the very early stages of development. APIs can and will change (now is the time to make suggestions!). Important features are missing.There is no Documentation for now. Please don't build any serious projects in DartGodot unless you are prepared to be broken by api changes constantly.

# Development Status

<del>
Im currently working on a Dart2Godot crossplatform compiler to use dart in godot without pain and hard configs
</del>

compiler is done

Next step is implementing api , its easy but its too time consuming
Im currently working on implementing api , its easy but its too time consuming

Support me by giving Star :)

# Getting Started
1. you must use Mono version (C# support) of Godot
2. add below package to your .csproj

<PackageReference Include="Jint">
<Version>3.0.0-beta-1828</Version>
</PackageReference>
3. clone or download this project (DartGodot)
4. see scripts folder in dartgodot project
5. edit or add scripts inside scripts folder
6. run compiler.dart (with command line)
7. copy compiled folder to your godot project files (you can add DartGodot folder to your godot project files for easier use and removing this step)
8. it is done :) you can use C# files in Godot


# Be a Project Sponsor

talk to me : [email protected]
Expand Down
31 changes: 31 additions & 0 deletions compiled/TestArea.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using Godot;

public class Node : Godot.Node
{
private DartConnector _dartConnector;

public override void _EnterTree()
{
base._EnterTree();
_dartConnector = new DartConnector("data\\TestArea.d2g");
_dartConnector.EnterTree();
}
public override void _Ready()
{
_dartConnector.Ready();
}
public override void _Process(float delta)
{
_dartConnector.Process(delta);
}
public override void _PhysicsProcess(float delta)
{
base._PhysicsProcess(delta);
_dartConnector.PhysicsProcess(delta);
}
public override void _ExitTree()
{
base._ExitTree();
_dartConnector.ExitTree();
}
}
79 changes: 79 additions & 0 deletions compiled/data/DartConnector.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
using System;
using System.IO;

namespace Godot
{
public class DartConnector
{
private readonly Jint.Engine engine;
/* you must add below package to your .csproj
<PackageReference Include="Jint">
<Version>3.0.0-beta-1828</Version>
</PackageReference>
*/
public DartConnector(string sourcePath)
{
engine = new Jint.Engine();
engine.SetValue("CS_GD__Print", new Action<object>(o => GD.Print(o)));
engine.SetValue("print", new Action<object>(o => GD.Print(o)));
engine.SetValue("self","this");
engine.Execute(new StreamReader(sourcePath).ReadToEnd());
}

public void EnterTree()
{
try
{
engine.Invoke("enterTree");
}
catch (Exception e)
{
GD.Print(e);
}
}
public void Ready()
{
try
{
engine.Invoke("ready");
}
catch (Exception e)
{
GD.Print(e);
}
}
public void Process(float delta)
{
try
{
engine.Invoke("process",(double)(decimal)delta);
}
catch (Exception e)
{
GD.Print(e);
}
}
public void PhysicsProcess(float delta)
{
try
{
engine.Invoke("physicsProcess",(double)(decimal)delta);
}
catch (Exception e)
{
GD.Print(e);
}
}
public void ExitTree()
{
try
{
engine.Invoke("exitTree");
}
catch (Exception e)
{
GD.Print(e);
}
}
}
}
64 changes: 54 additions & 10 deletions compiler.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,66 @@ Future<void> main () async {
String replaceCharAt(String oldString, int index, String newChar) {
return oldString.substring(0, index) + newChar + oldString.substring(index + 1);
}
var length = data.length;
for ( var i = 0 ; i + 4 < length ; i++){
if (data [i] == 's' && data [i+1] == 'e' &&
data [i+2] == 'l' && data [i+3] == 'f' && data [i+4] == '.'){
data = replaceCharAt (data,i,'');
data = replaceCharAt (data,i,'');
data = replaceCharAt (data,i,'');
data = replaceCharAt (data,i,'');
data = replaceCharAt (data,i,'');
String replaceString(String oldData,String oldString,String newString){
var length = oldData.length;
for ( var i = 0 ; i + oldString.length < length ; i++){
var isIt = true;
for (var j = 0 ; j < oldString.length; j++){
if (oldData[i+j] != oldString[j]){
isIt = false;
break;
}
}
if (isIt){
for (var j = 0 ; j < oldString.length; j++){
if(j == oldString.length - 1){
oldData = replaceCharAt (oldData,i,newString);
}else{
oldData = replaceCharAt (oldData,i,'');
}
length = oldData.length;
}
length = oldData.length;
}
length = oldData.length;
}
length = data.length;
return oldData;
}
bool have(String oldData,String oldString){
var length = oldData.length;
var isItAtAll = false;
for ( var i = 0 ; i + oldString.length < length ; i++){
var isIt = true;
for (var j = 0 ; j < oldString.length; j++){
if (oldData[i+j] != oldString[j]){
isIt = false;
break;
}
}
if (isIt == true) {
isItAtAll = true;
}
}
return isItAtAll;
}
String pathFixer(String path){
return path.replaceAll(r'\', r'\\');
}
data = data.replaceAll('self.','');
final file = await File(destination);
await file.writeAsString(data);

var csDestination = 'compiled\\${f.path.split('\\')[1].split('.')[0]}.cs';
var ourFile = await File(f.path).readAsString();

if (have(ourFile, 'extends Node')){
var ourCsData = await File('cs\\Node.cs').readAsString();
ourCsData = ourCsData.replaceAll('DARTGODOTFILEPATHJS', pathFixer(destination.replaceAll(r'compiled\', '')));
final fileCs = await File(csDestination);
await fileCs.writeAsString(ourCsData);
}

File('cs\\DartConnector.cs').copySync('compiled\\data\\DartConnector.cs');

});

Expand Down
2 changes: 1 addition & 1 deletion cs/Node.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public class Node : Godot.Node
public override void _EnterTree()
{
base._EnterTree();
_dartConnector = new DartConnector("test.js");
_dartConnector = new DartConnector("DARTGODOTFILEPATHJS");
_dartConnector.EnterTree();
}
public override void _Ready()
Expand Down

0 comments on commit 7cd932f

Please sign in to comment.