Skip to content

Commit

Permalink
Merge pull request #196 from calband/dev/quick_gen_pdf
Browse files Browse the repository at this point in the history
Issue #161: Support CalChart's new Viewer File exporter with Close
  • Loading branch information
christina-yao authored Jun 5, 2024
2 parents 7f89d49 + 0cbad64 commit c7b3f66
Show file tree
Hide file tree
Showing 7 changed files with 97 additions and 6 deletions.
2 changes: 1 addition & 1 deletion build/js/pdf.js

Large diffs are not rendered by default.

16 changes: 13 additions & 3 deletions index.html
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
<html>

<head>
<title>Calchart Viewer</title>
<link href='https://fonts.googleapis.com/css?family=Open+Sans:300,400,700' rel='stylesheet' type='text/css'>
<link rel="shortcut icon" href="img/favicon.png">
<link rel="stylesheet" type="text/css" href="build/css/app.css">
<link rel="stylesheet" type="text/css" href="build/css/graph.css">
<link rel="stylesheet" type="text/css" href="css/vendor/chosen.min.css">
<script type="text/javascript" src="js/vendor/jspdf.min.js"></script>
<script type="text/javascript" src="js/vendor/jquery-1.11.1.min.js"></script>
<script type="text/javascript" src="js/vendor/d3.min.js"></script>
<script type="text/javascript" src="js/vendor/soundmanager2-jsmin.js"></script>
<script type="text/javascript" src="js/vendor/chosen.jquery.min.js"></script>
<script type="text/javascript" src="build/js/application.js"></script>

</head>

<body>
<!-- Loading screen -->
<div class="loading">
Expand Down Expand Up @@ -66,7 +69,8 @@ <h1>Loading</h1>
<div class="show-title js-show-title">No Show Selected</div>
<div class="animation-state">
<div class="stuntsheet">Stuntsheet: <span class="js-stuntsheet-label">None selected</span></div>
<div class="beats">Beat: <span class="js-beat-number">0</span>/<span class="js-stuntsheet-total">0</span></div>
<div class="beats">Beat: <span class="js-beat-number">0</span>/<span
class="js-stuntsheet-total">0</span></div>
<div class="js-dot-continuity continuity-container"></div>
</div>
<div class="next-prev-control">
Expand All @@ -86,11 +90,17 @@ <h1>Loading</h1>
<option></option>
</select>
</div>
<div class="control-button js-generate-continuity">
Generate continuity for <span class="js-selected-dot-label">dots</span>
<div class="next-prev-control">
<div class="control-button js-generate-continuity">
Generate continuity for <span class="js-selected-dot-label">dots</span>
</div>
<div class="control-button js-quick-generate-continuity disabled">
Quick Gen for <span class="js-selected-dot-label">dot</span>
</div>
</div>
</div>
</div>
</div>
</body>

</html>
27 changes: 27 additions & 0 deletions js/application.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
var ApplicationController = require("./viewer/ApplicationController");
var JSUtils = require("./viewer/utils/JSUtils");
var PDFGenerator = require("./pdf/PDFGenerator");

// will hold timeout event for long pressing buttons
var longPress = null;
Expand Down Expand Up @@ -95,15 +96,41 @@ $(document).ready(function () {
var defaults = "&md-orientation=west&bev-orientation=west&sd-orientation=west&layout-order=ltr";
window.location.href = "pdf.html?show=" + show + "&dots=" + dot + defaults;
});

$(".js-quick-generate-continuity").click(function () {
var show = $(".js-viewer-file").val();
var dot = $(".js-dot-labels").val();
window.generator = new PDFGenerator(applicationController._show, [dot])
try {
var options = {
"md-orientation":"west",
"bev-orientation":"west",
"sd-orientation":"west",
"layout-order":"ltr"
};
window.generator.generate(options);
window.generator.pdf.save();
} catch(err) {
console.log("Error occured ", err);
$(".file-input-error")
.text("Error occured " + err)
.fadeIn(1000)
.delay(1000)
.fadeOut(500);
throw err;
}
});

