Skip to content

Commit

Permalink
work in progress of action-controls
Browse files Browse the repository at this point in the history
  • Loading branch information
kfarr committed Feb 21, 2017
1 parent ea45e80 commit 2379d82
Show file tree
Hide file tree
Showing 4 changed files with 176 additions and 17 deletions.
28 changes: 20 additions & 8 deletions CHANGELOG.md
Expand Up @@ -20,14 +20,26 @@ X - fix to use proper multiple component syntax
* - move "trigger" event to select bar component
* - game logic should be refined to listen for this
* - test and make sure works
O - separate select-bar component into new repo
- remove from this project and make this project reference the remote repo version


what is missing from being able to "escape" in city builder? teleport, reliable save

- 2nd controller with menu commands
- teleport
* - separate select-bar component into new repo
* - fix separate select-bar
* - remove from this project and make this project reference the remote repo version

* what is missing from being able to "escape" in city builder? teleport, reliable save

* - 2nd controller with menu commands
* - teleport
* - test inverted teleport from forked repo
* - forked repo should work - use ghetto version
-
O - activate (add component) only when menu item selected
* - action-controls
* - init - what is the action?
* - if teleport, add teleport component
* - remove when not selected
- if save, add save component?
- issue - select bar ID in console log undefined, but code appears correct - is it using an old definition?

- bonus prize add animation to currently select action frame to indicate happening
- save
- message re URL and city name
- auto save with visual indicator (custom firebase that works)
Expand Down
18 changes: 10 additions & 8 deletions index.html
Expand Up @@ -19,9 +19,11 @@
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha256-916EbMg70RQy9LHiGkXzG8hSg9EdNy97GazNG/aiY1w=" crossorigin="anonymous" />

<!-- components used -->
<script src="https://rawgit.com/fernandojsg/aframe-teleport-controls/master/dist/aframe-teleport-controls.min.js"></script>
<!-- <script src="https://rawgit.com/fernandojsg/aframe-teleport-controls/master/dist/aframe-teleport-controls.min.js"></script> -->
<script src="https://rawgit.com/kfarr/aframe-teleport-controls/master/dist/aframe-teleport-controls.min.js"></script>

<script src="https://rawgit.com/kfarr/aframe-select-bar-component/master/dist/aframe-select-bar-component.js"></script>

<!-- <script src="https://rawgit.com/bryik/aframe-bmfont-text-component/master/dist/aframe-bmfont-text-component.min.js"></script>
<script src="https://rawgit.com/ngokevin/kframe/master/components/text/dist/aframe-text-component.min.js"></script> -->
<!-- <script src="https://rawgit.com/ngokevin/aframe-animation-component/master/dist/aframe-animation-component.js"></script>
Expand Down Expand Up @@ -117,18 +119,18 @@
<!-- Left Hand -->
<!-- <a-entity id="leftController" wasd-controls > -->
<!-- <a-entity builder-controls id="leftController" wasd-controls oculus-touch-controls="hand: left" vive-controls="hand: left" > -->
<a-entity id="leftController" teleport-controls="button: trigger; collisionEntities: #ground" wasd-controls oculus-touch-controls="hand: left" vive-controls="hand: left" >
<a-entity id="leftController" action-controls="menuID: menuActions" wasd-controls oculus-touch-controls="hand: left" vive-controls="hand: left" >
<!-- <a-entity id="leftItem" file="base_street" objectGroup="kfarr_bases" objectId="1" obj-model="obj: url(assets/obj/base_street1.obj); mtl: url(assets/obj/base_street1.mtl)" scale="0.01 0.01 0.01" position="0 0 -0.25" rotation="0 90 0"></a-entity> -->
<a-entity id="menuActions" select-bar="controllerID: leftController" scale="0.7 0.7 0.7" position="0 0.05 0.08" rotation="-85 0 0">

<optgroup label="Actions" value="actions">
<option value="teleport" src="assets/environment/icon_teleport.png" selected>Teleport</option>
<option value="save" src="assets/environment/icon_save.png">Save</option>
<option value="saveAs" src="assets/environment/icon_saveAs.png">Save As Copy</option>
<option value="new" src="assets/environment/icon_new.png">New</option>
<option value="erase" src="assets/environment/icon_erase.png">Erase</option>
<option value="inspect" src="assets/environment/icon_inspect.png">Inspect</option>
<option value="exit" src="assets/environment/icon_exit.png">Exit</option>
<option value="saveAs" src="assets/environment/icon_saveAs.png">Coming soon</option>
<option value="new" src="assets/environment/icon_new.png">Coming soon</option>
<option value="erase" src="assets/environment/icon_erase.png">Coming soon</option>
<option value="inspect" src="assets/environment/icon_inspect.png">Coming soon</option>
<option value="exit" src="assets/environment/icon_exit.png">Coming soon</option>
</optgroup>

