Skip to content

Commit

Permalink
👼Script: Minor bugfixes and formatting in scripts.
Browse files Browse the repository at this point in the history
  • Loading branch information
ohlidalp committed Nov 25, 2024
1 parent afd3f44 commit 65c1baa
Show file tree
Hide file tree
Showing 5 changed files with 91 additions and 62 deletions.
4 changes: 2 additions & 2 deletions resources/scripts/example_GenericDocument_editor.as
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ void frameStep(float dt)
if (@actor != null)
{
CacheEntryClass@ entry = modcache.findEntryByFilename(LOADER_TYPE_ALLBEAM, /*partial:*/false, actor.getTruckFileName());
if (@entry != null)
if (@entry != null && entry.resource_bundle_type == "FileSystem")
{
@projectEntry = @entry;
loadDocument();
Expand Down Expand Up @@ -111,7 +111,7 @@ void createProjectFromActorAsync(BeamClass@ actor )
errorString = "Failed to load cache entry!";

// request project to be created from that cache entry
string proj_name = "project1";
string proj_name = "gd_editor_" + src_entry.fname;
game.pushMessage(MSG_EDI_CREATE_PROJECT_REQUESTED, {
{'name', proj_name},
{'source_entry', src_entry}
Expand Down
2 changes: 1 addition & 1 deletion resources/scripts/example_RigEditor_alpha.as
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ void frameStep(float dt)
if (@actor != null)
{
CacheEntryClass@ entry = modcache.findEntryByFilename(LOADER_TYPE_ALLBEAM, /*partial:*/false, actor.getTruckFileName());
if (@entry != null)
if (@entry != null && entry.resource_bundle_type == "FileSystem")
{
@m_project_entry = @entry;
loadDocument();
Expand Down
15 changes: 9 additions & 6 deletions resources/scripts/example_game_shockTuning.as
Original file line number Diff line number Diff line change
Expand Up @@ -217,14 +217,17 @@ void frameStep(float dt)
// End window
ImGui::End();

// Draw the individual shock in-scene windows
for (int i = 0; i < actor.getShockCount(); i++)
if (@actor != null)
{
SpringData@ shockdata = g_shock_buffers[i];
if (shockdata.drawInScene)
// Draw the individual shock in-scene windows
for (int i = 0; i < actor.getShockCount(); i++)
{
drawSpringHighlight(actor, i, cfgSpringColor, cfgSpringThickness);
drawSpringSceneHud(actor, i);
SpringData@ shockdata = g_shock_buffers[i];
if (shockdata.drawInScene)
{
drawSpringHighlight(actor, i, cfgSpringColor, cfgSpringThickness);
drawSpringSceneHud(actor, i);
}
}
}
}
Expand Down
130 changes: 78 additions & 52 deletions resources/scripts/example_ogre_overlays.as
Original file line number Diff line number Diff line change
Expand Up @@ -14,72 +14,98 @@
#include "imgui_utils.as"
imgui_utils::CloseWindowPrompt closeBtnHandler;

// overlay
string ovName = "ov"+thisScript;
bool ov_fail = false;

// panel
string paName = "pa"+thisScript;
bool pa_fail = false;
int paNumCreates = 0;
// misc
int framecounter = 0;
float pos_step = 50; // pixels

void frameStep(float dt)
{
Ogre::Overlay@ ov;
if (!ov_fail) {
// NOTE: getByName() will calmly return NULL if overlay doesn't exist.
@ov = Ogre::OverlayManager::getSingleton().getByName("ov");
// CAUTION: attempt to create the same overlay again will throw an exception, interrupting the script in between!
if (@ov == null) { @ov = Ogre::OverlayManager::getSingleton().create("ov"); }
if (@ov == null) { ov_fail = true; }
else { ov.show(); }
}

Ogre::OverlayElement@ pa;

if (!pa_fail ){
if ( Ogre::OverlayManager::getSingleton().hasOverlayElement("pa")) {

// CAUTION: getOverlayElement() will throw exception if not found, always do `hasOverlayElement()` first!
@pa = Ogre::OverlayManager::getSingleton().getOverlayElement("pa");
}
// CAUTION: using the same name twice will throw an exception, interrupting the script in between!
if (@pa == null ) { @pa = Ogre::OverlayManager::getSingleton().createOverlayElement("Panel", "pa");
if (@pa == null ) { pa_fail=true; }
else {
// game.log("adding pa to ov");
ov.add2D(pa);
pa.setMetricsMode(Ogre::GMM_PIXELS);
pa.setPosition(100,100);
pa.setDimensions(100,100);
pa.show();
}
}
pa.setMaterialName("tracks/wheelface", 'OgreAutodetect');
}

Ogre::Overlay@ ov;
if (!ov_fail)
{
// NOTE: getByName() will calmly return NULL if overlay doesn't exist.
@ov = Ogre::OverlayManager::getSingleton().getByName(ovName);
// CAUTION: attempt to create the same overlay again will throw an exception, interrupting the script in between!
if (@ov == null)
{
@ov = Ogre::OverlayManager::getSingleton().create(ovName);
}
if (@ov == null)
{
ov_fail = true;
}
else
{
ov.show();
}
}

Ogre::OverlayElement@ pa;

if (!pa_fail )
{
if ( Ogre::OverlayManager::getSingleton().hasOverlayElement(paName))
{
game.log('Looking for pa');
// CAUTION: getOverlayElement() will throw exception if not found, always do `hasOverlayElement()` first!
@pa = Ogre::OverlayManager::getSingleton().getOverlayElement(paName);

}
// CAUTION: using the same name twice will throw an exception, interrupting the script in between!
if (@pa == null )
{
@pa = Ogre::OverlayManager::getSingleton().createOverlayElement("Panel", paName);
paNumCreates++;
game.log('paNumCreates:'+paNumCreates);
if (@pa == null )
{
pa_fail=true;
}
else
{
// game.log("adding pa to ov");
ov.add2D(pa);
pa.setMetricsMode(Ogre::GMM_PIXELS);
pa.setPosition(100,100);
pa.setDimensions(100,100);
pa.setMaterialName("tracks/wheelface", 'OgreAutodetect');
pa.show();
}
}

}

if (ImGui::Begin("Example", closeBtnHandler.windowOpen, 0))
{
closeBtnHandler.draw();
ImGui::Text("overlays should work; ov_fail:"+ov_fail+", pa_fail:"+pa_fail
+", frames:"+framecounter);
ImGui::Text("overlays should work; ov_fail:"+ov_fail+", pa_fail:"+pa_fail +", frames:"+framecounter);
framecounter++;
if (!pa_fail && @pa != null)
{

ImGui::TextDisabled("The wheel overlay:");
if (ImGui::Button("Hide")) { pa.hide(); }
ImGui::SameLine(); if (ImGui::Button("Show")) { pa.show(); }

if (ImGui::Button("Position: Left+")) { pa.setLeft(pa.getLeft()+pos_step); }
ImGui::SameLine(); if (ImGui::Button("Position:left-")) { pa.setLeft(pa.getLeft()-pos_step); }

if (ImGui::Button("Position: Top+")) { pa.setTop(pa.getTop()+pos_step); }
ImGui::SameLine(); if (ImGui::Button("Position:Top-")) { pa.setTop(pa.getTop()-pos_step); }

if (ImGui::Button("Width+")) { pa.setWidth(pa.getWidth()+pos_step); }
ImGui::SameLine(); if (ImGui::Button("Width-")) { pa.setWidth(pa.getWidth()-pos_step); }

if (ImGui::Button("height+")) { pa.setHeight(pa.getHeight()+pos_step); }
ImGui::SameLine(); if (ImGui::Button("height-")) { pa.setHeight(pa.getHeight()-pos_step); }

if (ImGui::Button("Hide")) { pa.hide(); }
ImGui::SameLine(); if (ImGui::Button("Show")) { pa.show(); }
if (ImGui::Button("Position: Left+")) { pa.setLeft(pa.getLeft()+pos_step); }
ImGui::SameLine(); if (ImGui::Button("Position:left-")) { pa.setLeft(pa.getLeft()-pos_step); }
if (ImGui::Button("Position: Top+")) { pa.setTop(pa.getTop()+pos_step); }
ImGui::SameLine(); if (ImGui::Button("Position:Top-")) { pa.setTop(pa.getTop()-pos_step); }
if (ImGui::Button("Width+")) { pa.setWidth(pa.getWidth()+pos_step); }
ImGui::SameLine(); if (ImGui::Button("Width-")) { pa.setWidth(pa.getWidth()-pos_step); }
if (ImGui::Button("height+")) { pa.setHeight(pa.getHeight()+pos_step); }
ImGui::SameLine(); if (ImGui::Button("height-")) { pa.setHeight(pa.getHeight()-pos_step); }
}
ImGui::End();
}
Expand Down
2 changes: 1 addition & 1 deletion resources/scripts/example_ogre_terrnBatcher.as
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ void main()

void frameStep(float dt)
{
if (ImGui::Begin("TERRN BATCHER [ALPHA]", closeBtnHandler.draw(), ImGuiWindowFlags_AlwaysAutoResize))
if (ImGui::Begin("TERRN BATCHER [ALPHA]", closeBtnHandler.windowOpen, ImGuiWindowFlags_AlwaysAutoResize))
{
closeBtnHandler.draw();
tbUI.draw();
Expand Down

0 comments on commit 65c1baa

Please sign in to comment.