Skip to content
This repository has been archived by the owner on May 31, 2021. It is now read-only.

StageXL app generator. #381

Merged
merged 4 commits into from
Mar 21, 2017
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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ Kit and Yeoman.
* `web-angular` - A web app built using the latest stable version of Angular.
* `web-angular-simple` - A minimalist example app used in docs.
* `web-simple` - An absolute bare-bones web app.
* `web-stagexl` - A basic 2D canvas app with StageXL.

## Installation

Expand Down
23 changes: 23 additions & 0 deletions lib/generators/web_stagexl.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Copyright (c) 2014, Google Inc. Please see the AUTHORS file for details.
// All rights reserved. Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

import '../stagehand.dart';
import '../src/common.dart';
import 'web_stagexl_data.dart';

/**
* A generator for a StageXL web application.
*/
class WebStageXlGenerator extends DefaultGenerator {
WebStageXlGenerator()
: super('web-stagexl', 'Simple StageXL Application',
'A basic 2D canvas app with StageXL.',
categories: const ['dart', 'web']) {
for (TemplateFile file in decodeConcatenatedData(data)) {
addTemplateFile(file);
}

setEntrypoint(getFile('web/index.html'));
}
}
925 changes: 925 additions & 0 deletions lib/generators/web_stagexl_data.dart

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion lib/stagehand.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import 'generators/server_shelf.dart';
import 'generators/web_angular.dart';
import 'generators/web_angular_simple.dart';
import 'generators/web_simple.dart';
import 'generators/web_stagexl.dart';
import 'src/common.dart';

/// A curated, prescriptive list of Dart project generators.
Expand All @@ -42,7 +43,8 @@ final List<Generator> generators = [
new ServerShelfGenerator(),
new WebAngularGenerator(),
new WebAngularSimpleGenerator(),
new WebSimpleGenerator()
new WebSimpleGenerator(),
new WebStageXlGenerator()
]..sort();

Generator getGenerator(String id) {
Expand Down
1 change: 1 addition & 0 deletions site/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ <h1 id="usage">Usage</h1>
<li>web-angular - <em>A web app built using the latest stable version of Angular.</em></li>
<li>web-angular-simple - <em>A minimalist example app used in docs.</em></li>
<li>web-simple - <em>An absolute bare-bones web app.</em></li>
<li>web-stagexl - <em>A basic 2D canvas app with StageXL.</em></li>
</ul>

<aside class="alert alert-warning">
Expand Down
9 changes: 9 additions & 0 deletions templates/web-stagexl/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Files and directories created by pub
.packages
.pub/
build/
# Remove the following pattern if you wish to check in your lock file
pubspec.lock

# Directory created by dartdoc
doc/api/
5 changes: 5 additions & 0 deletions templates/web-stagexl/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Changelog

## 0.0.1

- Initial version, created by Stagehand
24 changes: 24 additions & 0 deletions templates/web-stagexl/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
Copyright (c) __year__, __author__.
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of the <organization> nor the
names of its contributors may be used to endorse or promote products
derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3 changes: 3 additions & 0 deletions templates/web-stagexl/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# A simple StageXL app

Generated by Stagehand. See LICENSE.
13 changes: 13 additions & 0 deletions templates/web-stagexl/analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# This file allows you to configure the Dart analyzer.
#
# The commented part below is just for inspiration. Read the guide here:
# https://www.dartlang.org/guides/language/analysis-options

# analyzer:
# strong-mode: true
# exclude:
# - path/to/excluded/files/**
# linter:
# rules:
# # see catalog here: http://dart-lang.github.io/linter/lints/
# - hash_and_equals
18 changes: 18 additions & 0 deletions templates/web-stagexl/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: __projectName__
description: A simple StageXL web app.
version: 0.0.1
#homepage: https://www.example.com
#author: __author__ <email@example.com>

environment:
sdk: '>=1.20.1 <2.0.0'

dependencies:
stagexl: ^1.1.0

dev_dependencies:
browser: ^0.10.0
dart_to_js_script_rewriter: ^1.0.1

transformers:
- dart_to_js_script_rewriter
Binary file added templates/web-stagexl/web/images/dart@1x.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 templates/web-stagexl/web/images/dart@2x.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 templates/web-stagexl/web/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<!DOCTYPE html>

<!--
Copyright (c) __year__, __author__. All rights reserved. Use of this source code
is governed by a BSD-style license that can be found in the LICENSE file.
-->

<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="scaffolded-by" content="https://github.com/google/stagehand">
<title>__projectName__</title>
<link rel="stylesheet" href="styles.css">
<script defer src="main.dart" type="application/dart"></script>
<script defer src="packages/browser/dart.js"></script>
</head>

<body>

<canvas id="stage" class="stage--fullscreen"></canvas>

</body>
</html>
55 changes: 55 additions & 0 deletions templates/web-stagexl/web/main.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// Copyright (c) __year__, __author__. All rights reserved. Use of this source code
// is governed by a BSD-style license that can be found in the LICENSE file.

import 'dart:async';
import 'dart:html' as html;
import 'package:stagexl/stagexl.dart';
import 'dart:math';

Future<Null> main() async {
StageOptions options = new StageOptions()
..backgroundColor = Color.White
..renderEngine = RenderEngine.WebGL;

var canvas = html.querySelector('#stage');
var stage = new Stage(canvas, width: 1280, height: 800, options: options);

var renderLoop = new RenderLoop();
renderLoop.addStage(stage);

var resourceManager = new ResourceManager();
resourceManager.addBitmapData("dart", "images/dart@1x.png");

await resourceManager.load();

var logoData = resourceManager.getBitmapData("dart");
var logo = new Sprite();
logo.addChild(new Bitmap(logoData));

logo.pivotX = logoData.width / 2;
logo.pivotY = logoData.height / 2;

// Place it at top center.
logo.x = 1280 / 2;
logo.y = 0;

stage.addChild(logo);

// And let it fall.
var tween = stage.juggler.addTween(logo, 3, Transition.easeOutBounce);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we set this up so that it dances on mouse-over...or reanimates when clicked?

Just something so it feel playful and shows a bit of event handling.

tween.animate.y.to(800 / 2);

// Add some interaction on mouse click.
Tween rotation;
logo.onMouseClick.listen((MouseEvent e) {
// Don't run more rotations at the same time.
if (rotation != null) return;
rotation = stage.juggler.addTween(logo, 0.5, Transition.easeInOutCubic);
rotation.animate.rotation.by(2 * PI);
rotation.onComplete = () => rotation = null;
});
logo.mouseCursor = MouseCursor.POINTER;

// See more examples:
// https://github.com/bp74/StageXL_Samples
}
9 changes: 9 additions & 0 deletions templates/web-stagexl/web/styles.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
@import url(https://fonts.googleapis.com/css?family=Roboto);

html, body, .stage--fullscreen {
width: 100%;
height: 100%;
margin: 0;
padding: 0;
border: 0;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing newline

2 changes: 1 addition & 1 deletion test/validate_templates.dart
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ void _testGenerator(stagehand.Generator generator, Directory tempDir) {
var pubspecFile = new File(pubspecPath);

if (!pubspecFile.existsSync()) {
fail('A pubspec much be defined!');
fail('A pubspec must be defined!');
}

Pub.get(runOptions: new RunOptions(workingDirectory: tempDir.path));
Expand Down