Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions build/api.json
Original file line number Diff line number Diff line change
Expand Up @@ -258,13 +258,17 @@
"libraries": [
"com.nolimitscoaster",
"nlvm.math3d",
"nlvm.util",
"scripts.containers",
"scripts.math"
],
"accessor": "public abstract",
"name": "Behaviour",
"full_name": "scripts.Behaviour",
"extends": "Script",
"implements": [
"IPropertyContainer"
],
"description": "Base class to derrive any SceneObject attached scripts.",
"members": [
{
Expand Down Expand Up @@ -385,6 +389,28 @@
"return_desc": "No Description Supplied.",
"description": "Gets the current world-space position of the player."
},
{
"args": [
{
"type": "bool",
"name": "isVisible",
"description": "True to show model, otherwise False to hide it."
}
],
"name": "SetIsVisible",
"return": "void",
"accessor": "public final",
"return_desc": "No Description Supplied.",
"description": "Sets the Behaviours model to be visible."
},
{
"args": [],
"name": "GetIsVisible",
"return": "bool",
"accessor": "public final",
"return_desc": "True if it is visible, otherwise False if its hidden.",
"description": "Gets the current Behaviours visibility."
},
{
"args": [],
"name": "GetPosition",
Expand All @@ -407,6 +433,28 @@
"return_desc": "No Description Supplied.",
"description": "Sets this Behaviour's world-space position."
},
{
"args": [],
"name": "GetRotation",
"return": "Vector3",
"accessor": "public final",
"return_desc": "No Description Supplied.",
"description": "Gets this Behaviour's world-space rotation."
},
{
"args": [
{
"type": "Vector3",
"name": "rotation",
"description": "The world-space rotation to set."
}
],
"name": "SetRotation",
"return": "void",
"accessor": "public final",
"return_desc": "No Description Supplied.",
"description": "Sets this Behaviour's world-space rotation."
},
{
"args": [],
"name": "GetScale",
Expand Down
24 changes: 16 additions & 8 deletions scripts/Behaviour.nlvm
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package scripts;

import com.nolimitscoaster.*;
import nlvm.math3d.*;
import nlvm.util.*;

import scripts.containers.*;
import scripts.math.*;
Expand Down Expand Up @@ -342,20 +343,27 @@ public abstract class Behaviour extends Script implements IPropertyContainer
if(!IsPropertyValid(id))
Exception.Throw("There is no property '" + id + "' on this instance");

int myVar = 0;
switch(myVar)
{
case POSITION:
break;
}

return new BehaviourPropertyHandler(this, id);
}



private HashMap m_SubElementHash = new HashMap();
public SubElement GetChild(String name)
{
if(m_SubElementHash.containsKey(name))
return (SubElement)m_SubElementHash.get(name);


SubElement child = new SubElement(this, m_SceneObject.getElementForName(name));
m_SubElementHash.put(name, child);
return child;
}
public SubElement GetChild(int index)
{
SceneObjectElement internChild = m_SceneObject.getElementAt(index);
String name = internChild.getName();
return GetChild(name);
}



Expand Down
180 changes: 180 additions & 0 deletions scripts/Door.nlvm
Original file line number Diff line number Diff line change
@@ -0,0 +1,180 @@
package scripts;

import com.nolimitscoaster.*;
import scripts.delegates.*;

public abstract class Door extends Behaviour implements InteractionActionListener, IReferenceable
{
private Delegate1 m_DoorOpenDelegate = null;
private Delegate1 m_DoorCloseDelegate = null;
private Delegate1 m_DoorStateChangeDelegate = null;

public static final int DOOR_CLOSED = 0;
public static final int DOOR_OPENING = 1;
public static final int DOOR_OPEN = 2;
public static final int DOOR_CLOSING = 3;
private int m_DoorState = DOOR_CLOSED;

protected DoorConfig m_Config;
private float m_CurrTime = 0;

protected InteractionObject[] m_InteractionHandle = new InteractionObject[0];

private String m_DoorId = "";
protected ResourcePath m_DoorConfigResource = null;

public int GetOrder() { return -5; }
public final bool Awake()
{
m_DoorId = GetStringParameter("door_id");
m_DoorConfigResource = GetResourcePathParameter("door_config");
Json configJson = Json.Parse(Tools.loadTextFileFromResource(m_DoorConfigResource));

m_Config = new DoorConfig();
m_Config.OpenTime = configJson.Get("open_time").GetFloat();
m_Config.CloseTime = configJson.Get("close_time").GetFloat();

m_DoorOpenDelegate = new Delegate1();
m_DoorCloseDelegate = new Delegate1();
m_DoorStateChangeDelegate = new Delegate1();

SetupDoor();
Registry.GetInstance().Register(this);

return true;
}

protected abstract void SetupDoor();
protected abstract void UpdateDoor();

public final void Update(float tick)
{
switch(m_DoorState)
{
case DOOR_CLOSED:
case DOOR_OPEN:
break;
case DOOR_OPENING:
m_CurrTime += tick;
if(m_CurrTime >= m_Config.OpenTime)
{
m_DoorState = DOOR_OPEN;
SetInteractionHandlesEnabled(true);
InvokeDoorOpen();
m_CurrTime = 0;
}
break;
case DOOR_CLOSING:
m_CurrTime += tick;
if(m_CurrTime >= m_Config.CloseTime)
{
m_DoorState = DOOR_CLOSED;
SetInteractionHandlesEnabled(true);
InvokeDoorClose();
m_CurrTime = 0;
}
break;
}
UpdateDoor();
}
public final void LateUpdate(float tick) { }
public final void LateUnblockedUpdate() { }

public void onInteractionAction(InteractionObject action)
{
bool foundMatch = false;
for(int i = 0; i < m_InteractionHandle.length; ++i)
{
if(m_InteractionHandle[i] == action)
{
foundMatch = true;
break;
}
}
if(!foundMatch)
return;

if(m_DoorState == DOOR_OPEN)
Close();
else if(m_DoorState == DOOR_CLOSED)
Open();
}


protected void SetInteractionHandlesEnabled(bool enabled)
{
for(int i = 0; i < m_InteractionHandle.length; ++i)
m_InteractionHandle[i].setEnabled(enabled);
}


public int GetDoorState()
{
return m_DoorState;
}

public void Open()
{
if(m_DoorState != DOOR_CLOSED)
return;

SetInteractionHandlesEnabled(false);
m_DoorState = DOOR_OPENING;
Object[] args = new Object[1];
args[0] = this;
m_DoorStateChangeDelegate.Invoke(args);
}
public void Close()
{
if(m_DoorState != DOOR_OPEN)
return;

SetInteractionHandlesEnabled(false);
m_DoorState = DOOR_CLOSING;
Object[] args = new Object[1];
args[0] = this;
m_DoorStateChangeDelegate.Invoke(args);
}


public final Delegate1 OnDoorOpened()
{
return m_DoorOpenDelegate;
}
public final Delegate1 OnDoorClosed()
{
return m_DoorCloseDelegate;
}
public final Delegate1 OnDoorStateChanged()
{
return m_DoorStateChangeDelegate;
}


protected void InvokeDoorOpen()
{
Object[] args = new Object[1];
args[0] = this;
m_DoorOpenDelegate.Invoke(args);
}
protected void InvokeDoorClose()
{
Object[] args = new Object[1];
args[0] = this;
m_DoorCloseDelegate.Invoke(args);
}


public String GetName()
{
return m_DoorId;
}
public void SetName(String name)
{
m_DoorId = name;
}
public String GetType()
{
return "scripts.Door";
}
}
9 changes: 9 additions & 0 deletions scripts/DoorConfig.nlvm
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package scripts;

public class DoorConfig extends Object
{
public float OpenTime = 1.0f;
public float CloseTime = 1.0f;

public DoorConfig() { }
}
73 changes: 73 additions & 0 deletions scripts/DoorSingle.nlvm
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package scripts;

import scripts.delegates.*;
import com.nolimitscoaster.*;
import scripts.easings.*;
import scripts.math.*;

public class DoorSingle extends Door implements InteractionActionListener, IFunc1
{
private SubElement m_DoorElement = null;
private SceneObjectElement m_HandleElement = null;

private PropertyTweenReference m_OpenTween = null;
private PropertyTweenReference m_CloseTween = null;

protected void SetupDoor()
{
Json configJson = Json.Parse(Tools.loadTextFileFromResource(m_DoorConfigResource));

String doorElement = configJson.Get("door_element").GetString();
String handleElement = configJson.Get("handle_element").GetString();

m_DoorElement = GetChild(doorElement);
m_HandleElement = m_SceneObject.getElementForName(handleElement);

m_InteractionHandle = new InteractionObject[1];
m_InteractionHandle[0] = InteractionObject.createSimpleButton();
m_InteractionHandle[0].addActionListener(this);
m_InteractionHandle[0].setRadius(1.75f);
m_InteractionHandle[0].setActive(true);


Vector3 closeAngle = new Vector3(0, configJson.Get("close_angle").GetFloat() * Mathf.DegToRad, 0);
Vector3 openAngle = new Vector3(0, configJson.Get("open_angle").GetFloat() * Mathf.DegToRad, 0);


IPropertyHandle rotationProperty = m_DoorElement.GetPropertyHandle(SubElement.ROTATION);
m_OpenTween = PropertyTween.CreateTween(
rotationProperty,
closeAngle,
openAngle,
m_Config.OpenTime,
new EaseInOutSine()
);
m_CloseTween = PropertyTween.CreateTween(
rotationProperty,
openAngle,
closeAngle,
m_Config.CloseTime,
new EaseInOutSine()
);

OnDoorStateChanged().Connect(this);
}

protected void UpdateDoor()
{
m_InteractionHandle[0].setPosition(m_HandleElement.getAbsoluteMatrix().getTrans());
}


public void OnCalled(Delegate delegate, Object arg)
{
if(delegate == OnDoorStateChanged())
{
int state = ((Door)arg).GetDoorState();
if(state == DOOR_OPENING)
m_OpenTween.Play();
else if(state == DOOR_CLOSING)
m_CloseTween.Play();
}
}
}
Loading