Skip to content

Commit 7f83131

Browse files
committed
Added duration setting.
1 parent 9df10db commit 7f83131

File tree

5 files changed

+78
-5
lines changed

5 files changed

+78
-5
lines changed

examples/threejs_shaders.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
{
2-
"config": {},
2+
"config": {
3+
"duration": 70
4+
},
35
"scripts": [
46
{
57
"name": "Renderer",

index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060

6161
// LocalStorage
6262

63+
editor.signals.durationChanged.add( saveState );
6364
editor.signals.animationAdded.add( saveState );
6465
editor.signals.animationModified.add( saveState );
6566
editor.signals.animationRemoved.add( saveState );

js/Editor.js

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@ function Editor() {
1212
this.signals = {
1313

1414
editorCleared: new Signal(),
15+
projectLoaded: new Signal(),
16+
17+
// config
18+
19+
duration: new Signal(),
20+
durationChanged: new Signal(),
1521

1622
// scripts
1723

@@ -65,7 +71,7 @@ function Editor() {
6571
this.player = new Player();
6672
this.resources = new Resources();
6773

68-
this.duration = 500;
74+
this.duration = 120;
6975

7076
this.scripts = [];
7177
this.effects = [];
@@ -77,6 +83,13 @@ function Editor() {
7783

7884
var scope = this;
7985

86+
this.signals.duration.add( function ( value ) {
87+
88+
scope.duration = value;
89+
scope.signals.durationChanged.dispatch();
90+
91+
} );
92+
8093
this.signals.animationModified.add( function () {
8194

8295
scope.timeline.reset();
@@ -441,6 +454,12 @@ Editor.prototype = {
441454

442455
var scope = this;
443456

457+
if ( json.config && json.config.duration ) {
458+
459+
scope.duration = json.config.duration;
460+
461+
}
462+
444463
var scripts = json.scripts;
445464

446465
for ( var i = 0, l = scripts.length; i < l; i ++ ) {
@@ -498,14 +517,17 @@ Editor.prototype = {
498517

499518
}
500519

520+
scope.signals.projectLoaded.dispatch();
501521
scope.setTime( 0 );
502522

503523
},
504524

505525
toJSON: function () {
506526

507527
var json = {
508-
"config": {},
528+
"config": {
529+
"duration": this.duration,
530+
},
509531
"scripts": [],
510532
"effects": [],
511533
// "curves": [],

js/SidebarProject.js

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,47 @@ function SidebarProject( editor ) {
1111
var container = new UIPanel();
1212
container.setId( 'project' );
1313

14+
// Config
15+
16+
container.add( new UIText( 'Config' ).setTextTransform( 'uppercase' ) );
17+
container.add( new UIBreak(), new UIBreak() );
18+
19+
var row = new UIRow();
20+
row.add( new UIText( 'Duration' ).setWidth( '90px' ) );
21+
container.add( row );
22+
23+
function toSeconds( time ) {
24+
25+
const parts = time.split( ':' );
26+
return parseInt( parts[ 0 ] ) * 60 + parseInt( parts[ 1 ] );
27+
28+
}
29+
30+
function fromSeconds( seconds ) {
31+
32+
var minute = Math.floor( seconds / 60 );
33+
var second = Math.floor( seconds % 60 );
34+
35+
return `${ minute }:${ second.toString().padStart( 2, '0' ) }`;
36+
37+
}
38+
39+
var duration = new UIInput( '2:00' ).setWidth( '80px' );
40+
duration.onChange( function () {
41+
42+
signals.duration.dispatch( toSeconds( this.getValue() ) );
43+
44+
} );
45+
row.add( duration );
46+
47+
signals.projectLoaded.add( function () {
48+
49+
duration.setValue( fromSeconds( editor.duration ) );
50+
51+
} );
52+
53+
container.add( new UIBreak() );
54+
1455
// Scripts
1556

1657
container.add( new UIText( 'Scripts' ).setTextTransform( 'uppercase' ) );

js/Timeline.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,10 @@ function Timeline( editor ) {
3737
// Get mouse position relative to the timeline
3838
const rect = timeline.dom.getBoundingClientRect();
3939
const mouseX = event.clientX - rect.left;
40-
40+
4141
// Calculate the time at the mouse position
4242
const mouseTime = (scroller.scrollLeft + mouseX) / scale;
43-
43+
4444
// Update scale
4545
scale = Math.max( 2, scale - ( event.deltaY / 10 ) );
4646
signals.timelineScaled.dispatch( scale );
@@ -253,6 +253,13 @@ function Timeline( editor ) {
253253

254254
// signals
255255

256+
signals.durationChanged.add( function () {
257+
258+
updateMarks();
259+
updateContainers();
260+
261+
} );
262+
256263
signals.timeChanged.add( function () {
257264

258265
updateTimeMark();

0 commit comments

Comments
 (0)