Boiler-plate code generated when new scripts are created

dev
Joey Pollack 3 years ago
parent 320b776fcd
commit 060bfcf6c9

@ -43,7 +43,7 @@ Physics:
Scripting: Scripting:
☐ Add a Log method to the CoreAPI ☐ Add a Log methods to the CoreAPI
✔ Allow scripts to interact (calling methods in other scripts) @done(23-01-10 16:54) ✔ Allow scripts to interact (calling methods in other scripts) @done(23-01-10 16:54)
- In order for a script to be registered with the World API it MUST - In order for a script to be registered with the World API it MUST

@ -1,7 +1,6 @@
Editor: Editor:
☐ Generate boiler-plate code when a new script is created ✔ Generate boiler-plate code when a new script is created @critical @done(23-01-11 13:49)
☐ Include setting the entity ID
✔ Add pure virtual ShowProperties method to EditorAsset @done(22-11-28 20:11) ✔ Add pure virtual ShowProperties method to EditorAsset @done(22-11-28 20:11)
✔ Script Editor Asset @done(22-11-14 18:19) ✔ Script Editor Asset @done(22-11-14 18:19)

@ -20,15 +20,39 @@ namespace lunarium { namespace editor
: EditorAsset(AssetType::EATYPE_SCRIPT) : EditorAsset(AssetType::EATYPE_SCRIPT)
{ {
std::string full_path = (asset_dir / file_location).string(); 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.write(code.c_str(), code.size());
ofs.clear();
ofs.close();
ofs.clear();
}
mLocation = file_location; mLocation = file_location;
} }

Loading…
Cancel
Save