Skip to content

Commit

Permalink
open source microStudio, initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
pmgl committed Jul 13, 2021
0 parents commit ded9f13
Show file tree
Hide file tree
Showing 458 changed files with 88,064 additions and 0 deletions.
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
plugins/
server/.greenlockrc
server/greenlock.d
config.json
server/node_modules/
files/
data/
.DS_Store
21 changes: 21 additions & 0 deletions LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2021 Gilles Pommereuil

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.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
microStudio is a free, open source game engine online.
It is also a platform to learn and practise programming.

microStudio can be used for free at https://microstudio.dev

You can also install your own copy, to work locally or on your own server
for your team or classroom. You will find instructions below.

# Installing microStudio to work locally

* Install Node JS (downloads and instructions: https://nodejs.org/en/download/)
* clone this repository
* `cd microstudio/server`
* `npm install`
* `node server.js`
5 changes: 5 additions & 0 deletions config_local.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"realm": "local",
"dev-domain": "localhost:8080",
"run-domain": "localhost:8080"
}
7 changes: 7 additions & 0 deletions config_prod.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"realm": "production",
"dev-domain": "yourdevdomain.com",
"run-domain": "youroutputdomain.com",
"backup-key": "your_backup_service_key",
"builder-key": "your_builder_service_key"
}
259 changes: 259 additions & 0 deletions server/app/exportfeatures.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,259 @@
#fs = require "fs"

JSZip = require "jszip"
pug = require "pug"
JobQueue = require __dirname+"/jobqueue.js"
{ createCanvas, loadImage } = require('canvas')

class @ExportFeatures
constructor:(@webapp)->
@addSpritesExport()
@addPublishHTML()

addSpritesExport:()->
# /user/project[/code]/export/sprites/
@webapp.app.get /^\/[^\/\|\?\&\.]+\/[^\/\|\?\&\.]+\/([^\/\|\?\&\.]+\/)?export\/sprites\/$/,(req,res)=>
access = @webapp.getProjectAccess req,res
return if not access?

user = access.user
project = access.project
manager = @webapp.getProjectManager(project)

zip = new JSZip

queue = new JobQueue ()=>
zip.generateAsync({type:"nodebuffer"}).then (content)=>
res.setHeader("Content-Type", "application/zip")
res.setHeader("Content-Disposition","attachement; filename=\"#{project.slug}_sprites.zip\"")
res.send content

queue.add ()=>
manager.listFiles "sprites",(sprites)=>
for s in sprites
do (s)=>
queue.add ()=>
console.info "reading: "+JSON.stringify s
@webapp.server.content.files.read "#{user.id}/#{project.id}/sprites/#{s.file}","binary",(content)=>
if content?
zip.file(s.file,content)
queue.next()
queue.next()

queue.add ()=>
manager.listFiles "doc",(docs)=>
for doc in docs
do (doc)=>
queue.add ()=>
console.info "reading: "+JSON.stringify doc
@webapp.server.content.files.read "#{user.id}/#{project.id}/doc/#{doc.file}","text",(content)=>
if content?
zip.file(doc.file,content)
queue.next()
queue.next()

queue.start()

addPublishHTML:()->
# /user/project[/code]/publish/html/
@webapp.app.get /^\/[^\/\|\?\&\.]+\/[^\/\|\?\&\.]+\/([^\/\|\?\&\.]+\/)?publish\/html\/$/,(req,res)=>
access = @webapp.getProjectAccess req,res
return if not access?

user = access.user
project = access.project
manager = @webapp.getProjectManager(project)

zip = new JSZip
# icon16,32,64,180,192,512,1024.png
# manifest.json
maps_dict = {}
images = []
assets = []
fonts = []
sounds_list = []
music_list = []
fullsource = "\n\n"

queue = new JobQueue ()=>
resources = JSON.stringify
images: images
assets: assets
maps: maps_dict
sounds: sounds_list
music: music_list

resources = "var resources = #{resources};\n"
resources += "var graphics = \"#{project.graphics}\";\n"

export_funk = pug.compileFile "../templates/export/html.pug"

html = export_funk
user: user
javascript_files: ["microengine.js"]
fonts: fonts
game:
name: project.slug
title: project.title
author: user.nick
resources: resources
orientation: project.orientation
aspect: project.aspect
code: fullsource

zip.file("index.html",html)

mani = @webapp.manifest_template.toString().replace(/SCOPE/g,"")
mani = mani.toString().replace("APPNAME",project.title)
mani = mani.toString().replace("APPSHORTNAME",project.title)
mani = mani.toString().replace("ORIENTATION",project.orientation)
mani = mani.toString().replace(/USER/g,user.nick)
mani = mani.toString().replace(/PROJECT/g,project.slug)
mani = mani.toString().replace(/ICONVERSION/g,"0")
mani = mani.replace("START_URL",".")

