Skip to content

Commit 65c1baa

Browse files
committed
👼Script: Minor bugfixes and formatting in scripts.
1 parent afd3f44 commit 65c1baa

5 files changed

+91
-62
lines changed

resources/scripts/example_GenericDocument_editor.as

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ void frameStep(float dt)
2525
if (@actor != null)
2626
{
2727
CacheEntryClass@ entry = modcache.findEntryByFilename(LOADER_TYPE_ALLBEAM, /*partial:*/false, actor.getTruckFileName());
28-
if (@entry != null)
28+
if (@entry != null && entry.resource_bundle_type == "FileSystem")
2929
{
3030
@projectEntry = @entry;
3131
loadDocument();
@@ -111,7 +111,7 @@ void createProjectFromActorAsync(BeamClass@ actor )
111111
errorString = "Failed to load cache entry!";
112112

113113
// request project to be created from that cache entry
114-
string proj_name = "project1";
114+
string proj_name = "gd_editor_" + src_entry.fname;
115115
game.pushMessage(MSG_EDI_CREATE_PROJECT_REQUESTED, {
116116
{'name', proj_name},
117117
{'source_entry', src_entry}

resources/scripts/example_RigEditor_alpha.as

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ void frameStep(float dt)
5353
if (@actor != null)
5454
{
5555
CacheEntryClass@ entry = modcache.findEntryByFilename(LOADER_TYPE_ALLBEAM, /*partial:*/false, actor.getTruckFileName());
56-
if (@entry != null)
56+
if (@entry != null && entry.resource_bundle_type == "FileSystem")
5757
{
5858
@m_project_entry = @entry;
5959
loadDocument();

resources/scripts/example_game_shockTuning.as

+9-6
Original file line numberDiff line numberDiff line change
@@ -217,14 +217,17 @@ void frameStep(float dt)
217217
// End window
218218
ImGui::End();
219219

220-
// Draw the individual shock in-scene windows
221-
for (int i = 0; i < actor.getShockCount(); i++)
220+
if (@actor != null)
222221
{
223-
SpringData@ shockdata = g_shock_buffers[i];
224-
if (shockdata.drawInScene)
222+
// Draw the individual shock in-scene windows
223+
for (int i = 0; i < actor.getShockCount(); i++)
225224
{
226-
drawSpringHighlight(actor, i, cfgSpringColor, cfgSpringThickness);
227-
drawSpringSceneHud(actor, i);
225+
SpringData@ shockdata = g_shock_buffers[i];
226+
if (shockdata.drawInScene)
227+
{
228+
drawSpringHighlight(actor, i, cfgSpringColor, cfgSpringThickness);
229+
drawSpringSceneHud(actor, i);
230+
}
228231
}
229232
}
230233
}

resources/scripts/example_ogre_overlays.as

+78-52
Original file line numberDiff line numberDiff line change
@@ -14,72 +14,98 @@
1414
#include "imgui_utils.as"
1515
imgui_utils::CloseWindowPrompt closeBtnHandler;
1616

17+
// overlay
18+
string ovName = "ov"+thisScript;
1719
bool ov_fail = false;
18-
20+
// panel
21+
string paName = "pa"+thisScript;
1922
bool pa_fail = false;
23+
int paNumCreates = 0;
24+
// misc
2025
int framecounter = 0;
2126
float pos_step = 50; // pixels
2227

2328
void frameStep(float dt)
2429
{
25-
Ogre::Overlay@ ov;
26-
if (!ov_fail) {
27-
// NOTE: getByName() will calmly return NULL if overlay doesn't exist.
28-
@ov = Ogre::OverlayManager::getSingleton().getByName("ov");
29-
// CAUTION: attempt to create the same overlay again will throw an exception, interrupting the script in between!
30-
if (@ov == null) { @ov = Ogre::OverlayManager::getSingleton().create("ov"); }
31-
if (@ov == null) { ov_fail = true; }
32-
else { ov.show(); }
33-
}
34-
35-
Ogre::OverlayElement@ pa;
36-
37-
if (!pa_fail ){
38-
if ( Ogre::OverlayManager::getSingleton().hasOverlayElement("pa")) {
39-
40-
// CAUTION: getOverlayElement() will throw exception if not found, always do `hasOverlayElement()` first!
41-
@pa = Ogre::OverlayManager::getSingleton().getOverlayElement("pa");
42-
}
43-
// CAUTION: using the same name twice will throw an exception, interrupting the script in between!
44-
if (@pa == null ) { @pa = Ogre::OverlayManager::getSingleton().createOverlayElement("Panel", "pa");
45-
if (@pa == null ) { pa_fail=true; }
46-
else {
47-
// game.log("adding pa to ov");
48-
ov.add2D(pa);
49-
pa.setMetricsMode(Ogre::GMM_PIXELS);
50-
pa.setPosition(100,100);
51-
pa.setDimensions(100,100);
52-
pa.show();
53-
}
54-
}
55-
pa.setMaterialName("tracks/wheelface", 'OgreAutodetect');
56-
}
57-
30+
Ogre::Overlay@ ov;
31+
if (!ov_fail)
32+
{
33+
// NOTE: getByName() will calmly return NULL if overlay doesn't exist.
34+
@ov = Ogre::OverlayManager::getSingleton().getByName(ovName);
35+
// CAUTION: attempt to create the same overlay again will throw an exception, interrupting the script in between!
36+
if (@ov == null)
37+
{
38+
@ov = Ogre::OverlayManager::getSingleton().create(ovName);
39+
}
40+
if (@ov == null)
41+
{
42+
ov_fail = true;
43+
}
44+
else
45+
{
46+
ov.show();
47+
}
48+
}
49+
50+
Ogre::OverlayElement@ pa;
51+
52+
if (!pa_fail )
53+
{
54+
if ( Ogre::OverlayManager::getSingleton().hasOverlayElement(paName))
55+
{
56+
game.log('Looking for pa');
57+
// CAUTION: getOverlayElement() will throw exception if not found, always do `hasOverlayElement()` first!
58+
@pa = Ogre::OverlayManager::getSingleton().getOverlayElement(paName);
59+
60+
}
61+
// CAUTION: using the same name twice will throw an exception, interrupting the script in between!
62+
if (@pa == null )
63+
{
64+
@pa = Ogre::OverlayManager::getSingleton().createOverlayElement("Panel", paName);
65+
paNumCreates++;
66+
game.log('paNumCreates:'+paNumCreates);
67+
if (@pa == null )
68+
{
69+
pa_fail=true;
70+
}
71+
else
72+
{
73+
// game.log("adding pa to ov");
74+
ov.add2D(pa);
75+
pa.setMetricsMode(Ogre::GMM_PIXELS);
76+
pa.setPosition(100,100);
77+
pa.setDimensions(100,100);
78+
pa.setMaterialName("tracks/wheelface", 'OgreAutodetect');
79+
pa.show();
80+
}
81+
}
82+
83+
}
84+
5885
if (ImGui::Begin("Example", closeBtnHandler.windowOpen, 0))
5986
{
6087
closeBtnHandler.draw();
61-
ImGui::Text("overlays should work; ov_fail:"+ov_fail+", pa_fail:"+pa_fail
62-
+", frames:"+framecounter);
88+
ImGui::Text("overlays should work; ov_fail:"+ov_fail+", pa_fail:"+pa_fail +", frames:"+framecounter);
6389
framecounter++;
6490
if (!pa_fail && @pa != null)
6591
{
66-
92+
6793
ImGui::TextDisabled("The wheel overlay:");
68-
if (ImGui::Button("Hide")) { pa.hide(); }
69-
ImGui::SameLine(); if (ImGui::Button("Show")) { pa.show(); }
70-
71-
if (ImGui::Button("Position: Left+")) { pa.setLeft(pa.getLeft()+pos_step); }
72-
ImGui::SameLine(); if (ImGui::Button("Position:left-")) { pa.setLeft(pa.getLeft()-pos_step); }
73-
74-
if (ImGui::Button("Position: Top+")) { pa.setTop(pa.getTop()+pos_step); }
75-
ImGui::SameLine(); if (ImGui::Button("Position:Top-")) { pa.setTop(pa.getTop()-pos_step); }
76-
77-
if (ImGui::Button("Width+")) { pa.setWidth(pa.getWidth()+pos_step); }
78-
ImGui::SameLine(); if (ImGui::Button("Width-")) { pa.setWidth(pa.getWidth()-pos_step); }
79-
80-
if (ImGui::Button("height+")) { pa.setHeight(pa.getHeight()+pos_step); }
81-
ImGui::SameLine(); if (ImGui::Button("height-")) { pa.setHeight(pa.getHeight()-pos_step); }
82-
94+
if (ImGui::Button("Hide")) { pa.hide(); }
95+
ImGui::SameLine(); if (ImGui::Button("Show")) { pa.show(); }
96+
97+
if (ImGui::Button("Position: Left+")) { pa.setLeft(pa.getLeft()+pos_step); }
98+
ImGui::SameLine(); if (ImGui::Button("Position:left-")) { pa.setLeft(pa.getLeft()-pos_step); }
99+
100+
if (ImGui::Button("Position: Top+")) { pa.setTop(pa.getTop()+pos_step); }
101+
ImGui::SameLine(); if (ImGui::Button("Position:Top-")) { pa.setTop(pa.getTop()-pos_step); }
102+
103+
if (ImGui::Button("Width+")) { pa.setWidth(pa.getWidth()+pos_step); }
104+
ImGui::SameLine(); if (ImGui::Button("Width-")) { pa.setWidth(pa.getWidth()-pos_step); }
105+
106+
if (ImGui::Button("height+")) { pa.setHeight(pa.getHeight()+pos_step); }
107+
ImGui::SameLine(); if (ImGui::Button("height-")) { pa.setHeight(pa.getHeight()-pos_step); }
108+
83109
}
84110
ImGui::End();
85111
}

resources/scripts/example_ogre_terrnBatcher.as

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ void main()
2727

2828
void frameStep(float dt)
2929
{
30-
if (ImGui::Begin("TERRN BATCHER [ALPHA]", closeBtnHandler.draw(), ImGuiWindowFlags_AlwaysAutoResize))
30+
if (ImGui::Begin("TERRN BATCHER [ALPHA]", closeBtnHandler.windowOpen, ImGuiWindowFlags_AlwaysAutoResize))
3131
{
3232
closeBtnHandler.draw();
3333
tbUI.draw();

0 commit comments

Comments
 (0)