$(".js-dot-labels").chosen({
allow_single_deselect: true,
width: "90px"
}).change(function(evt, params){
if (params) {
applicationController.applyAnimationAction("selectDot", params.selected);
$(".js-quick-generate-continuity").removeClass("disabled");
} else {
applicationController.applyAnimationAction("clearSelectedDot");
$(".js-quick-generate-continuity").addClass("disabled");
}
});

Expand Down
38 changes: 38 additions & 0 deletions js/viewer/MovementCommandClose.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/**
* @fileOverview Defines the MovementCommandClose class.
*/

var JSUtils = require("./utils/JSUtils");
var MovementCommand = require("./MovementCommand");
var AnimationState = require("./AnimationState");

/**
* A MovementCommand representing being closed.
* @param {float} x The x coordinate to stand at.
* @param {float} y The y coordinate to stand at.
* @param {float} orientation The angle at which the marcher will
* face while standing. This is measured in degrees relative
* to Grapher standard position (@see MathUtils.js for a definition
* of "grapher standard position).
* @param {int} beats The duration of the movement, in beats.
*/
var MovementCommandClose = function(x, y, orientation, beats) {
this._orientation = orientation;
MovementCommand.apply(this, [x, y, x, y, beats]);
};

JSUtils.extends(MovementCommandClose, MovementCommand);

MovementCommandClose.prototype.getAnimationState = function(beatNum) {
return new AnimationState(this._startX, this._startY, this._orientation);
};

/**
* Returns the continuity text for this movement
* @return {String} the continuity text in the form of "Close E"
*/
MovementCommandClose.prototype.getContinuityText = function() {
return "Close " + this.getOrientation();
};

module.exports = MovementCommandClose;
2 changes: 1 addition & 1 deletion js/viewer/MovementCommandStand.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ MovementCommandStand.prototype.getAnimationState = function(beatNum) {
* @return {String} the continuity text in the form of "Close 16E"
*/
MovementCommandStand.prototype.getContinuityText = function() {
return "Close " + this._numBeats + this.getOrientation();
return "Stand & Play " + this._numBeats + this.getOrientation();
};

module.exports = MovementCommandStand;
16 changes: 16 additions & 0 deletions js/viewer/fileLoad/ViewerFileLoadSelector.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ var Dot = require("../Dot");
var Sheet = require("../Sheet");
var Show = require("../Show");
var MovementCommandStand = require("../MovementCommandStand");
var MovementCommandClose = require("../MovementCommandClose");
var MovementCommandMarkTime = require("../MovementCommandMarkTime");
var MovementCommandArc = require("../MovementCommandArc");
var MovementCommandMove = require("../MovementCommandMove");
Expand Down Expand Up @@ -218,6 +219,8 @@ ViewerFileLoad_1_0_0.prototype.buildIndividualMovement = function(movementToBuil
switch (movementToBuild.type) {
case "stand":
return this.buildStandMovement(movementToBuild);
case "close":
return this.buildCloseMovement(movementToBuild);
case "mark":
return this.buildMarkMovement(movementToBuild);
case "move":
Expand Down Expand Up @@ -246,6 +249,19 @@ ViewerFileLoad_1_0_0.prototype.buildStandMovement = function(movementToBuild) {
return new MovementCommandStand(movementToBuild.x, movementToBuild.y, movementToBuild.facing, movementToBuild.beats);
};

/**
* Builds a MovementCommandClose from its representation in
* a viewer file.
*
* @param {object} movementToBuild The MovementCommand's representation
* in the viewer file.
* @return {MovementCommandClose} The MovementCommandClose represented
* in the viewer file.
*/
ViewerFileLoad_1_0_0.prototype.buildCloseMovement = function(movementToBuild) {
return new MovementCommandClose(movementToBuild.x, movementToBuild.y, movementToBuild.facing, movementToBuild.beats);
};

/**
* Builds a MovementCommandMarkTime from its representation in
* a viewer file.
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"npm": "1.2.x"
},
"devDependencies": {
"grunt": "=1.3.0",
"grunt": "^1.6.1",
"grunt-contrib-less": "latest",
"grunt-contrib-watch": "latest",
"grunt-webpack": "latest",
Expand Down

0 comments on commit c7b3f66

Please sign in to comment.