initialize Improv

This commit is contained in:
Alexander Yakovlev 2018-07-13 21:45:37 +07:00
parent 20500ec141
commit 19588cd17b
7 changed files with 1256 additions and 200 deletions

View file

@ -1,16 +1,32 @@
watchify = require('watchify')
browserify = require('browserify')
browserSync = require('browser-sync')
gulp = require('gulp')
gutil = require('gulp-util')
coffee = require("gulp-coffee")
coffeify = require('coffeeify')
sass = require('gulp-sass')
uglify = require('gulp-uglify')
zip = require('gulp-zip')
concat = require('gulp-concat')
rename = require('gulp-rename')
source = require('vinyl-source-stream')
fs = require 'fs'
reload = browserSync.reload
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'))
html = (target, debug) ->
return () ->
sources = [
@ -80,11 +96,10 @@ gulp.task('concatCoffee', () ->
.pipe(gulp.dest('./build/game'))
)
gulp.task('coffee', ['concatCoffee'], () ->
gulp.src('./build/game/main.coffee')
.pipe(coffee({bare: true}))
.pipe(gulp.dest('./build/game/'))
)
bundler.on('update', bundle)
bundler.on('log', gutil.log)
gulp.task('coffee', ['concatCoffee'], bundle)
gulp.task('build', [
'html'

View file

@ -1,6 +1,7 @@
###
# This is the file with all thing *around* Salet.
###
Improv = require('improv')
salet.game_id = "2868be0e-0011-4d94-87a9-1a80f65ff7f0"
salet.game_version = "1.0"

View file

@ -193,3 +193,141 @@ sysroom "map",
text: () -> """
Здесь будет карта
"""
Array.prototype.remove = (args...) ->
output = []
for arg in args
index = @indexOf arg
output.push @splice(index, 1) if index isnt -1
output = output[0] if args.length is 1
output
Array.prototype.shuffle = () ->
i = this.length
while --i > 0
j = ~~(salet.rnd.randf() * (i + 1))
t = this[j]
this[j] = this[i]
this[i] = t
this
# Volume from 0 to 1
get_volume = () ->
return ($('#slider').slider('value') - 1) / 100
window.set_volume = (value) ->
document.getElementById("bgsound").volume = (value / 100)
volume = $('.voldisplay')
if value <= 5
volume.css('background-position', '0 0')
else if value <= 25
volume.css('background-position', '0 -25px')
else if value <= 75
volume.css('background-position', '0 -50px')
else
volume.css('background-position', '0 -75px')
update_paths = (character) ->
x = character.x
y = character.y
maze = character.maze
if maze.isEast(x,y)
text = "east".l()
if not character.has("compass")
eastCell = character.getCell(x+1,y)
type = eastCell.getTag("type")
text = "#{type}".l()
$("#east").html("<a href='east'>#{text}</a>")
else
$("#east").html("")
if maze.isWest(x,y)
text = "west".l()
if not character.has("compass")
westCell = character.getCell(x-1,y)
type = westCell.getTag("type")
text = "#{type}".l()
$("#west").html("<a href='west'>#{text}</a>")
else
$("#west").html("")
if maze.isNorth(x,y)
text = "north".l()
if not character.has("compass")
northCell = character.getCell(x,y-1)
type = northCell.getTag("type")
text = "#{type}".l()
$("#north").html("<a href='north'>#{text}</a>")
else
$("#north").html("")
if maze.isSouth(x,y)
text = "south".l()
if not character.has("compass")
southCell = character.getCell(x,y+1)
type = southCell.getTag("type")
text = "#{type}".l()
$("#south").html("<a href='south'>#{text}</a>")
else
$("#south").html("")
return
typeIsArray = ( value ) ->
value and
typeof value is 'object' and
value instanceof Array and
typeof value.length is 'number' and
typeof value.splice is 'function' and
not ( value.propertyIsEnumerable 'length' )
###
# Improv's mismatchFilter with tag options.
# Ensures that the group and model don't have any mismatched tags.
# Returns null if found a mismatch between model tag and the group.
# Every match counts as +1 to the score offset.
# Returns 0 if unsure.
#
# Unlike the default mismatchFilter, it allows tags like this:
#
# ['to', ['thickforest', 'rareforest', 'deepforest']]
#
###
tagMismatchFilter = (group, model) ->
score = 0
if group.tags.length == 0
return 0
for groupTag in group.tags
for modelTag in model.tags
if modelTag[0] != groupTag[0]
continue
modelTag = modelTag[1]
groupTag = groupTag[1]
if typeIsArray(groupTag)
if groupTag.indexOf(modelTag) != -1
score = score + 1
else
return null
else
if modelTag != groupTag
return null
return score
setAdjacent = (model) ->
cells = {}
cells["north"] = salet.character.maze.getNorth(salet.character.x, salet.character.y)
cells["west"] = salet.character.maze.getWest(salet.character.x, salet.character.y)
cells["east"] = salet.character.maze.getEast(salet.character.x, salet.character.y)
cells["south"] = salet.character.maze.getSouth(salet.character.x, salet.character.y)
adjacent = []
for direction, cell of cells
if cell == false
continue
type = cell.getTag('type')
if adjacent.indexOf(type) != -1 # уже есть сосед этого типа
continue
adjacent.push(type)
model["#{type}_direction"] = "#{direction}".l()
model["#{type}_direction_instrumental"] = "#{direction}_instrumental".l()
model["#{type}_direction_genitive"] = "#{direction}_genitive".l()
model["#{type}_direction_vocative"] = "#{direction}_vocative".l()
model["#{type}_direction_adverb"] = "#{direction}_adverb".l()
model.tags.push(["adjacent", adjacent])
return model

View file

@ -47,13 +47,10 @@
<!-- CDN JS Libraries -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/marked/0.3.5/marked.min.js"></script>
<script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
<script src="game/improv/index.js"></script>
<script src="game/improv/filters.js"></script>
<script src="game/improv/template.js"></script>
<script src="game/salet.min.js"></script>
<script src="game/gamepad.min.js"></script>
<script src="https://togetherjs.com/togetherjs-min.js"></script>
<script type="text/javascript" defer="defer" src="game/main.js"></script>
<script type="text/javascript" defer="defer" src="game/bundle.js"></script>
</body>
</html>

View file

@ -56,7 +56,7 @@
<script src="https://code.jquery.com/qunit/qunit-2.3.3.js"></script>
<script src="game/salet.min.js"></script>
<script src="game/main.js"></script>
<script src="game/bundle.js"></script>
<script defer="defer" src="test/main.js"></script>

1279
package-lock.json generated

File diff suppressed because it is too large Load diff

View file

@ -1,7 +1,10 @@
{
"dependencies": {
"browserify": "^16.2.2",
"cson": "^5.1.0",
"improv": "^1.0.0"
"improv": "^1.0.0",
"vinyl-source-stream": "^2.0.0",
"watchify": "^3.11.0"
},
"private": true,
"devDependencies": {
@ -10,6 +13,7 @@
"coffee-script": "^1.12.7",
"gulp": "^3.8.11",
"gulp-coffee": "^2.3.4",
"coffeeify": "^2.1.0",
"gulp-concat": "^2.6.1",
"gulp-rename": "^1.2.2",
"gulp-sass": "^3.1.0",