Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Examples and fix for #25 #28

Open
wants to merge 29 commits into
base: master
Choose a base branch
from
Open
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
Binary file not shown.
Binary file added example/cactus_Example/public/favicon.ico
Binary file not shown.
Binary file not shown.
Binary file not shown.
43 changes: 43 additions & 0 deletions example/cactus_Example/public/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<link rel="shortcut icon" href="%PUBLIC_URL%/favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="theme-color" content="#000000" />
<meta
name="description"
content="Web site created using create-react-app"
/>
<link rel="apple-touch-icon" href="logo192.png" />
<!--
manifest.json provides metadata used when your web app is installed on a
user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/
-->
<link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
<!--
Notice the use of %PUBLIC_URL% in the tags above.
It will be replaced with the URL of the `public` folder during the build.
Only files inside the `public` folder can be referenced from the HTML.

Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will
work correctly both with client-side routing and a non-root public URL.
Learn how to configure a non-root public URL by running `npm run build`.
-->
<title>Flare Sample</title>
</head>
<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
<div id="root"></div>
<!--
This HTML file is a template.
If you open it directly in the browser, you will see an empty page.

You can add webfonts, meta tags, or analytics to this file.
The build step will place the bundled scripts into the <body> tag.

To begin the development, run `npm start` or `yarn start`.
To create a production bundle, use `npm run build` or `yarn build`.
-->
</body>
</html>
Binary file added example/cactus_Example/public/logo192.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added example/cactus_Example/public/logo512.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
25 changes: 25 additions & 0 deletions example/cactus_Example/public/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"short_name": "React App",
"name": "Create React App Sample",
"icons": [
{
"src": "favicon.ico",
"sizes": "64x64 32x32 24x24 16x16",
"type": "image/x-icon"
},
{
"src": "logo192.png",
"type": "image/png",
"sizes": "192x192"
},
{
"src": "logo512.png",
"type": "image/png",
"sizes": "512x512"
}
],
"start_url": ".",
"display": "standalone",
"theme_color": "#000000",
"background_color": "#ffffff"
}
2 changes: 2 additions & 0 deletions example/cactus_Example/public/robots.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# https://www.robotstxt.org/robotstxt.html
User-agent: *
22 changes: 22 additions & 0 deletions example/cactus_Example/src/App.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
.App {
text-align: center;
}

.App-logo {
height: 40vmin;
}

.App-header {
background-color: #282c34;
min-height: 100vh;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
font-size: calc(10px + 2vmin);
color: white;
}

.App-link {
color: #09d3ac;
}
176 changes: 176 additions & 0 deletions example/cactus_Example/src/App.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,176 @@
import React from 'react';
import './App.css';

import FlareComponent from 'flare-react';
import cactus from './Cactus_No_Joy.flr';
import flutter from './Flutter_Celebration.flr';
import ActorNodeSolo from '../node_modules/flare-react/dependencies/Flare-JS/source/ActorNodeSolo';
import ActorBone from 'flare-react/dependencies/Flare-JS/source/ActorBone.js';
import CustomProperty from 'flare-react/dependencies/Flare-JS/source/CustomProperty.js';
import soundfile from './huh_sound_cartoon.wav';
import HappySoundFile from './happy_sound_cartoon.wav';

