|
|
|
|
@ -20,15 +20,39 @@ namespace lunarium { namespace editor
|
|
|
|
|
: EditorAsset(AssetType::EATYPE_SCRIPT)
|
|
|
|
|
{
|
|
|
|
|
std::string full_path = (asset_dir / file_location).string();
|
|
|
|
|
std::ofstream ofs(asset_dir / file_location);
|
|
|
|
|
if (!ofs.is_open())
|
|
|
|
|
|
|
|
|
|
if (!std::filesystem::exists(full_path))
|
|
|
|
|
{
|
|
|
|
|
Logger::Warn(Editor::LogCat, "Could not create file \"%s\"", full_path.c_str());
|
|
|
|
|
}
|
|
|
|
|
std::ofstream ofs(asset_dir / file_location);
|
|
|
|
|
if (!ofs.is_open())
|
|
|
|
|
{
|
|
|
|
|
Logger::Warn(Editor::LogCat, "Could not create file \"%s\"", full_path.c_str());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// This is a new script file so generate the boiler-plate
|
|
|
|
|
std::string script_name = std::filesystem::path(full_path).stem().string();
|
|
|
|
|
std::string code = "// Wren script: " + script_name + "\n";
|
|
|
|
|
code += "\nimport \"CoreAPI\" for Core";
|
|
|
|
|
code += "\nimport \"WorldInterface\" for WorldInterface, EntityBehavior";
|
|
|
|
|
code += "\nimport \"KeyCodes\" for KeyCodes";
|
|
|
|
|
code += "\n\nclass " + script_name + " is EntityBehavior {";
|
|
|
|
|
code += "\n\tconstruct new(id) {";
|
|
|
|
|
code += "\n\t\tsuper.EntityID = id";
|
|
|
|
|
code += "\n\t}";
|
|
|
|
|
code += "\n\n\tOnLoad() {";
|
|
|
|
|
code += "\n\n\t}";
|
|
|
|
|
code += "\n\n\tOnUnload() {";
|
|
|
|
|
code += "\n\n\t}";
|
|
|
|
|
code += "\n\n\tUpdate(dt) {";
|
|
|
|
|
code += "\n\n\t}";
|
|
|
|
|
code += "\n}";
|
|
|
|
|
|
|
|
|
|
ofs.close();
|
|
|
|
|
ofs.clear();
|
|
|
|
|
ofs.write(code.c_str(), code.size());
|
|
|
|
|
|
|
|
|
|
ofs.close();
|
|
|
|
|
ofs.clear();
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
mLocation = file_location;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|