This repository has been archived by the owner on Feb 23, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcompiler.dart
96 lines (80 loc) · 2.94 KB
/
compiler.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
// DartGodot Compiler (Dart2Godot)
// and to compiled (runnable c#)
import 'dart:io';
import 'package:process_run/process_run.dart';
Future<void> main () async {
var scriptsFolder = Directory('scripts');
var scripts = scriptsFolder.listSync();
scripts.forEach((f) async {
var input = f.path;
var className = f.path.split('\\')[1].split('.')[0];
var destination = 'compiled\\data\\${className}.d2g';
await Directory('compiled\\data').create(recursive: true);
await run('dart2js',['-O4','-o',destination,input], verbose: true);
var data = await File(destination).readAsString();
await File(destination).delete();
await File(destination+'.deps').delete();
await File(destination+'.map').delete();
String replaceCharAt(String oldString, int index, String newChar) {
return oldString.substring(0, index) + newChar + oldString.substring(index + 1);
}
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;
}
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\\${className}.cs';
var ourFile = await File(f.path).readAsString();
if (have(ourFile, 'extends Node')){
var ourCsData = await File('cs\\Node.cs.tmp').readAsString();
ourCsData = ourCsData.replaceAll('DARTGODOT_FILEPATHJS', pathFixer(destination.replaceAll(r'compiled\', r'DartGodot\compiled\')));
ourCsData = ourCsData.replaceAll('DARTGODOT_CLASSNAME',className);
final fileCs = await File(csDestination);
await fileCs.writeAsString(ourCsData);
}
File('cs\\DartConnector.cs.tmp').copySync('compiled\\data\\DartConnector.cs');
});
}