</a-entity>
Expand Down
2 changes: 1 addition & 1 deletion index.js
@@ -1,6 +1,6 @@
require('aframe-gridhelper-component');
require('aframe-animation-component');

require('./lib/action-controls.js');
require('./lib/builder-controls.js');
require('./lib/ground.js');
require('./lib/skyGradient.js');
145 changes: 145 additions & 0 deletions lib/action-controls.js
@@ -0,0 +1,145 @@
/* global AFRAME */

if (typeof AFRAME === 'undefined') {
throw new Error('Component attempted to register before AFRAME was available.');
}

/**
* Game logic for controlling a-frame actions such as teleport and save
*/
AFRAME.registerComponent('action-controls', {
schema: {
menuID: {type: "string", default: "menu"}
},

/**
* Set if component needs multiple instancing.
*/
multiple: false,

/**
* Add event listeners.
*/
addEventListeners: function () {
// get menu element associated with these controls
var menuEl = document.getElementById(this.data.menuID);
menuEl.addEventListener('menuChanged', this.onActionChange.bind(this));
// menuEl.addEventListener('menuSelected', this.onPlaceObject.bind(this));
},

/**
* Remove event listeners.
*/
removeEventListeners: function () {
var menuEl = document.getElementById(this.data.menuID);
menuEl.removeEventListener('menuChanged', this.onActionChange);
// menuEl.removeEventListener('menuSelected', this.onPlaceObject);
},

init: function () {
console.log(this.data.menuID);
var menuEl = document.getElementById(this.data.menuID);

if (typeof menuEl === 'undefined') {
// Wait for select bar menu to init.
var self = this;
return setTimeout(function () {
console.log("init loop");
self.init();
});
}

console.log(menuEl);
// get currently selected action
var optionValue = menuEl.components['select-bar'].data.selectedOptionValue;
// do the thing associated with the action
this.handleActionStart(optionValue);
},

onActionSelect: function () {
// what is the action

// call the thing that does it
},

onActionChange: function () {
// undo old one
handleActionEnd(this.previousAction);

var menuEl = document.getElementById(this.data.menuID);
// get currently selected action
var optionValue = menuEl.components['select-bar'].data.selectedOptionValue;

// do new one
this.handleActionStart(optionValue);
},

/**
* Called when entity resumes.
* Use to continue or add any dynamic or background behavior such as events.
*/
play: function () {
this.addEventListeners();
},

/**
* Called when entity pauses.
* Use to stop or remove any dynamic or background behavior such as events.
*/
pause: function () {
this.removeEventListeners();
},

/**
* Called when a component is removed (e.g., via removeAttribute).
* Generally undoes all modifications to the entity.
*/
remove: function () {
this.removeEventListeners();
},

handleActionStart: function(optionValue) {
this.previousAction = optionValue;

// for given optionValue, do something
// caseswitch (optionValue) {
// case "teleport": // add teleport component to the control element that is the parent of this menu
// console.log("teleportStart");
// // find control element that is the parent of this menu
// controlEl = this.el.parentElement;
// // Add attribute from this html: teleport-controls="button: trigger; collisionEntities: #ground"
// controlEl.setAttribute("teleport-controls", "button: trigger; collisionEntities: #ground");
// return; // without this return the other cases are fired - weird!
// case "save":
// console.log("saveStart");
// return;
// case "saveAs":
// console.log("saveAsStart");
// return;
// case "new":
// console.log("newStart");
// return;
// }
},

handleActionEnd: function(optionValue) {
// caseswitch (optionValue) {
// case "teleport": // add teleport component to the control element that is the parent of this menu
// // find control element that is the parent of this menu
// controlEl = this.el.parentElement;
// // Remove teleport controls attribute
// controlEl.removeAttribute("teleport-controls");
// return; // without this return the other cases are fired - weird!
// case "save":
// console.log("saveRemove");
// return;
// case "saveAs":
// console.log("saveAsRemove");
// return;
// case "new":
// console.log("newRemove");
// return;
// }
return;
}
});

0 comments on commit 2379d82

Please sign in to comment.