Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
1j01 committed Apr 22, 2016
1 parent c6c70f3 commit 7ee4710
Show file tree
Hide file tree
Showing 11 changed files with 568 additions and 0 deletions.
78 changes: 78 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@

node_modules/

# Logs
logs
*.log

# Runtime data
pids
*.pid
*.seed

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage

# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Compiled binary addons (http://nodejs.org/api/addons.html)
build/Release

# Dependency directory
# Commenting this out is preferred by some people, see
# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git-
node_modules

# Users Environment Variables
.lock-wscript

# =========================
# Operating System Files
# =========================

# OSX
# =========================

.DS_Store
.AppleDouble
.LSOverride

# Thumbnails
._*

# Files that might appear on external disk
.Spotlight-V100
.Trashes

# Directories potentially created on remote AFP share
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk

# Windows
# =========================

# Windows image file caches
Thumbs.db
ehthumbs.db

# Folder config file
Desktop.ini

# Recycle Bin used on file shares
$RECYCLE.BIN/

# Windows Installer files
*.cab
*.msi
*.msm
*.msp

# Windows shortcuts
*.lnk
44 changes: 44 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@

# Card Game Generator

A tool for developing card games for and along with [Tabletop Simulator][].

Use HTML or SVG templates to create and render custom decks of cards
and style them with CSS.


## Installation

* Have [Node.js][] and create a project
* `npm install card-game-generator --save-dev`

<!--
## Import into Tabletop Simulator
Without installing, you can save [Card Game.json][] to `%USERPROFILE%\Documents\My Games\Tabletop Simulator\Saves\Chest\`
If installed, you can just `npm run export-to-tabletop-simulator`
In Tabletop Simulator, go to Host > Chest > Saved Objects and find Card Game.
## Update cards
* Edit `cards.json` and preview with `index.html`
* `npm run export`
* `npm run export-to-tabletop-simulator`
<!-- When there are multiple card sets:
You can `set PARALLEL_EXPORT=ON` before running `export` to speed it up significantly **IF** it's on a powerful enough machine.
If it's not powerful enough it might freeze up the entire computer.
It needs a lot of video memory.
-->

## TODO

* API



[Node.js]: https://nodejs.org/en/
[Tabletop Simulator]: http://store.steampowered.com/app/286160/
3 changes: 3 additions & 0 deletions exporter/export.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<title>Exporting Cards</title>
<script src="../src/export.coffee" type="text/coffeescript"></script>
<script src="lib/coffee-script.js"></script>
12 changes: 12 additions & 0 deletions exporter/lib/coffee-script.js

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions exporter/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"name": "card-game-exporter",
"version": "0.0.0",
"description": "Just the nw-based exporting component of card-game-exporter",
"main": "export.html"
}
36 changes: 36 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Cards</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="styles/reset.css">
<link rel="stylesheet" href="styles/cards.css">
<link rel="stylesheet" href="styles/counters.css">
<style type="text/css">
body, html {
width: 100%;
height: 100%;
margin: 0;
border: 0;
padding: 0;
font-family: "Helvetica";
text-align: center;
}
.card {
display: inline-block;
vertical-align: bottom;
margin: 0.5cm;
}
h2 {
font-size: 2em;
margin: 0.2em;
}
</style>
</head>
<body>
<script src="lib/jquery-2.1.1.min.js"></script>
<script src="lib/coffee-script.js"></script>
<script src="src/render.coffee" type="text/coffeescript"></script>
</body>
</html>
16 changes: 16 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"name": "card-game-generator",
"version": "0.1.0",
"description": "A card game development toolkit",
"scripts": {},
"main": "src/card-game-generator.coffee",
"devDependencies": {
"async": "^1.5.2",
"coffee-script": "^1.10.0",
"nw": "^0.12.3"
},
"os": "win32",
"dependencies": {
"mkdirp": "^0.5.1"
}
}
45 changes: 45 additions & 0 deletions src/card-game-generator.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@

mkdirp = require "mkdirp"
fs = require "fs"
path = require "path"
{spawn} = require "child_process"
nw = (require "nw").findpath()
create_save = require "./create-save"

# TODO: cross-platform!
ts_folder = "#{process.env.USERPROFILE}/Documents/My Games/Tabletop Simulator"

module.exports =
class CardGameGenerator
constructor: ({@cardSets, @counters, @imagesURL, @exportedImagesURL, @saveName})->
@counters ?= {}

export: ({page, exportFolder, cardWidth, cardHeight, scale, debug}, callback)->
exportFolder = path.resolve(exportFolder)
page = path.resolve(page)
mkdirp(exportFolder)
mkdirp(page)
json_args = JSON.stringify({@cardSets, page, exportFolder, cardWidth, cardHeight, scale, debug})
nw_process = spawn(nw, [path.join(__dirname, "../exporter"), json_args])
nw_process.on "error", callback
nw_process.on "exit", (code)->
callback() if code is 0

exportToTabletopSimulator: ({exportFolder, saveName})->
exportFolder = path.resolve(exportFolder)

save = create_save({@imagesURL, @exportedImagesURL, @cardSets})

save_json = JSON.stringify(save, null, 2)

fs.writeFileSync "#{exportFolder}/#{saveName}.json", save_json, "utf8"

chest_folder = "#{ts_folder}/Saves/Chest"
fs.writeFileSync "#{chest_folder}/#{saveName}.json", save_json, "utf8"

@clearTabletopSimulatorCache()

clearTabletopSimulatorCache: ->
cache_folder = "#{ts_folder}/Mods/Images"
for fname in fs.readdirSync cache_folder
fs.unlinkSync "#{cache_folder}/#{fname}"
Loading

0 comments on commit 7ee4710

Please sign in to comment.