zip.file("manifest.json",mani)

if project.graphics == "M3D"
zip.file("microengine.js",@webapp.concatenator["player3d_js_concat"])
else
zip.file("microengine.js",@webapp.concatenator["player_js_concat"])

zip.generateAsync({type:"nodebuffer"}).then (content)=>
res.setHeader("Content-Type", "application/zip")
res.setHeader("Content-Disposition","attachement; filename=\"#{project.slug}.zip\"")
res.setHeader("Cache-Control","no-cache")
res.send content

queue.add ()=>
manager.listFiles "sprites",(sprites)=>
for s in sprites
do (s)=>
queue.add ()=>
console.info "reading: "+JSON.stringify s
@webapp.server.content.files.read "#{user.id}/#{project.id}/sprites/#{s.file}","binary",(content)=>
if content?
zip.file("sprites/#{s.file}",content)
images.push s
queue.next()
queue.next()

queue.add ()=>
manager.listFiles "maps",(maps)=>
for map in maps
do (map)=>
queue.add ()=>
console.info "reading: "+JSON.stringify map
@webapp.server.content.files.read "#{user.id}/#{project.id}/maps/#{map.file}","text",(content)=>
if content?
maps_dict[map.file.split(".")[0]] = content
queue.next()
queue.next()

queue.add ()=>
manager.listFiles "sounds",(sounds)=>
for s in sounds
do (s)=>
queue.add ()=>
console.info "reading: "+JSON.stringify s
@webapp.server.content.files.read "#{user.id}/#{project.id}/sounds/#{s.file}","binary",(content)=>
if content?
zip.file("sounds/#{s.file}",content)
sounds_list.push s
queue.next()
queue.next()

queue.add ()=>
manager.listFiles "music",(music)=>
for m in music
do (m)=>
queue.add ()=>
console.info "reading: "+JSON.stringify m
@webapp.server.content.files.read "#{user.id}/#{project.id}/music/#{m.file}","binary",(content)=>
if content?
zip.file("music/#{m.file}",content)
music_list.push m
queue.next()
queue.next()

queue.add ()=>
manager.listFiles "assets",(assets)=>
for asset in assets
do (asset)=>
queue.add ()=>
console.info "reading: "+JSON.stringify asset
@webapp.server.content.files.read "#{user.id}/#{project.id}/assets/#{asset.file}","binary",(content)=>
if content?
zip.file("assets/#{asset.file}",content)
assets.push asset
queue.next()
queue.next()

queue.add ()=>
manager.listFiles "doc",(docs)=>
for doc in docs
do (doc)=>
queue.add ()=>
console.info "reading: "+JSON.stringify doc
@webapp.server.content.files.read "#{user.id}/#{project.id}/doc/#{doc.file}","text",(content)=>
if content?
zip.file(doc.file,content)
queue.next()
queue.next()

queue.add ()=>
manager.listFiles "ms",(ms)=>
for src in ms
do (src)=>
queue.add ()=>
console.info "reading: "+JSON.stringify src
@webapp.server.content.files.read "#{user.id}/#{project.id}/ms/#{src.file}","text",(content)=>
if content?
fullsource += content+"\n\n"
queue.next()

queue.add ()=>
for font in @webapp.fonts.fonts
if font == "BitCell" or fullsource.indexOf("\"#{font}\"")>=0
fonts.push font
do (font)=>
queue.add ()=>
console.info "reading font: #{font}"
@webapp.fonts.read font,(data)=>
if data?
zip.file "fonts/#{font}.ttf",data
queue.next()

queue.next()

queue.next()

queue.add ()=>
path = "#{user.id}/#{project.id}/sprites/icon.png"
path = @webapp.server.content.files.sanitize path
loadImage("../files/#{path}").then ((image)=>
for size in [16,32,64,180,192,512,1024]
do (size)=>
queue.add ()=>
canvas = createCanvas(size,size)
context = canvas.getContext "2d"
context.antialias = "none"
context.imageSmoothingEnabled = false
if image?
context.drawImage image,0,0,size,size

if size>100
context.antialias = "default"
context.globalCompositeOperation = "destination-in"
@webapp.fillRoundRect context,0,0,size,size,size/8

canvas.toBuffer (err,result)=>
zip.file "icon#{size}.png",result
queue.next()
),(error)=>
queue.next()
queue.next()

queue.start()

module.exports = @ExportFeatures
Loading

0 comments on commit ded9f13

Please sign in to comment.