Skip to content

Commit

Permalink
init: simple workspace with completly separate components
Browse files Browse the repository at this point in the history
  • Loading branch information
alshakh committed May 7, 2015
0 parents commit 6e893df
Show file tree
Hide file tree
Showing 29 changed files with 298 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
js/*
16 changes: 16 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@


all: coreLib symbolLib editorLib testsLib


coreLib:
(cd components/Core; make all)

symbolLib:
(cd components/Symbol; make all)

editorLib:
(cd components/Editor; make all)

testsLib:
(cd components/Tests; make all)
15 changes: 15 additions & 0 deletions components/Core/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
OutputName=coreLib
SourceFiles=src/Core.ts src/Fragment.ts src/Paper.ts
BaseDir=../..
OutputDir=$(BaseDir)/js
Out=$(OutputDir)/$(OutputName).js

all: $(Out)

$(Out): lib.ts $(SourceFiles)
tsc --declaration --sourceMap --out $@ lib.ts
sed -i "/\/\/\/\ *<reference/d" $(OutputDir)/$(OutputName).d.ts #reused as source for other components
cp -f $(OutputDir)/$(OutputName).d.ts ../declareFiles/

clean:
rm $(OUT)
3 changes: 3 additions & 0 deletions components/Core/lib.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/// <reference path="src/Core.ts" />
/// <reference path="src/Fragment.ts" />
/// <reference path="src/Paper.ts" />
4 changes: 4 additions & 0 deletions components/Core/src/Core.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

module Sanara.Core {
export type SanaraContext = CanvasRenderingContext2D;
}
24 changes: 24 additions & 0 deletions components/Core/src/Fragment.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/// <reference path="Paper.ts"/>

module Sanara.Core {
export interface Fragment {
paint(paper: Paper) : void;
paintMe(paper : Paper) : void;
}
export class BaseFragment implements Fragment {
children : [Fragment];
constructor (children : [Fragment] = <[Fragment]>[]) {
this.children = children;
}
paint(paper: Paper) {
paper.context.save();
this.paintMe(paper);
paper.context.restore();
}
paintMe(paper : Paper) {
this.children.forEach(function (v) {
v.paint(paper);
})
}
}
}
30 changes: 30 additions & 0 deletions components/Core/src/Paper.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/// <reference path="Fragment.ts" />


module Sanara.Core {
export interface Paper {
domElement : HTMLCanvasElement;
context : SanaraContext;
w : number;
h : number;
root : Fragment;
repaint(time:number) : void;
}
export class BasicPaper implements Paper {
domElement : HTMLCanvasElement;
context : SanaraContext;
w : number;
h : number;
root : Fragment;
constructor (w:number = 100, h:number = 100) {
this.w = w;
this.h = h;

this.domElement = <HTMLCanvasElement>document.createElement("canvas");
this.context = <SanaraContext>this.domElement.getContext("2d");
}
repaint(time:number = 0) : void {
this.root.paint(this);
}
}
}
17 changes: 17 additions & 0 deletions components/Core/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"compileOnSave": false,
"version": "1.5.0-alpha",
"compilerOptions": {
"target": "es5"
},
"filesGlob": [
"./**/*.ts",
"!./node_modules/**/*.ts"
],
"files": [
"./lib.ts",
"./src/Core.ts",
"./src/Fragment.ts",
"./src/Paper.ts"
]
}
15 changes: 15 additions & 0 deletions components/Editor/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
OutputName=editorLib
SourceFiles=src/Editor.ts
BaseDir=../..
OutputDir=$(BaseDir)/js
Out=$(OutputDir)/$(OutputName).js

all: $(Out)

$(Out): lib.ts $(SourceFiles)
tsc --removeComments --declaration --sourceMap --out $@ lib.ts
sed -i "/\/\/\/\ *<reference/d" $(OutputDir)/$(OutputName).d.ts #reused as source for other components
cp -f $(OutputDir)/$(OutputName).d.ts ../declareFiles/

clean:
rm $(OUT)
1 change: 1 addition & 0 deletions components/Editor/declareFiles/coreLib.d.ts
1 change: 1 addition & 0 deletions components/Editor/lib.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/// <reference path="src/Editor.ts" />
1 change: 1 addition & 0 deletions components/Editor/src/Editor.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/// <reference path="../declareFiles/coreLib.d.ts"/>
16 changes: 16 additions & 0 deletions components/Editor/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"compileOnSave": false,
"version": "1.5.0-alpha",
"compilerOptions": {
"target": "es5"
},
"filesGlob": [
"./**/*.ts",
"!./node_modules/**/*.ts"
],
"files": [
"./declareFiles/coreLib.d.ts",
"./lib.ts",
"./src/Editor.ts"
]
}
16 changes: 16 additions & 0 deletions components/Symbol/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
OutputName=symbolLib
SourceFiles=src/Rect.ts

BaseDir=../..
OutputDir=$(BaseDir)/js
Out=$(OutputDir)/$(OutputName).js

all: $(Out)

