Skip to content

Commit 3f8b7a8

Browse files
committed
Added more API compat
1 parent b41f3af commit 3f8b7a8

11 files changed

Lines changed: 577 additions & 217 deletions

File tree

.idea/workspace.xml

Lines changed: 360 additions & 206 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/scripting/build/api/Display.js

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -82,15 +82,15 @@ var Display;
8282
var Display;
8383
(function (Display) {
8484
var DisplayObject = (function () {
85-
function DisplayObject() {
86-
/** This represents an element in the HTML rendering **/
87-
this._id = Runtime.getId();
85+
function DisplayObject(id) {
86+
if (typeof id === "undefined") { id = Runtime.getId(); }
8887
this._alpha = 1;
8988
this._x = 0;
9089
this._y = 0;
9190
this._scaleX = 1;
9291
this._scaleY = 1;
9392
this._filters = [];
93+
this._id = id;
9494
}
9595
DisplayObject.prototype.propertyUpdate = function (propertyName, updatedValue) {
9696
__pchannel("Runtime:UpdateProperty", {
@@ -223,6 +223,10 @@ var Display;
223223
configurable: true
224224
});
225225

226+
/** AS3 Stuff **/
227+
DisplayObject.prototype.addEventListener = function (event, listener) {
228+
};
229+
226230
/** Common Functions **/
227231
DisplayObject.prototype.serialize = function () {
228232
var filters = [];
@@ -263,8 +267,8 @@ var Display;
263267
(function (Display) {
264268
var Sprite = (function (_super) {
265269
__extends(Sprite, _super);
266-
function Sprite() {
267-
_super.call(this);
270+
function Sprite(id) {
271+
_super.call(this, id);
268272
}
269273
return Sprite;
270274
})(Display.DisplayObject);

src/scripting/src/api/Display/Display.ts

Lines changed: 66 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,78 @@
99

1010
module Display {
1111
export var root:DisplayObject;
12-
var _root:DisplayObject = new Sprite();
12+
export var loaderInfo:Object;
13+
export var stage:DisplayObject;
14+
export var version:string;
15+
export var width:number;
16+
export var height:number;
17+
export var fullScreenWidth:number;
18+
export var fullScreenHeight:number;
19+
export var frameRate:number;
20+
21+
var _root:DisplayObject = new Sprite("__root");
22+
var _width:number = 0;
23+
var _height:number = 0;
24+
var _fullScreenWidth:number = 0;
25+
var _fullScreenHeight:number = 0;
26+
var _frameRate:number = 24;
27+
1328
Object.defineProperty(Display, 'root', {
1429
get: function() { return _root; },
1530
set: function(value) {
1631
__trace("Display.root is read-only", "warn");
1732
}
1833
});
34+
Object.defineProperty(Display, 'loaderInfo', {
35+
get: function() { return {}; },
36+
set: function(value) {
37+
__trace("Display.loaderInfo is disabled", "warn");
38+
}
39+
});
40+
Object.defineProperty(Display, 'stage', {
41+
get: function() { return _root; },
42+
set: function(value) {
43+
__trace("Display.stage is read-only", "warn");
44+
}
45+
});
46+
Object.defineProperty(Display, 'version', {
47+
get: function() {
48+
return "CCLDisplay/1.0 HTML5/* (bilibili, like BSE, like flash, AS3 compatible)";
49+
},
50+
set: function(value) {
51+
__trace("Display.version is read-only", "warn");
52+
}
53+
});
54+
Object.defineProperty(Display, 'width', {
55+
get: function() { return _width; },
56+
set: function(value) {
57+
__trace("Display.width is read-only", "warn");
58+
}
59+
});
60+
Object.defineProperty(Display, 'height', {
61+
get: function() { return _height; },
62+
set: function(value) {
63+
__trace("Display.height is read-only", "warn");
64+
}
65+
});
66+
Object.defineProperty(Display, 'fullScreenWidth', {
67+
get: function() { return _fullScreenWidth; },
68+
set: function(value) {
69+
__trace("Display.fullScreenWidth is read-only", "warn");
70+
}
71+
});
72+
Object.defineProperty(Display, 'fullScreenHeight', {
73+
get: function() { return _fullScreenHeight; },
74+
set: function(value) {
75+
__trace("Display.fullScreenHeight is read-only", "warn");
76+
}
77+
});
78+
Object.defineProperty(Display, 'frameRate', {
79+
get: function() { return _frameRate; },
80+
set: function(value) {
81+
__pchannel("Display:SetFrameRate", value);
82+
}
83+
});
1984
}
2085

2186
/// <reference path="CommentButton.ts" />

src/scripting/src/api/Display/DisplayObject.ts

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,19 @@
99
module Display {
1010
export class DisplayObject implements ISerializable {
1111
/** This represents an element in the HTML rendering **/
12-
private _id:string = Runtime.getId();
12+
private _id:string;
1313
private _alpha:number = 1;
1414
private _x:number = 0;
1515
private _y:number = 0;
1616
private _scaleX:number = 1;
1717
private _scaleY:number = 1;
1818
private _filters:Array<Filter> = [];
19+
private _visible:boolean = false;
20+
21+
constructor(id:string = Runtime.generateId()){
22+
this._id = id;
23+
this._visible = true;
24+
}
1925

2026
private propertyUpdate(propertyName:string, updatedValue):void {
2127
__pchannel("Runtime:UpdateProperty", {
@@ -108,6 +114,19 @@ module Display {
108114
return 0;
109115
}
110116

117+
set visible(visible:boolean){
118+
this._visible = visible;
119+
this.propertyUpdate("visible", visible);
120+
}
121+
122+
get visible():boolean{
123+
return this._visible;
124+
}
125+
/** AS3 Stuff **/
126+
public addEventListener(event:String, listener:Function):void{
127+
128+
}
129+
111130
/** Common Functions **/
112131
public serialize():Object {
113132
var filters:Array<Object> = [];
@@ -124,6 +143,7 @@ module Display {
124143
}
125144

126145
public unload():void {
146+
this._visible = false;
127147
__pchannel("Runtime:CallMethod", {
128148
"id": this._id,
129149
"method": "unload",

src/scripting/src/api/Display/Sprite.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
/// <reference path="DisplayObject.ts" />
77
module Display {
88
export class Sprite extends DisplayObject {
9-
constructor(){
10-
super();
9+
constructor(id?:string){
10+
super(id);
1111
}
1212
}
1313
}

src/scripting/src/api/OOAPI.d.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,9 @@ declare function __channel(id:string, payload:Object, callback:Function):void;
2929
declare function __pchannel(id:string, payload:Object):void;
3030
declare function __schannel(id:string, callback:Function):void;
3131
declare function __achannel(id:string, auth:string, payload:Object):void;
32+
33+
declare var __OOAPI:{
34+
createChannel(id:string, max:number = 0, token:string = null):boolean;
35+
deleteChannel(id:string, token:string = null):boolean;
36+
addListenerChannel(id:string, listener:Function):boolean;
37+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/**
2+
* Player Library
3+
* Author: Jim Chen
4+
*/
5+
module Player{
6+
class Sound{
7+
private _source:string;
8+
private _isPlaying:boolean = false;
9+
public onload:Function;
10+
constructor(type:string, onload:Function){
11+
this.onload = onload;
12+
this._source = type;
13+
}
14+
public createFromURL(url:string):void{
15+
this._source = url;
16+
}
17+
public play():void{
18+
19+
}
20+
public remove():void{
21+
22+
}
23+
public stop():void{
24+
25+
}
26+
public loadPercent():number{
27+
return 0;
28+
}
29+
public serialize():Object{
30+
return {
31+
"class":"Sound",
32+
"url":this._source
33+
};
34+
}
35+
}
36+
}

src/scripting/src/api/Runtime/Runtime.ts

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,58 @@ module Runtime{
2323
return this._name;
2424
}
2525
}
26+
class TimerRuntime {
27+
public start():void{
2628

29+
}
30+
public stop():void{
31+
32+
}
33+
public setInterval():number{
34+
35+
}
36+
public setTimeout():number{
37+
38+
}
39+
public clearInterval(id:number):void{
40+
41+
}
42+
public clearTimeout(id:number):void{
43+
44+
}
45+
public clearAll():void{
46+
47+
}
48+
}
49+
export class Timer{
50+
51+
}
52+
/** Variables **/
53+
var objCount:number = 0;
54+
var registeredObjects:Object = {
55+
"__self":new MetaObject("__self"),
56+
"__player":new MetaObject("__player")
57+
};
58+
var masterTimer:TimerRuntime = new TimerRuntime();
59+
export function crash():void{
60+
__trace("Runtime.crash() : Manual crash", "fatal");
61+
}
62+
63+
export function alert(msg:string):void{
64+
__achannel("Runtime::alert", "::Runtime" , msg);
65+
}
66+
67+
export function hasObject(objectId:string):boolean{
68+
return registeredObjects.hasOwnProperty(objectId);
69+
}
70+
71+
export function generateId(type:string = "obj"):string{
72+
var id:string = type + ":" + (new Date()).getTime() + "|" +
73+
Math.round(Math.random() * 4096) + ":" + objCount;
74+
while(this.hasObject(id)){
75+
id = type + ":" + (new Date()).getTime() + "|" +
76+
Math.round(Math.random() * 4096) + ":" + objCount;
77+
}
78+
return id;
79+
};
2780
}

src/scripting/src/api/Scripting.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@
33
////////////////
44

55
declare var Runtime: {
6-
getId():string
6+
generateId():string
77
}

0 commit comments

Comments
 (0)