class MyFlareController extends FlareComponent.Controller
{
constructor()
{
super();
this._IdleAnim = null;
this._SoloIdx = 1;
this._CurrSoloIdx = 1;
this._ActorAnimator = null;
this._ProgressTracker = null;
this._SoloNode = new ActorNodeSolo();
this._MyBone = new ActorBone();
this._MyCP = new CustomProperty();
this._MyNode = null;

this._CanPlay = false;
this._SmileTime = 0;
this._AnimTime = 0;

this.sound = new Audio(soundfile);
this.happySound = new Audio(HappySoundFile);
}

initialize(artboard)
{
if(artboard.name === "Scene"){
this._Artboard = artboard;

}

this._MyNode = this._Artboard.getNode("Scale Node_Special Property");

this._MyBone = this._Artboard.getNode("Bone");

this._ActorAnimator = this._Artboard.getAnimation("Mustache_New");
this._ProgressTracker = this._Artboard.getAnimation("Mustache_New");
}

advance(artboard, elapsed)
{
this._AnimTime += elapsed *1;

//let _animationEvents = [];


if (this._CanPlay === true)
{
this._ActorAnimator.apply(this._AnimTime % this._ActorAnimator.duration, artboard, 1);
}
if (this._SoloIdx !== this._CurrSoloIdx)
{
this._SoloNode = artboard.getNode("Mustache_Solo");
this._SoloNode.setActiveChildIndex(this._SoloIdx);

this._CanPlay = true;
this._SmileTime = 0;
this._CurrSoloIdx = this._SoloIdx;

}

// let _currLayerAnim = this._SmileTime;

this._SmileTime += elapsed * 1;
if (this._SmileTime > this._ActorAnimator.duration)
{
this._CanPlay = false;
}

/*for (let props in this._MyNode._CustomProperties)
{
switch (this._MyNode._CustomProperties[props]._Name)
{

case "happy_sound":
///play our sound when the custom property changes
if (this._MyNode._CustomProperties[props]._Value === true){
this.happySound.play();
}
break;
default:
break;

}

}*/


/*this._ProgressTracker.triggerEvents(artboard._Components, _currLayerAnim, this._SmileTime, _animationEvents);

for (let event in _animationEvents)
{
switch (_animationEvents[event].name)
{
case "Event":
///play our sound when the event happens
this.sound.play();
break;
default:
break;
}
}*/

return true;
}

changeSoloNode = () =>
{
this._SoloIdx ++;
if (this._SoloIdx > 5){
this._SoloIdx = 1;
}
console.log(this._SoloIdx);
}
}

export default class MyComponent extends React.Component
{
constructor(props)
{
super(props);

this.state = {
myfile: cactus,
myFlareController: new MyFlareController()
};
this.Update_Stache = this.Update_Stache.bind(this);
}

render()
{
return (
<div>
<FlareComponent width={500} height={500} animationName="Idle" file={this.state.myfile} controller={this.state.myFlareController} />

<button onClick={this.onChange.bind(this)}>Click Me!</button>
</div>
);
}
//<button onClick={this.Update_Stache}>Click Me!</button>
onChange(e) {
this.setState({[e.target.id]: e.target.value},
() => {
if (this.state.myfile === flutter) {
this.setState({ myfile: cactus });
} else {
this.setState({ myfile: flutter });
}
}
);
console.log(this.state.myfile);
}
Update_Stache = () =>
{

//this.state.myFlareController.changeSoloNode();
this.setState({

myfile: flutter,
});

console.log("pressed");
}

}
9 changes: 9 additions & 0 deletions example/cactus_Example/src/App.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import React from 'react';
import ReactDOM from 'react-dom';
import App from './App';

it('renders without crashing', () => {
const div = document.createElement('div');
ReactDOM.render(<App />, div);
ReactDOM.unmountComponentAtNode(div);
});
Binary file added example/cactus_Example/src/Cactus_No_Joy.flr
Binary file not shown.
Binary file not shown.
Binary file added example/cactus_Example/src/huh_sound_cartoon.wav
Binary file not shown.
13 changes: 13 additions & 0 deletions example/cactus_Example/src/index.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
body {
margin: 0;
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Roboto", "Oxygen",
"Ubuntu", "Cantarell", "Fira Sans", "Droid Sans", "Helvetica Neue",
sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}

code {
font-family: source-code-pro, Menlo, Monaco, Consolas, "Courier New",
monospace;
}
12 changes: 12 additions & 0 deletions example/cactus_Example/src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import React from 'react';
import ReactDOM from 'react-dom';
import './index.css';
import App from './App';
import * as serviceWorker from './serviceWorker';

ReactDOM.render(<App />, document.getElementById('root'));

// If you want your app to work offline and load faster, you can change
// unregister() to register() below. Note this comes with some pitfalls.
// Learn more about service workers: https://bit.ly/CRA-PWA
serviceWorker.unregister();
1 change: 1 addition & 0 deletions example/cactus_Example/src/logo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading