Skip to content

Commit

Permalink
Don't ignore notes
Browse files Browse the repository at this point in the history
  • Loading branch information
shirakaba committed Mar 9, 2019
1 parent 010380e commit 6c1fc88
Show file tree
Hide file tree
Showing 3 changed files with 198 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -6,6 +6,7 @@ platforms/
# NativeScript Template
*.js.map
*.js
!notes/*.js
!webpack.config.js
*.css

Expand Down
102 changes: 102 additions & 0 deletions notes/SpriteKit.js
@@ -0,0 +1,102 @@
// SKScene is SpriteKit; SCN is SceneKit
// https://stackoverflow.com/questions/26225236/swift-spritekit-adding-button-programmatically
const ButtonTestScene = SKScene.extend(
{
initWithFrame(frame){
SKScene.prototype.init.apply(this, []);
// this.frame = frame; /* readonly */
// this.frame.size = frame.size;
// this.frame.size.x = frame.size.x;
// this.frame.size.y = frame.size.y;
this.frame.origin = frame.origin;
return this;
},
didMoveToView: function (view){
this.button = SKSpriteNode.alloc().initWithColorSize(
UIColor.alloc().initWithRedGreenBlueAlpha(1,0,0,1),
CGSizeMake(100, 44)
);

this.button.position = CGPointMake(
CGRectGetMidX(this.frame),
CGRectGetMidY(this.frame),
);

this.addChild(this.button);
},

// touchesEndedWithEvent(touches: NSSet<UITouch>, event: _UIEvent): void;
touchesEndedWithEvent: function (touches, event){
// Synchronous
touches.enumerateObjectsUsingBlock((touch, i) => {
const location = touch.locationInNode(this);
if(button.containsPoint(location)){
// Respond to tap somehow.
}
});
}
},
{
name: "ButtonTestScene",
protocols: [],
exposedMethods: {
"initWithFrame": {
params: [CGRect],
returns: SKScene
}
}
}
);

ButtonTestScene.alloc().initWithFrame(CGRectMake(2, 2, 25, 25));


const GameViewController = UIViewController.extend(
{
viewDidLoad: function(){
UIViewController.prototype.viewDidLoad.apply(this, arguments);

this.view = SKView.alloc().initWithFrame(this.view.bounds);
if(this.view instanceof SKView){
const scene =
}
}
},
{
name: "GameViewController",
protocols: []
}
);

new GameViewController();


// https://stackoverflow.com/questions/53104428/spritekit-example-without-storyboard
/*
class GameViewController: UIViewController {

// MARK: View Controller overrides
override func viewDidLoad() {
super.viewDidLoad()

view = SKView(frame: view.bounds)

if let view = self.view as! SKView? {
// Initialise the scene
let scene = GameScene(size: view.bounds.size) // <-- IMPORTANT: Initialise your first scene (as you have no .sks)

// Set the scale mode to scale to fit the window
scene.scaleMode = .aspectFill

// Present the scene
view.presentScene(scene)

// Scene properties
view.showsPhysics = false
view.ignoresSiblingOrder = true
view.showsFPS = true
view.showsNodeCount = true
}
}

}
95 changes: 95 additions & 0 deletions notes/printViewDraft.js
@@ -0,0 +1,95 @@
// eachChild = ScrollView, which is a View
// eachChildView = TextView, which is a ViewBase
function printView(view, tabDepth) {
if(typeof tabDepth === "undefined") tabDepth = 0;
let buffer = "";

// buffer += "[" + (typeof view.eachChildView !== "undefined") + "]";

view.eachChild((child) => {
// view.eachChild((child) => {
const opener = new Array(tabDepth).fill(" ").join('') + "<" + child.typeName;
buffer += opener;

// buffer += "[" + (typeof child.eachChildView !== "undefined") + "]";

let children = 0;
child.eachChild((subchild) => {
if(children === 0) buffer += ">\n";
children++;
// isView check
// buffer += "[" + (typeof subchild.eachChildView !== "undefined") + "]";
buffer += printView(subchild, tabDepth + 1);
return true;
});

if(children === 0){
if(child.eachChildView){
child.eachChildView((subchild) => {
if(children === 0) buffer += ">\n";
children++;
buffer += printView(subchild, tabDepth + 2);
return true;
});
}
}

if(children === 0){
buffer += "/>\n";
} else {
const closer = new Array(tabDepth).fill(" ").join('') + "<" + child.typeName + "/>";
buffer += closer + '\n';
}

return true;
});

// if(view.eachChildView){
// buffer += "[ECV]";
// } else {
// buffer += "[EC]";
// }

if(view.eachChildView) view.eachChildView((child) => {
// view.eachChild((child) => {
const opener = new Array(tabDepth).fill(" ").join('') + "<" + child.typeName;
buffer += opener;

// buffer += "[" + (typeof child.eachChildView !== "undefined") + "]";

let children = 0;
child.eachChild((subchild) => {
if(children === 0) buffer += ">\n";
children++;
// isView check
// buffer += "[" + (typeof subchild.eachChildView !== "undefined") + "]";
buffer += printView(subchild, tabDepth + 1);
return true;
});

if(children === 0){
if(child.eachChildView){
child.eachChildView((subchild) => {
if(children === 0) buffer += ">\n";
children++;
buffer += printView(subchild, tabDepth + 2);
return true;
});
}
}

if(children === 0){
buffer += "/>\n";
} else {
const closer = new Array(tabDepth).fill(" ").join('') + "<" + child.typeName + "/>";
buffer += closer + '\n';
}

return true;
});

if(tabDepth === 0) console.log(buffer);
return buffer;
}
global.printView = printView;
printView(app.getRootView());

0 comments on commit 6c1fc88

Please sign in to comment.