Made the game "codepen-ready".

Removed Browserify, made the game lighter.
The game now loads Salet as a JS library.

The preparations for that are done by Gulp.
This commit is contained in:
Alexander Yakovlev 2016-12-27 15:16:16 +07:00
parent fee26fc1ea
commit b02f728d0c
10 changed files with 60 additions and 318 deletions

View file

@ -1,22 +1,24 @@
watchify = require('watchify')
browserify = require('browserify')
browserSync = require('browser-sync')
gulp = require('gulp')
source = require('vinyl-source-stream')
gutil = require('gulp-util')
coffeify = require('coffeeify')
coffee = require("gulp-coffee")
sass = require('gulp-sass')
uglify = require('gulp-uglify')
buffer = require('vinyl-buffer')
zip = require('gulp-zip')
concat = require('gulp-concat')
rename = require('gulp-rename')
reload = browserSync.reload
html = (target) ->
return () ->
return gulp.src(['html/index.html']).pipe(gulp.dest(target))
gulp.src(['html/index.html'])
.pipe(gulp.dest(target))
gulp.src(['node_modules/salet/lib/index.min.js'])
.pipe(rename('salet.min.js'))
.pipe(gulp.dest(target+"/game"))
# Images
img = (target) ->
@ -32,35 +34,30 @@ gulp.task('html', html('./build'))
gulp.task('img', img('./build/img'))
gulp.task('audio', audio('./build/audio'))
# SCSS styles
gulp.task('sass', () ->
gulp.src('sass/main.scss')
.pipe(sass({outputStyle: 'compressed'}).on('error', sass.logError))
.pipe(gulp.dest('./build/css'))
)
bundler = watchify(browserify({
entries: ["./build/game/main.coffee"]
debug: true
transform: [coffeify]
}))
bundle = () ->
return bundler.bundle()
.on('error', gutil.log.bind(gutil, 'Browserify Error'))
.pipe(source('bundle.js'))
.pipe(gulp.dest('./build/game'))
gulp.task('concatCoffee', () ->
return gulp.src([
'./game/begin.coffee',
'./game/story.coffee',
]).pipe(concat('./main.coffee')).pipe(gulp.dest('./build/game'))
gulp.src([
## additional functions
'./game/dialogue.coffee',
'./game/phrase.coffee',
## the actual game
'./game/begin.coffee',
'./game/story.coffee',
]).pipe(concat('./main.coffee'))
.pipe(gulp.dest('./build/game'))
)
gulp.task('coffee', ['concatCoffee'], bundle)
bundler.on('update', bundle)
bundler.on('log', gutil.log)
gulp.task('coffee', ['concatCoffee'], () ->
gulp.src('./build/game/main.coffee')
.pipe(coffee({bare: true}))
.pipe(gulp.dest('./build/game/'))
)
gulp.task('build', ['html', 'img', 'sass', 'coffee', 'audio'])
@ -99,19 +96,13 @@ gulp.task('sass-dist', () ->
.pipe(gulp.dest('./dist/css'))
)
distBundler = browserify({
debug: false,
entries: ['./build/game/main.coffee'],
transform: ['coffeeify']
})
gulp.task('coffee-dist', ['concatCoffee'], () ->
return distBundler.bundle()
.pipe(source('bundle.js'))
.pipe(buffer())
.pipe(uglify())
.on('error', gutil.log)
.pipe(gulp.dest('./dist/game'))
gulp.src('./build/game/main.coffee', {sourcemaps: false})
.pipe(coffee())
.pipe(buffer())
.pipe(uglify())
.on('error', gutil.log)
.pipe(gulp.dest('./dist/game/'))
)
gulp.task('dist', [

View file

@ -1,8 +1,3 @@
dialogue = require('../../lib/dialogue.coffee')
phrase = require('../../lib/phrase.coffee')
oneOf = require('../../lib/oneOf.coffee')
require('salet')
salet.game_id = "your-game-id-here"
salet.game_version = "1.6"
$(document).ready(() ->

View file

@ -21,5 +21,3 @@ dialogue = (title, startTag, endTag, text, effect) ->
retval.before = (character, system) ->
eval(effect)
return retval
module.exports = dialogue

View file

@ -24,5 +24,3 @@ phrase = (title, tag, text, effect) ->
retval.before = (character, system) ->
eval(effect)
return retval
module.exports = phrase

View file

@ -5,6 +5,7 @@
<title>Salet showcase</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href='https://fonts.googleapis.com/css?family=PT+Sans:400,400italic|PT+Sans+Caption' rel='stylesheet' type='text/css'>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.5/css/bootstrap.min.css">
<link rel="stylesheet" href="css/main.css">
</head>
<body>
@ -80,10 +81,10 @@
</div> <!-- End of div.page -->
<!-- CDN JS Libraries -->
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/marked/0.3.5/marked.min.js" integrity="sha384-QXBtGc4014gU26HdCwzgy8TVO+FHSSE4+EvPPiSTpdE9w0KyJy1ocfiIbBl1HLq7" crossorigin="anonymous"></script>
<script type="text/javascript" src="https://code.jquery.com/jquery-3.0.0.min.js"
integrity="sha384-THPy051/pYDQGanwU6poAc/hOdQxjnOEXzbT+OuUAFqNqFjL+4IGLBgCJC3ZOShY" crossorigin="anonymous"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/marked/0.3.5/marked.min.js" crossorigin="anonymous"></script>
<script type="text/javascript" src="https://code.jquery.com/jquery-3.1.1.min.js" crossorigin="anonymous"></script>
<script type="text/javascript" src="game/salet.min.js"></script>
<script type="text/javascript" src="game/bundle.js"></script>
<script type="text/javascript" defer="defer" src="game/main.js"></script>
</body>
</html>

View file

@ -1,2 +0,0 @@
These functions are not used by Salet core.
But you can `require` them in your game and use thusly.

View file

@ -1,169 +0,0 @@
###
oneOf.js
Copyright (c) 2015 Bruno Dias
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
###
###
Undularity Tools
Those functions are not a core part of Undularity, but provide some
general functionality that relates to adaptive text generation.
This is provided partly as a helper to less technical users, and as
a convenience for authors.
###
# Monkey patching
###
Shuffles an array. It can use Undum's random number generator implementation,
so it expects a System.rnd object to be passed into it. If one isn't
supplied, it will use Math.Random instead.
This is an implementation of the Fischer-Yates (Knuth) shuffle.
Returns the shuffled array.
###
Array.prototype.shuffle = () ->
# slice() clones the array. Object members are copied by reference, beware.
newArr = this.slice()
m = newArr.length
while (m)
i = Math.floor(salet.rnd.randf() * m--)
t = newArr[m]
newArr[m] = newArr[i]
newArr[i] = t
return newArr
###
oneOf()
Takes an array and returns an object with several methods. Each method
returns an iterator which iterates over the array in a specific way:
inOrder()
Returns the array items in order.
cycling()
Returns the array items in order, cycling back to the first item when
it runs out.
stopping()
Returns the array items in order, then repeats the last item when it
runs out.
randomly()
Returns the array items at random. Takes a system object, for consistent
randomness. Will never return the same item twice in a row.
trulyAtRandom()
Returns the array items purely at random. Takes a system object, for
consistent randomness.
inRandomOrder()
Returns the array items in a random order. Takes a system object, for
consistent randomness.
###
###
Takes a function and gives it a toString() property that calls itself and
returns its value, allowing for ambiguous use of the closure object
as a text snippet.
Returns the modified function.
###
stringish = (callback) ->
callback.toString = () ->
return '' + this.call()
return callback
oneOf = (ary...) ->
if ary.length == 0
throw new Error(
"tried to create a oneOf iterator with a 0-length array");
return {
inOrder: () ->
i = 0
return stringish(() ->
if i >= ary.length
return null
return ary[i++]
)
cycling: () ->
i = 0
return stringish(() ->
if (i >= ary.length)
i = 0
return ary[i++]
)
stopping: () ->
i = 0
return stringish(() ->
if (i >= ary.length)
i = ary.length - 1
return ary[i++]
)
randomly: (system) ->
last = null
if (ary.length<2)
throw new Error("attempted to make randomly() iterator with a 1-length array")
return stringish( () ->
i = null
offset = null
if not last?
i = Math.floor(salet.rnd.randf() * ary.length)
else
###
Let offset be a random number between 1 and the length of the
array, minus one. We jump offset items ahead on the array,
wrapping around to the beginning. This gives us a random item
other than the one we just chose.
###
offset = Math.floor(salet.rnd.randf() * (ary.length -1) + 1)
i = (last + offset) % ary.length
last = i
return ary[i]
)
trulyAtRandom: (system) ->
return stringish(() ->
return ary[Math.floor(salet.rnd.randf() * ary.length)];
)
inRandomOrder: (system) ->
shuffled = ary.shuffle(system)
i = 0
return stringish(() ->
if (i >= ary.length)
i = 0
return shuffled[i++]
)
}
Array.prototype.oneOf = () ->
oneOf.apply(null, this)
String.prototype.oneOf = () ->
return this
module.exports = oneOf

View file

@ -1,24 +1,21 @@
{
"dependencies": {
"salet": "^1.5.4"
"gulp-rename": "^1.2.2",
"salet": "^1.6.15"
},
"private": true,
"devDependencies": {
"bootstrap": "^4.0.0-alpha.2",
"browser-sync": "^2.18.2",
"browserify": "^13.1.1",
"browserify-shim": "^3.8.8",
"coffee-script": "^1.12.0",
"coffeeify": "^2.1.0",
"bootstrap": "^4.0.0-alpha.5",
"browser-sync": "^2.18.5",
"coffee-script": "^1.12.2",
"gulp": "^3.8.11",
"gulp-coffee": "^2.3.3",
"gulp-concat": "^2.6.1",
"gulp-sass": "^2.1.1",
"gulp-sass": "^3.0.0",
"gulp-uglify": "^2.0.0",
"gulp-util": "^3.0.4",
"gulp-util": "^3.0.8",
"gulp-zip": "^3.0.2",
"vinyl-buffer": "^1.0.0",
"vinyl-source-stream": "^1.1.0",
"watchify": "^3.1.0"
"vinyl-source-stream": "^1.1.0"
}
}

View file

@ -1,16 +0,0 @@
@mixin halfcolumn() {
@media (min-width: breakpoint-min(sm)) {
@include make-col(6);
}
@media (max-width: breakpoint-max(xs)) {
@include make-col(12);
}
}
@mixin col($sm-width, $xs-width) {
@media (min-width: breakpoint-min(sm)) {
@include make-col($sm-width);
}
@media (max-width: breakpoint-max(xs)) {
@include make-col($xs-width);
}
}

View file

@ -1,42 +1,16 @@
@import "../node_modules/bootstrap/scss/mixins/grid";
@import "mixins";
@import "variables";
// Bootstrap v4 stripped core
@import "../node_modules/bootstrap/scss/variables";
@import "../node_modules/bootstrap/scss/mixins";
@import "../node_modules/bootstrap/scss/normalize";
@import "../node_modules/bootstrap/scss/print";
@import "../node_modules/bootstrap/scss/reboot";
@import "../node_modules/bootstrap/scss/type";
// @import "../node_modules/bootstrap/scss/images";
@import "../node_modules/bootstrap/scss/grid";
@import "../node_modules/bootstrap/scss/buttons";
@import "../node_modules/bootstrap/scss/bootstrap.scss";
@import "../node_modules/bootstrap/scss/nav";
@import "../node_modules/bootstrap/scss/responsive-embed";
@import "../node_modules/bootstrap/scss/utilities";
body {
overflow-y: scroll;
overflow-x: hidden;
background: $body-bg;
}
// The title block
.title {
margin-top: 3.5em;
@include col(10,12);
@media (min-width: breakpoint-min(sm)) {
@include make-col-offset(1);
}
@extend .col-xs-12;
.label {
margin: 1.5em auto;
@media (min-width: breakpoint-min(sm)) {
@include make-col-offset(2);
@include make-col(8);
}
@media (max-width: breakpoint-min(sm)) {
@include make-col(12);
}
margin-top: 1.5em;
margin-bottom: 1em;
@extend .col-md-8;
@extend .offset-md-2;
@extend .col-xs-12;
text-align: center;
}
.subtitle {
@ -65,7 +39,7 @@ body {
}
}
#choices {
@include make-col(12);
@extend .col-xs-12;
}
.fixed {
position: fixed;
@ -79,10 +53,10 @@ body {
background: $body-bg;
.ways {
padding: 0.5em;
@include make-col(6);
@extend .col-md-6;
}
.buttons {
@include make-col(6);
@extend .col-md-6;
text-align: right;
}
button {
@ -94,17 +68,9 @@ body {
border-radius: 5px;
}
.content {
@include col(10, 12);
@media (min-width: breakpoint-min(sm)) {
@include make-col-offset(1);
}
.pic {
text-align: center;
margin-bottom: 1em;
}
p {
hyphens: auto;
}
@extend .col-md-10;
@extend .offset-md-1;
@extend .col-xs-12;
padding: 1em;
ul {
margin: 0;
@ -130,17 +96,9 @@ body {
section {
border-top: 1px dashed #bbb;
}
.situation-start {
.room-start {
border-top: none;
}
img.right {
float: right;
margin: 1.1em 0 1.1em 1.1em;
}
img.left {
float: left;
margin: 1.1em 1.1em 1.1em 0;
}
h3 {
text-align: center;
}
@ -150,24 +108,15 @@ body {
color: darken($body-color, 10%);
font-size: smaller;
#footleft {
@media (min-width: breakpoint-min(sm)) {
@include make-col-offset(2);
@include make-col(5);
}
@media (max-width: breakpoint-max(xs)) {
@include make-col(12);
}
@extend .col-md-5;
@extend .offset-md-2;
@extend .col-xs-12;
}
#footright {
text-align: right;
@media (min-width: breakpoint-min(sm)) {
@include make-col(3);
@include make-col-offset(2);
}
@media (max-width: breakpoint-max(xs)) {
@include make-col(12);
margin-bottom: 1em;
}
@extend .col-md-2;
@extend .offset-md-2;
@extend .col-xs-12;
}
}