Skip to content

Commit

Permalink
[v2.1] Add Play Sound Button Function (#3)
Browse files Browse the repository at this point in the history
- Added "Play Sound from Speaker(s)" function to all buttons.
- Added new "[ Sounds ]" folder w/ sample announcements to use with this function.
- Updated the demo park to showcase the new function and sounds.
- Updated the README to include information on Speaker compatibility.
- Updated the LICENSE to have the correct year.
- Fixed typos & slightly reduced memory usage in the code.
  • Loading branch information
lilkingjr1 committed Jun 8, 2024
1 parent 3895b52 commit c4c34b7
Show file tree
Hide file tree
Showing 21 changed files with 255 additions and 33 deletions.
Binary file modified Reds-Panels-and-Operators.nl2park
Binary file not shown.
6 changes: 3 additions & 3 deletions scenery/reds_panels_and_operators/LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Red's Panels & Operators is a No Limits 2 Roller Coaster Simulator (NL2)
custom scenery object (SCO) package of various panels, operators, etc for use in the NL2 software.
Copyright (c) 2021 David Wolfe (Red-Thirten)
Copyright (c) 2024 David Wolfe (Red-Thirten)


GNU GENERAL PUBLIC LICENSE
Expand Down Expand Up @@ -638,7 +638,7 @@ the "copyright" line and a pointer to where the full notice is found.

Red's Panels & Operators is a No Limits 2 Roller Coaster Simulator (NL2)
custom scenery object (SCO) package of various panels, operators, etc for use in the NL2 software.
Copyright (c) 2021 David Wolfe (Red-Thirten)
Copyright (c) 2024 David Wolfe (Red-Thirten)

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
Expand All @@ -659,7 +659,7 @@ Also add information on how to contact you by electronic and paper mail.
notice like this when it starts in an interactive mode:

Red's Panels & Operators
Copyright (c) 2021 David Wolfe (Red-Thirten)
Copyright (c) 2024 David Wolfe (Red-Thirten)
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
Expand Down
16 changes: 15 additions & 1 deletion scenery/reds_panels_and_operators/Push Button (Flat).nl2sco
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
<scriptparameter>
<type>int</type>
<defaultvalue>0</defaultvalue>
<enums>None,Block Advance,Block Reverse,Station Dispatch,Restraints Open,Restraints Lock,Platform Raise,Platform Lower,Platform Toggle,Flyer Seats Unlock,Flyer Seats Lock,Flyer Seats Toggle,Special Track Left,Special Track Right,Auto Dispatch,Manual Dispatch,Automatic Operation,Manual Block Operation,Full Manual Operation,E-Stop Reset,Lift Jog (No Interaction),Brake Release (No Interaction)</enums>
<enums>None,Block Advance,Block Reverse,Station Dispatch,Restraints Open,Restraints Lock,Platform Raise,Platform Lower,Platform Toggle,Flyer Seats Unlock,Flyer Seats Lock,Flyer Seats Toggle,Special Track Left,Special Track Right,Auto Dispatch,Manual Dispatch,Automatic Operation,Manual Block Operation,Full Manual Operation,E-Stop Reset,Lift Jog (No Interaction),Brake Release (No Interaction),Play Sound from Speaker(s)</enums>
<id>function</id>
<description>How this button will behave during Play Mode.</description>
<label>Function:</label>
Expand All @@ -59,6 +59,20 @@
<description>This is the Special Track that this operator will control. Required for the Special Track Functions.</description>
<label>Special Track (for Special Track Functions):</label>
</scriptparameter>
<scriptparameter>
<type>string</type>
<defaultvalue></defaultvalue>
<id>speakers_sco_name</id>
<description>Name that matches the name of one or more SCO instances that will act as a speaker to play the sound. Any SCO can be used, but Red&apos;s Speakers are preferred (see README for details).</description>
<label>Speaker(s) SCO Name (for Play Sound Function):</label>
</scriptparameter>
<scriptparameter>
<type filetype="audio">resourcepath</type>
<defaultvalue></defaultvalue>
<id>play_sound</id>
<description>Sound file to play on all configured speakers when the button is pushed.</description>
<label>Speaker Sound (for Play Sound Function):</label>
</scriptparameter>
<scriptparameter>
<type>specialtrack</type>
<id>special_track_attach</id>
Expand Down
16 changes: 15 additions & 1 deletion scenery/reds_panels_and_operators/Push Button (Mushroom).nl2sco
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
<scriptparameter>
<type>int</type>
<defaultvalue>0</defaultvalue>
<enums>None (Light Off),None (Light On),None (Light Blinking),Block Advance,Block Reverse,Station Dispatch,Restraints Open,Restraints Lock,Platform Raise,Platform Lower,Platform Toggle,Flyer Seats Unlock,Flyer Seats Lock,Flyer Seats Toggle,Special Track Left,Special Track Right,Auto Dispatch,Manual Dispatch,Automatic Operation,Manual Block Operation,Full Manual Operation,E-Stop Reset,Lift Jog (No Interaction),Brake Release (No Interaction)</enums>
<enums>None (Light Off),None (Light On),None (Light Blinking),Block Advance,Block Reverse,Station Dispatch,Restraints Open,Restraints Lock,Platform Raise,Platform Lower,Platform Toggle,Flyer Seats Unlock,Flyer Seats Lock,Flyer Seats Toggle,Special Track Left,Special Track Right,Auto Dispatch,Manual Dispatch,Automatic Operation,Manual Block Operation,Full Manual Operation,E-Stop Reset,Lift Jog (No Interaction),Brake Release (No Interaction),Play Sound from Speaker(s)</enums>
<id>function</id>
<description>How this button will behave during Play Mode.</description>
<label>Function:</label>
Expand All @@ -60,6 +60,20 @@
<description>This is the Special Track that this operator will control. Required for the Special Track Functions.</description>
<label>Special Track (for Special Track Functions):</label>
</scriptparameter>
<scriptparameter>
<type>string</type>
<defaultvalue></defaultvalue>
<id>speakers_sco_name</id>
<description>Name that matches the name of one or more SCO instances that will act as a speaker to play the sound. Any SCO can be used, but Red&apos;s Speakers are preferred (see README for details).</description>
<label>Speaker(s) SCO Name (for Play Sound Function):</label>
</scriptparameter>
<scriptparameter>
<type filetype="audio">resourcepath</type>
<defaultvalue></defaultvalue>
<id>play_sound</id>
<description>Sound file to play on all configured speakers when the button is pushed.</description>
<label>Speaker Sound (for Play Sound Function):</label>
</scriptparameter>
<scriptparameter>
<type>specialtrack</type>
<id>special_track_attach</id>
Expand Down
16 changes: 15 additions & 1 deletion scenery/reds_panels_and_operators/Push Button (Shielded).nl2sco
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
<scriptparameter>
<type>int</type>
<defaultvalue>0</defaultvalue>
<enums>None (Light Off),None (Light On),None (Light Blinking),Block Advance,Block Reverse,Station Dispatch,Restraints Open,Restraints Lock,Platform Raise,Platform Lower,Platform Toggle,Flyer Seats Unlock,Flyer Seats Lock,Flyer Seats Toggle,Special Track Left,Special Track Right,Auto Dispatch,Manual Dispatch,Automatic Operation,Manual Block Operation,Full Manual Operation,E-Stop Reset,Lift Jog (No Interaction),Brake Release (No Interaction)</enums>
<enums>None (Light Off),None (Light On),None (Light Blinking),Block Advance,Block Reverse,Station Dispatch,Restraints Open,Restraints Lock,Platform Raise,Platform Lower,Platform Toggle,Flyer Seats Unlock,Flyer Seats Lock,Flyer Seats Toggle,Special Track Left,Special Track Right,Auto Dispatch,Manual Dispatch,Automatic Operation,Manual Block Operation,Full Manual Operation,E-Stop Reset,Lift Jog (No Interaction),Brake Release (No Interaction),Play Sound from Speaker(s)</enums>
<id>function</id>
<description>How this button will behave during Play Mode.</description>
<label>Function:</label>
Expand All @@ -60,6 +60,20 @@
<description>This is the Special Track that this operator will control. Required for the Special Track Functions.</description>
<label>Special Track (for Special Track Functions):</label>
</scriptparameter>
<scriptparameter>
<type>string</type>
<defaultvalue></defaultvalue>
<id>speakers_sco_name</id>
<description>Name that matches the name of one or more SCO instances that will act as a speaker to play the sound. Any SCO can be used, but Red&apos;s Speakers are preferred (see README for details).</description>
<label>Speaker(s) SCO Name (for Play Sound Function):</label>
</scriptparameter>
<scriptparameter>
<type filetype="audio">resourcepath</type>
<defaultvalue></defaultvalue>
<id>play_sound</id>
<description>Sound file to play on all configured speakers when the button is pushed.</description>
<label>Speaker Sound (for Play Sound Function):</label>
</scriptparameter>
<scriptparameter>
<type>specialtrack</type>
<id>special_track_attach</id>
Expand Down
16 changes: 15 additions & 1 deletion scenery/reds_panels_and_operators/Push Button.nl2sco
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
<scriptparameter>
<type>int</type>
<defaultvalue>0</defaultvalue>
<enums>None (Light Off),None (Light On),None (Light Blinking),Block Advance,Block Reverse,Station Dispatch,Restraints Open,Restraints Lock,Platform Raise,Platform Lower,Platform Toggle,Flyer Seats Unlock,Flyer Seats Lock,Flyer Seats Toggle,Special Track Left,Special Track Right,Auto Dispatch,Manual Dispatch,Automatic Operation,Manual Block Operation,Full Manual Operation,E-Stop Reset,Lift Jog (No Interaction),Brake Release (No Interaction)</enums>
<enums>None (Light Off),None (Light On),None (Light Blinking),Block Advance,Block Reverse,Station Dispatch,Restraints Open,Restraints Lock,Platform Raise,Platform Lower,Platform Toggle,Flyer Seats Unlock,Flyer Seats Lock,Flyer Seats Toggle,Special Track Left,Special Track Right,Auto Dispatch,Manual Dispatch,Automatic Operation,Manual Block Operation,Full Manual Operation,E-Stop Reset,Lift Jog (No Interaction),Brake Release (No Interaction),Play Sound from Speaker(s)</enums>
<id>function</id>
<description>How this button will behave during Play Mode.</description>
<label>Function:</label>
Expand All @@ -60,6 +60,20 @@
<description>This is the Special Track that this operator will control. Required for the Special Track Functions.</description>
<label>Special Track (for Special Track Functions):</label>
</scriptparameter>
<scriptparameter>
<type>string</type>
<defaultvalue></defaultvalue>
<id>speakers_sco_name</id>
<description>Name that matches the name of one or more SCO instances that will act as a speaker to play the sound. Any SCO can be used, but Red&apos;s Speakers are preferred (see README for details).</description>
<label>Speaker(s) SCO Name (for Play Sound Function):</label>
</scriptparameter>
<scriptparameter>
<type filetype="audio">resourcepath</type>
<defaultvalue></defaultvalue>
<id>play_sound</id>
<description>Sound file to play on all configured speakers when the button is pushed.</description>
<label>Speaker Sound (for Play Sound Function):</label>
</scriptparameter>
<scriptparameter>
<type>specialtrack</type>
<id>special_track_attach</id>
Expand Down
37 changes: 35 additions & 2 deletions scenery/reds_panels_and_operators/README.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ <h4><i>
Red's Panels &amp; Operators<br>
©2024 David W. (Red-Thirten)<br>
<a href="mailto:red_thirten@yahoo.com">red_thirten@yahoo.com</a><br>
Version 2.0, 15 March 2024<br>
Version 2.1, 06 June 2024<br>
NL2 Scenery Custom Object (SCO) Package<br>
</h4></i>
<p>
Expand Down Expand Up @@ -55,11 +55,39 @@ <h3>
</ol>
<ul><li>As a final note, it might be good to not delete your original "master" panels until you are completed with your build, just in case you need another copy or you want to modify it. Modifying already moved / rotated panels is a <em>pain</em>!!!</li></ul>
<hr>
<h3>
<u>"Play Sound" Button Function - Speaker Compatibility:</u>
</h3>
<h4><a href="https://github.com/lilkingjr1/Reds-Speakers">Red's Speakers</a> Pack:</h4>
<ul>
<li>This pack of speakers is recommended for use with this button function.</li>
<li>The location of the sound will be correct and aligned with the speaker.</li>
<li>You can edit various parameters of the speaker to adjust the sound, including:</li>
<ul>
<li>Gain (Volume)</li>
<li>Range</li>
<li>Falloff</li>
<li>and Pitch</li>
</ul>
</ul>
<h4>Any SCO:</h4>
<ul>
<li>Any SCO can technically be used as a "speaker".</li>
<li>The sound will play from the SCO's origin (wherever that is).</li>
<li>Default parameters will be used for sound properties (like Gain, etc.), and they cannot be changed.</li>
</ul>
<h4>Custom Tailored SCOs:</h4>
<ul>
<li>If you would like to create a custom speaker, you can do so easily.</li>
<li>The SCO's 3D object should have an element named "speaker". The sound will play from the origin of this element.</li>
<li>The SCO should have 4 float script parameters, named: "gain", "range", "falloff", and "pitch". These respective properties will be honored if present.</li>
</ul>
<hr>
<h3>
<u>Known Issues:</u>
</h3>
<ul style="line-height: 1.5;">
<li>"Auto-alignment" via coordinates doesn't work for Main Panels, because they are at an angle. The best practice, in my opinion, is to align one operator by hand, and then copy it's coordinates to other operators you want to add, and adjust from there. This makes aligning any additional operators much easier.</li>
<li>"Auto-alignment" via coordinates doesn't work for Main Panels, because they are at an angle. The best practice is to align one operator by hand and then copy it's coordinates to other operators you want to add, and adjust from there. This makes aligning any additional operators much easier.</li>
<li>"Trains in Service" Mode for Key Switch operators will display the key animation when it shouldn't the first time the ride is put into "Manual Block" Mode. I'm not really sure how to fix this, because it seems like NL2 is miscalculating the number of lashed trains upon entering "Manual Block" Mode for the first time.</li>
<li>A LOT of stuff was copy and pasted from object to object. PLEASE let me know if there are any typos or if settings/options are mislabeled.</li>
</ul>
Expand All @@ -68,6 +96,11 @@ <h3>
<u>Change Log:</u>
</h3>
<ul>
<li>[v2.1] Add Play Sound Button Function
<ul>
<li><a href="https://github.com/lilkingjr1/Reds-Panels-and-Operators/releases/tag/v2.1">Change List</a></li>
</ul>
</li>
<li>[v2.0] Operator Interactions, Lights, & Sounds Update
<ul>
<li><a href="https://github.com/lilkingjr1/Reds-Panels-and-Operators/releases/tag/v2.0">Change List</a></li>
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
69 changes: 56 additions & 13 deletions scenery/reds_panels_and_operators/scripts/PushButton.nlvm
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
Push Button NL2 Script
David Wolfe (Red-Thirten)
03/18/2024
06/06/2024
Animates the pilot light and button during run time, based on user settings.
Licensed under GNU GPLv3 - See LICENSE for more details.
*/
Expand All @@ -19,6 +19,7 @@ import com.nolimitscoaster.ResourcePath;

import obj.OperatorButton;
import obj.IndicatorLight;
import obj.Speakers;
import util.Logger;
import util.SceneObjectTools;
import util.CoasterTools;
Expand Down Expand Up @@ -63,8 +64,10 @@ public class PushButton extends Script implements InteractionActionListener{
protected static final int F_ESTOP_RESET = 21;
protected static final int F_LIFT_JOG_NO_INT = 22;
protected static final int F_BRAKE_RELEASE_NO_INT = 23;
protected static final int F_ESTOP_SIMPLE = 24;
protected static final int F_ESTOP_ADVANCED = 25;
protected static final int F_PLAY_SOUND = 24;
// E-Stop Specific Functions at End
protected static final int F_ESTOP_SIMPLE = 25;
protected static final int F_ESTOP_ADVANCED = 26;
private static final int[] NON_INTERACT_MODES = {
F_LIFT_JOG_NO_INT,
F_BRAKE_RELEASE_NO_INT
Expand All @@ -77,10 +80,10 @@ public class PushButton extends Script implements InteractionActionListener{
private InteractionObject iObj;
private SceneObjectLight plcLight;

private Logger log;
private OperatorButton button;
private SpecialTrackModule specialTrackModule;
private IndicatorLight plcIndicatorLight;
private Speakers speakers;

private int func = F_STATIC_OFF;
private int frameCounter = 5; // Stupid workaround for Dispatch Function where NL2 bug can sometimes report moving train speed as 0
Expand All @@ -96,7 +99,7 @@ public class PushButton extends Script implements InteractionActionListener{
);

// Setup Logger
log = new Logger(SCRIPT_NAME, sco.getName());
Logger log = new Logger(SCRIPT_NAME, sco.getName());

// Hide placard if configured
if ( sco.getBooleanParameter("hide_placard").boolValue() ){
Expand All @@ -110,9 +113,9 @@ public class PushButton extends Script implements InteractionActionListener{

// Get configured function and required parameters
func = getFuncFromScoParams(sco);
if (func > F_STATIC_BLINK){ // If not static function
if (func > F_STATIC_BLINK && func != F_PLAY_SOUND){ // If not static or Play Sound functions
block = sco.getBlockParameter("block");
if (block == null){ // Check for unconfigured block
if (block == null){ // Check for un-configured block
log.err("Block parameter required for any non-static functions.");
return false;
}
Expand Down Expand Up @@ -207,6 +210,25 @@ public class PushButton extends Script implements InteractionActionListener{
return false;
}
break;
// Functions that require a speaker
case F_PLAY_SOUND:
ResourcePath soundResource = sco.getResourcePathParameter("play_sound");
if (soundResource == null){
log.err("The configured function requires the Sound parameter to be specified.");
return false;
}
String speakersScoName = sco.getStringParameter("speakers_sco_name");
if (speakersScoName.length() < 1){
log.err("The configured function requires the Speaker(s) SCO Name parameter to be specified.");
return false;
}
SceneObject[] speakerSCOS = sim.getSceneObjectsWithName(speakersScoName);
if (speakerSCOS.length < 1){
log.err("No SCO(s) with the instance name of \"" + speakersScoName + "\" could be found.");
return false;
}
speakers = new Speakers(speakerSCOS, soundResource);
break;
}

// Check for platform (if applicable)
Expand Down Expand Up @@ -265,8 +287,8 @@ public class PushButton extends Script implements InteractionActionListener{
);
}

// Setup InteractionObject (if interactible function)
if (isInteractibleFunc(func)){
// Setup InteractionObject (if interactable function)
if (isInteractableFunc(func)){
iObj = InteractionObject.createSimpleButton();
iObj.setPosition(button.getAbsoluteTranslation());
iObj.setRadius(BUTTON_INTERACTION_RADIUS);
Expand All @@ -287,7 +309,7 @@ public class PushButton extends Script implements InteractionActionListener{
return sco.getIntegerParameter("function").intValue();
}

private bool isInteractibleFunc(int func){
private bool isInteractableFunc(int func){
for (int i = 0; i < NON_INTERACT_MODES.length; i++){
if (func == NON_INTERACT_MODES[i])
return false;
Expand All @@ -314,7 +336,7 @@ public class PushButton extends Script implements InteractionActionListener{
}
}

// Interactible Functions //
// Interactable Functions //

private void handleStaticFunc(bool action){
if (action){
Expand Down Expand Up @@ -347,7 +369,7 @@ public class PushButton extends Script implements InteractionActionListener{
// Can Semi-Manual move
else{
enableAction();
button.setLightState(block.LAMP_FLASHING);
button.setLightState(Block.LAMP_FLASHING);
}
}

Expand Down Expand Up @@ -596,6 +618,24 @@ public class PushButton extends Script implements InteractionActionListener{
button.lightOff();
}
}

private void handlePlaySoundFunc(bool action){
if (action){
button.buttonPush();
speakers.play();
return;
}

if (button.isAnimating()){
disableAction();
button.lightOn();
}
else{
enableAction();
button.lightOff();
}
speakers.updateTranslation();
}

// E-Stop Functions //

Expand Down Expand Up @@ -663,7 +703,7 @@ public class PushButton extends Script implements InteractionActionListener{
}
}

// Non-Interactible Functions //
// Non-Interactable Functions //

private void handleLiftJogFunc(){
if (coaster.getBlockSystemMode() != Coaster.E_BLOCK_SYSTEM_MODE_FULL_MANUAL || coaster.isEmergencyStop()){
Expand Down Expand Up @@ -751,6 +791,9 @@ public class PushButton extends Script implements InteractionActionListener{
case F_BRAKE_RELEASE_NO_INT:
handleManualBrakeReleaseFunc();
break;
case F_PLAY_SOUND:
handlePlaySoundFunc(action);
break;
default:
handleStaticFunc(action);
}
Expand Down
Loading

0 comments on commit c4c34b7

Please sign in to comment.