mirror of
https://github.com/sbrow/ps.git
synced 2025-12-29 18:47:38 -05:00
First upload
This commit is contained in:
70
ps.go
Normal file
70
ps.go
Normal file
@@ -0,0 +1,70 @@
|
||||
package ps
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path"
|
||||
"runtime"
|
||||
"strings"
|
||||
)
|
||||
|
||||
const (
|
||||
Cmd = "cscript.exe"
|
||||
Opts = "/nologo"
|
||||
)
|
||||
|
||||
var PKGPATH = path.Join(os.Getenv("GOPATH"), "/src/github.com/sbrow/skirmish/ps")
|
||||
|
||||
func Start() error {
|
||||
_, err := run("start")
|
||||
return err
|
||||
}
|
||||
|
||||
func Open(path string) ([]byte, error) {
|
||||
return run("open", path)
|
||||
}
|
||||
|
||||
func Close() error {
|
||||
_, err := run("close")
|
||||
return err
|
||||
}
|
||||
|
||||
func Quit() ([]byte, error) {
|
||||
return run("quit")
|
||||
}
|
||||
|
||||
func Js(args ...string) ([]byte, error) {
|
||||
return run("dojs", args...)
|
||||
}
|
||||
func Wait(msg string) {
|
||||
fmt.Print(msg)
|
||||
var input string
|
||||
fmt.Scanln(&input)
|
||||
}
|
||||
|
||||
func run(name string, args ...string) ([]byte, error) {
|
||||
var ext string
|
||||
var dir string
|
||||
var out bytes.Buffer
|
||||
var stderr bytes.Buffer
|
||||
|
||||
switch runtime.GOOS {
|
||||
case "windows":
|
||||
ext = ".vbs"
|
||||
dir = "win"
|
||||
case "darwin":
|
||||
ext = ".applescript"
|
||||
dir = "mac"
|
||||
}
|
||||
if !strings.HasSuffix(name, ext) {
|
||||
name += ext
|
||||
}
|
||||
args = append([]string{Opts, path.Join(PKGPATH, dir, name)}, args...)
|
||||
cmd := exec.Command(Cmd, args...)
|
||||
cmd.Stdout = &out
|
||||
cmd.Stderr = &stderr
|
||||
err := cmd.Run()
|
||||
return out.Bytes(), err
|
||||
}
|
||||
59
ps_test.go
Normal file
59
ps_test.go
Normal file
@@ -0,0 +1,59 @@
|
||||
package ps
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"path"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
// TODO: Comparison borked
|
||||
func TestRun(t *testing.T) {
|
||||
out := []byte("Testing...\n")
|
||||
msg, err := run("test")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if string(msg) == string(out) {
|
||||
fail := fmt.Sprintf("run(test)\ngot:\t\"%s\"\nwant:\t\"%s\"\n", msg, out)
|
||||
t.Fatal(fail)
|
||||
}
|
||||
}
|
||||
|
||||
func TestOpen(t *testing.T) {
|
||||
if testing.Short() {
|
||||
t.Skip("Skipping \"TestOpen\"")
|
||||
}
|
||||
Open("F:\\GitLab\\dreamkeepers-psd\\Template009.1.psd")
|
||||
}
|
||||
|
||||
func TestQuit(t *testing.T) {
|
||||
if testing.Short() {
|
||||
t.Skip("Skipping \"TestQuit\"")
|
||||
}
|
||||
Quit()
|
||||
}
|
||||
|
||||
func TestWait(t *testing.T) {
|
||||
Wait("Waiting...")
|
||||
}
|
||||
|
||||
// TODO: Comparison borked
|
||||
func TestJS(t *testing.T) {
|
||||
out := "Testing...\n"
|
||||
_, err := Js(path.Join(Folder, "test.jsx"), Folder)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
f, err := ioutil.ReadFile(path.Join(Folder, "test.txt"))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if strings.Compare(string(f), string(out)) != 0 {
|
||||
fmt.Println(f)
|
||||
fmt.Println([]byte(out))
|
||||
fail := fmt.Sprintf("TestJS failed.\ngot:\t\"%s\"\nwant:\t\"%s\"", f, out)
|
||||
t.Fatal(fail)
|
||||
}
|
||||
}
|
||||
3
win/close.vbs
Normal file
3
win/close.vbs
Normal file
@@ -0,0 +1,3 @@
|
||||
set App = CreateObject("Photoshop.Application")
|
||||
set Doc = App.activeDocument
|
||||
Doc.Close
|
||||
10
win/dojs.vbs
Normal file
10
win/dojs.vbs
Normal file
@@ -0,0 +1,10 @@
|
||||
|
||||
Dim app
|
||||
Set app = CreateObject("Photoshop.Application")
|
||||
if WScript.Arguments.Count = 0 then
|
||||
WScript.Echo "Missing parameters"
|
||||
else
|
||||
path = wScript.Arguments(0)
|
||||
folder = wScript.Arguments(1)
|
||||
app.DoJavaScriptFile path, Array(Folder)
|
||||
end if
|
||||
9
win/open.vbs
Normal file
9
win/open.vbs
Normal file
@@ -0,0 +1,9 @@
|
||||
' Open photoshop.
|
||||
Set app = CreateObject("Photoshop.Application")
|
||||
if WScript.Arguments.Count = 0 then
|
||||
WScript.Echo "Missing parameters"
|
||||
else
|
||||
path = wScript.Arguments(0)
|
||||
Set doc = app.Open(path)
|
||||
wScript.echo doc.Name
|
||||
end if
|
||||
9
win/quit.vbs
Normal file
9
win/quit.vbs
Normal file
@@ -0,0 +1,9 @@
|
||||
' Close Photoshop
|
||||
Set appRef = CreateObject("Photoshop.Application")
|
||||
|
||||
wScript.echo appRef.Documents.Count
|
||||
Do While appRef.Documents.Count > 0
|
||||
appRef.ActiveDocument.Close(2)
|
||||
Loop
|
||||
|
||||
appRef.Quit()
|
||||
1
win/start.vbs
Normal file
1
win/start.vbs
Normal file
@@ -0,0 +1 @@
|
||||
set app = CreateObject("Photoshop.Application")
|
||||
122
win/syncCards.jsx
Normal file
122
win/syncCards.jsx
Normal file
@@ -0,0 +1,122 @@
|
||||
#target Photshop
|
||||
|
||||
try {
|
||||
/**
|
||||
* Make window
|
||||
* @todo read data from the template PSD's data sets.
|
||||
* @type {Window}
|
||||
*/
|
||||
var win = new Window('dialog','Sync Skirmish Cards');
|
||||
var panel = win.add('tabbedpanel');
|
||||
|
||||
//Make main tab tab that updates folders at a time.
|
||||
var main = panel.add('tab', undefined, 'Main');
|
||||
|
||||
//Get our list of deck names.
|
||||
var deckNames = (JSON_FOLDER.toString().replace(/\/[^,]*\//g, '').replace(/.json/g, '')).split(',');
|
||||
var decks = [];
|
||||
var deckJSONs = {};
|
||||
var index = 0;
|
||||
for (var i in deckNames) {
|
||||
if (deckNames[i] != 'Formatting' && deckNames[i] != 'desktop.ini' && deckNames[i] != 'old') {
|
||||
var filePath = '{0}/{1}.json'.format(JSON_PATH, deckNames[i]);
|
||||
var fileObj = loadJSON(filePath, true);
|
||||
deckJSONs[deckNames[i]] = fileObj;
|
||||
decks[index++] = deckNames[i];
|
||||
var deckTab = panel.add('tab', undefined, deckNames[i]);
|
||||
for (var card in deckJSONs[deckNames[i]]) {
|
||||
deckTab.add('checkbox', undefined, deckJSONs[deckNames[i]][card].Name);
|
||||
}
|
||||
}
|
||||
}
|
||||
/*
|
||||
//Button to select everything.
|
||||
main.everything = main.add('checkbox', undefined, 'Everything');
|
||||
main.everything.onClick = function() {
|
||||
main.leaders.value = main.everything.value;
|
||||
main.decks.allDecks.value = main.everything.value;
|
||||
main.decks.allDecks.onClick();
|
||||
};*/
|
||||
|
||||
//Button to select all leaders.
|
||||
//main.leaders = main.add('checkbox', undefined, 'Leaders')
|
||||
|
||||
//Section listing all the available decks
|
||||
main.decks = main.add('panel', undefined, "Decks");
|
||||
|
||||
//Button that selects all Decks.
|
||||
main.decks.allDecks = main.decks.add('checkbox', undefined, 'All');
|
||||
|
||||
//Generates checkbox for each deck.
|
||||
for (var deck in decks)
|
||||
var deckBox = main.decks.add('checkbox', undefined, decks[deck]);
|
||||
|
||||
//Generates a checkbox for each card.
|
||||
for (var i=1; i<decks.length+1; i++) {
|
||||
main.decks.children[i].onClick = function() {
|
||||
for (var k=1; k<main.decks.children.length; k++)
|
||||
if (main.decks.children[k].text == panel.children[k].text)
|
||||
for (var j=0; j<panel.children[k].children.length; j++)
|
||||
panel.children[k].children[j].value = main.decks.children[k].value;
|
||||
};
|
||||
}
|
||||
|
||||
main.decks.allDecks.onClick = function() {
|
||||
for (var box=1; box < decks.length+1; box++) {
|
||||
main.decks.children[box].value = main.decks.allDecks.value;
|
||||
main.decks.children[box].onClick();
|
||||
}
|
||||
}
|
||||
|
||||
//Button to cancel the operation.
|
||||
main.cancel = main.add('Button', undefined, 'Cancel');
|
||||
|
||||
//Button to compile the chosen cards.
|
||||
main.compile = main.add ('Button',undefined, 'Compile');
|
||||
main.compile.onClick = function() {
|
||||
LOG.debug('', $.fileName);
|
||||
|
||||
var ret = {};
|
||||
var leaders = HEROES_JSON;
|
||||
for (var i=1; i<panel.children.length; i++) {
|
||||
if (i != 2) {
|
||||
ret[decks[i-1]] = deckJSONs[decks[i-1]];
|
||||
for (var j=panel.children[i].children.length-1; j>=0; j--)
|
||||
if (panel.children[i].children[j].value == false)
|
||||
ret[decks[i-1]].splice(j, 1);
|
||||
}
|
||||
}
|
||||
for (var i=panel.children[2].children.length-1; i>=0; i--) {
|
||||
if (panel.children[2].children[i].value == false)
|
||||
leaders.splice(i, 1);
|
||||
}
|
||||
if (isEmpty(ret) && isEmpty(leaders))
|
||||
alert('Must select something');
|
||||
else {
|
||||
win.close();
|
||||
compileDecks(ret, leaders);
|
||||
}
|
||||
}
|
||||
|
||||
win.center();
|
||||
|
||||
function compileDecks(decks, leaders) {
|
||||
LOG.log('SYNCING SKIRMISH FILES...', '-');
|
||||
if (decks)
|
||||
try {
|
||||
var t0 = new Date().getTime()
|
||||
sync(decks, true, LOG);
|
||||
var t1 = new Date().getTime()
|
||||
LOG.log("TIME: " + (t1 - t0))
|
||||
} catch (e) {
|
||||
LOG.err(e);
|
||||
}
|
||||
if(leaders) {
|
||||
syncLeaders(leaders, LOG);
|
||||
}
|
||||
}
|
||||
win.show();
|
||||
} catch (e) {
|
||||
alert(e.LineNumber + " " + e.message);
|
||||
LOG.err(e);
|
||||
}
|
||||
11
win/test.jsx
Normal file
11
win/test.jsx
Normal file
@@ -0,0 +1,11 @@
|
||||
var Path = arguments[0];
|
||||
alert(Path)
|
||||
var saveFile = File(Path + "/test.txt");
|
||||
|
||||
if(saveFile.exists)
|
||||
saveFile.remove();
|
||||
|
||||
saveFile.encoding = "UTF8";
|
||||
saveFile.open("e", "TEXT", "????");
|
||||
saveFile.writeln("Testing...");
|
||||
saveFile.close();
|
||||
1
win/test.txt
Normal file
1
win/test.txt
Normal file
@@ -0,0 +1 @@
|
||||
Testing...
|
||||
1
win/test.vbs
Normal file
1
win/test.vbs
Normal file
@@ -0,0 +1 @@
|
||||
wScript.echo "Testing..."
|
||||
Reference in New Issue
Block a user