$(Out): lib.ts $(SourceFiles)
tsc --removeComments --declaration --sourceMap --out $@ lib.ts
sed -i "/\/\/\/\ *<reference/d" $(OutputDir)/$(OutputName).d.ts #reused as source for other components
cp -f $(OutputDir)/$(OutputName).d.ts ../declareFiles/

clean:
rm $(OUT)
1 change: 1 addition & 0 deletions components/Symbol/declareFiles/coreLib.d.ts
1 change: 1 addition & 0 deletions components/Symbol/lib.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/// <reference path="src/Rect.ts"/>
16 changes: 16 additions & 0 deletions components/Symbol/src/Rect.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/// <reference path="../declareFiles/coreLib.d.ts" />

module Sanara.Symbol {
export class Rect extends Sanara.Core.BaseFragment {
w : number;
h : number;
constructor(w: number=100, h: number=100){
super();
this.w = w;
this.h = h;
}
paintMe (paper : Sanara.Core.Paper) {
paper.context.fillRect(0,0,this.w,this.h);
}
}
}
16 changes: 16 additions & 0 deletions components/Symbol/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"compileOnSave": false,
"version": "1.5.0-alpha",
"compilerOptions": {
"target": "es5"
},
"filesGlob": [
"./**/*.ts",
"!./node_modules/**/*.ts"
],
"files": [
"./declareFiles/coreLib.d.ts",
"./lib.ts",
"./src/Rect.ts"
]
}
15 changes: 15 additions & 0 deletions components/Tests/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
OutputName=testsLib
SourceFiles=src/simplePaper.ts

BaseDir=../..
OutputDir=$(BaseDir)/js
Out=$(OutputDir)/$(OutputName).js

all: $(Out)

$(Out): lib.ts $(SourceFiles)
tsc --declaration --sourceMap --out $@ lib.ts
cp -f $(OutputDir)/$(OutputName).d.ts ../declareFiles/

clean:
rm $(OUT)
1 change: 1 addition & 0 deletions components/Tests/declareFiles/coreLib.d.ts
1 change: 1 addition & 0 deletions components/Tests/declareFiles/symbolLib.d.ts
1 change: 1 addition & 0 deletions components/Tests/lib.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/// <reference path="src/simplePaper.ts" />
10 changes: 10 additions & 0 deletions components/Tests/src/simplePaper.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/// <reference path="../declareFiles/coreLib.d.ts" />
/// <reference path="../declareFiles/symbolLib.d.ts" />

module Sanara.Tests {
export var simplePaper = (function () {
var paper = new Sanara.Core.BasicPaper(1000,1000);
paper.root = new Sanara.Symbol.Rect(122,500);
return paper;
})();
}
17 changes: 17 additions & 0 deletions components/Tests/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"compileOnSave": false,
"version": "1.5.0-alpha",
"compilerOptions": {
"target": "es5"
},
"filesGlob": [
"./**/*.ts",
"!./node_modules/**/*.ts"
],
"files": [
"./declareFiles/coreLib.d.ts",
"./declareFiles/symbolLib.d.ts",
"./lib.ts",
"./src/simplePaper.ts"
]
}
34 changes: 34 additions & 0 deletions components/declareFiles/coreLib.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
declare module Sanara.Core {
type SanaraContext = CanvasRenderingContext2D;
}
declare module Sanara.Core {
interface Paper {
domElement: HTMLCanvasElement;
context: SanaraContext;
w: number;
h: number;
root: Fragment;
repaint(time: number): void;
}
class BasicPaper implements Paper {
domElement: HTMLCanvasElement;
context: SanaraContext;
w: number;
h: number;
root: Fragment;
constructor(w?: number, h?: number);
repaint(time?: number): void;
}
}
declare module Sanara.Core {
interface Fragment {
paint(paper: Paper): void;
paintMe(paper: Paper): void;
}
class BaseFragment implements Fragment {
children: [Fragment];
constructor(children?: [Fragment]);
paint(paper: Paper): void;
paintMe(paper: Paper): void;
}
}
Empty file.
8 changes: 8 additions & 0 deletions components/declareFiles/symbolLib.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
declare module Sanara.Symbol {
class Rect extends Sanara.Core.BaseFragment {
w: number;
h: number;
constructor(w?: number, h?: number);
paintMe(paper: Sanara.Core.Paper): void;
}
}
5 changes: 5 additions & 0 deletions components/declareFiles/testsLib.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/// <reference path="../components/Tests/declareFiles/coreLib.d.ts" />
/// <reference path="../components/Tests/declareFiles/symbolLib.d.ts" />
declare module Sanara.Tests {
var simplePaper: Core.BasicPaper;
}
12 changes: 12 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@

<html>
<body>
<script src="js/coreLib.js"></script>
<script src="js/symbolLib.js"></script>
<script src="js/testsLib.js"></script>
<script>
document.body.appendChild(Sanara.Tests.simplePaper.domElement);
Sanara.Tests.simplePaper.repaint();
</script>
</body>
</html>

0 comments on commit 6e893df

Please sign in to comment.