1 module armos.command.generator.material;
2 
3 import std.path;
4 import std.file;
5 import std.uni:toLower;
6 
7 auto generateMaterial(string[] args){
8     MaterialConfig config;
9     config.className = args[0];
10     config.path = buildPath(packageName(), "materials", config.className.toLower~".d");
11     import std.getopt;
12     args.getopt("path|p", &config.path);
13     import std.array;
14     import std.algorithm;
15     import std.conv;
16     config.path = config.path.toLower.filter!(c => c!='-').array.to!string;
17 
18     immutable source = generateMaterialSource(config);
19 
20     string writenPath = buildPath(getcwd, "source", config.path);
21     if(!writenPath.dirName.exists){
22         writenPath.dirName.mkdirRecurse;
23     }
24     write(writenPath, source);
25 }
26 
27 /++
28 +/
29 struct MaterialConfig {
30     public{
31         string className;
32         string path;
33     }//public
34 
35     private{
36     }//private
37 }//struct MaterialConfig
38 
39 auto generateMaterialSource(in MaterialConfig config){
40     string absolutePath;
41     if(isAbsolute(config.path)){
42         absolutePath = config.path;
43     }else{
44         absolutePath = buildPath(getcwd, config.path);
45     }
46 
47     import std.array;
48     import std.algorithm;
49     import std.conv;
50     auto moduleName = config.path.setExtension("").pathSplitter.array;
51     return materialSourceTemplate(moduleName, config.className);
52 }
53 
54 unittest{
55     // MaterialConfig config = {className:"BunnyMaterialm", path:packageName ~ "/" ~ "materials/bunny"};
56     // import std.stdio;
57     // generateMaterialSource(config).writeln;
58 }
59 
60     
61 string materialSourceTemplate(in string[] moduleName, in string className){
62     import std.array;
63     return `module `~moduleName.join('.')~`;
64 import armos.graphics.material;
65 class `~ className ~` : Material{
66     mixin MaterialImpl;
67 }
68 `;
69 }
70 
71 string packageName(){
72     import dub.package_:Package;
73     import dub.internal.vibecompat.inet.path:Path;
74     auto thisPackage = Package.load(Path(buildPath(getcwd)));
75     return thisPackage.recipe.name;
76 }
77 
78 unittest{
79     assert(packageName == "armos");
80 }