Skip to content

Commit 5ff59e4

Browse files
committed
merged pk-engine-js as a subtree to pk-engine-js
2 parents d466478 + 1b9065b commit 5ff59e4

37 files changed

+5316
-0
lines changed

pk-engine-js/.gitignore

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
*~
2+
.*~
3+
\#*\#
4+
.\#*\#
5+
6+
.DS_Store
7+
._.DS_Store
8+
.project
9+
.settings
10+
.directory
11+
12+
*.kdevelop.*
13+
*.kdevelop
14+
*.kdevses
15+
*.kdev4
16+
/Doxyfile
17+
/tags
18+
19+
nohup.out
20+
*.log
21+
.idea
22+
*.iml
23+
24+
*.kate_swp
25+
tmp/*
26+
*.kate_swps
+115
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
//------------------------------------------------------------------------------
2+
// ajax_request_helper.js: Ajax request helper
3+
// This file is a part of pk-engine-js library
4+
// Copyright (c) Alexander Gladysh <[email protected]>
5+
// Copyright (c) Dmitry Potapov <[email protected]>
6+
// See file `COPYRIGHT` for the license
7+
//------------------------------------------------------------------------------
8+
9+
PKEngine.check_namespace("Ajax");
10+
11+
PKEngine.Ajax.PRINT_RECEIVED_DATA = false;
12+
13+
PKEngine.Ajax.do_request = function(url, type, post_data, event_maker, on_error, on_server_conn_error)
14+
{
15+
//console.log("Ajax url:", url)
16+
//console.log(window.printStackTrace().join("\n"))
17+
18+
on_error = on_error || PKEngine.Ajax.default_error_handler;
19+
20+
$.ajax(
21+
url,
22+
{
23+
'type' : type,
24+
'data' : post_data,
25+
//'dataType' : "json", // TODO: Hack (non-working, BTW), to be removed
26+
'success' : function(data_in, textStatus, jqXHR)
27+
{
28+
if (PKEngine.Ajax.PRINT_RECEIVED_DATA)
29+
{
30+
console.log("[Ajax.do_request]: " + url, PK.clone(data_in), textStatus, jqXHR)
31+
}
32+
33+
// assert(
34+
// typeof(data_in) == "object",
35+
// I18N('Invalid format of server response for request "${1}"', url)
36+
// )
37+
// TODO: Hack, to be removed
38+
var data;
39+
try
40+
{
41+
data = (typeof(data_in) == "string") ? JSON.parse(data_in) : data_in;
42+
}
43+
catch (ex)
44+
{
45+
CRITICAL_ERROR(I18N('Unable to parse server response for request "${1}"', url));
46+
return;
47+
}
48+
49+
if(data)
50+
{
51+
if(event_maker)
52+
{
53+
PKEngine.EventQueue.push(event_maker(data));
54+
}
55+
}
56+
else
57+
{
58+
on_error(url, textStatus, jqXHR);
59+
}
60+
},
61+
'error' : function(jqXHR, textStatus, errorThrown)
62+
{
63+
if (
64+
textStatus == "timeout"
65+
|| (jqXHR.readyState == 0 && jqXHR.responseText == "")
66+
|| jqXHR.status == 500 || jqXHR.status == 502
67+
|| jqXHR.status == 503 || jqXHR.status == 504
68+
)
69+
{
70+
LOG("ServerConnectionError = " + JSON.stringify(jqXHR));
71+
if (on_server_conn_error)
72+
{
73+
on_server_conn_error();
74+
}
75+
return;
76+
}
77+
on_error(url, textStatus, jqXHR);
78+
}
79+
}
80+
);
81+
}
82+
83+
PKEngine.Ajax.default_error_handler = function(name, textStatus, jqXHR)
84+
{
85+
var loc_text_status = I18N("Ajax error NULL")
86+
switch (textStatus)
87+
{
88+
case 'timeout' : loc_text_status = I18N("Ajax error TIMEOUT"); break;
89+
case 'error' : loc_text_status = I18N("Ajax ERROR"); break;
90+
case 'abort' : loc_text_status = I18N("Ajax error ABORT"); break;
91+
case 'parsererror' : loc_text_status = I18N("Ajax error PARSERERROR"); break;
92+
}
93+
94+
CRITICAL_ERROR(
95+
I18N("Bad server answer!") + "<br>"
96+
+ I18N("Request URL: ${1}", name) + "<br>"
97+
+ I18N("Text error: ${1}", loc_text_status) + "<br>"
98+
+ I18N("Response status: ${1}", jqXHR.status) + "<br>"
99+
+ I18N("Response text: ${1}", jqXHR.responseText)
100+
);
101+
};
102+
103+
104+
PKEngine.Ajax.on_soft_error_received = function(name, error)
105+
{
106+
assert(error)
107+
108+
var error_text = error.id ? String(error.id) : JSON.stringify(error)
109+
110+
CRITICAL_ERROR(
111+
I18N("Bad server answer!") + "<br>"
112+
+ I18N("Request URL: ${1}", name) + "<br>"
113+
+ I18N("Text error: ${1}", error_text) + "<br>"
114+
);
115+
};

pk-engine-js/src/js/base.js

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//------------------------------------------------------------------------------
2+
// base.js: Initialization of base project things
3+
// This file is a part of pk-engine-js library
4+
// Copyright (c) Alexander Gladysh <[email protected]>
5+
// Copyright (c) Dmitry Potapov <[email protected]>
6+
// See file `COPYRIGHT` for the license
7+
//------------------------------------------------------------------------------
8+
9+
if (PKEngine === undefined)
10+
{
11+
var PKEngine = new function()
12+
{
13+
this.check_namespace = function(name)
14+
{
15+
if (this[name] === undefined)
16+
this[name] = new Object
17+
return this[name]
18+
}
19+
}
20+
}

pk-engine-js/src/js/client_api.js

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
//------------------------------------------------------------------------------
2+
// client_api.js: Server protocol description and checks
3+
// This file is a part of pk-engine-js library
4+
// Copyright (c) Alexander Gladysh <[email protected]>
5+
// Copyright (c) Dmitry Potapov <[email protected]>
6+
// See file `COPYRIGHT` for the license
7+
//------------------------------------------------------------------------------
8+
9+
PKEngine.ClientAPI = new function()
10+
{
11+
var supported_version_;
12+
var received_version_;
13+
14+
this.init = function(supported_version)
15+
{
16+
supported_version_ = supported_version;
17+
}
18+
19+
this.get_client_version = function()
20+
{
21+
return supported_version_;
22+
}
23+
24+
this.get_server_version = function()
25+
{
26+
return received_version_;
27+
}
28+
29+
this.check_version = function(received_version)
30+
{
31+
received_version_ = received_version;
32+
33+
if (
34+
received_version &&
35+
received_version.name == supported_version_.name &&
36+
(
37+
Number(received_version['major']) == supported_version_['major'] &&
38+
Number(received_version['minor']) == supported_version_['minor'] &&
39+
Number(received_version['build']) >= supported_version_['build']
40+
)
41+
)
42+
{
43+
return true;
44+
}
45+
46+
LOG( I18N(
47+
'Invalid API version: expected ${1}, got ${2}',
48+
JSON.stringify(supported_version_, null, 4),
49+
JSON.stringify(received_version, null, 4)
50+
));
51+
52+
CRITICAL_ERROR(
53+
I18N('The current client is out of date. Click "close" to reload the page.')
54+
);
55+
56+
return false;
57+
}
58+
}

pk-engine-js/src/js/const.js

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
//------------------------------------------------------------------------------
2+
// const.js: Constants
3+
// This file is a part of pk-engine-js library
4+
// Copyright (c) Alexander Gladysh <[email protected]>
5+
// Copyright (c) Dmitry Potapov <[email protected]>
6+
// See file `COPYRIGHT` for the license
7+
//------------------------------------------------------------------------------
8+
9+
PKEngine.Const =
10+
{
11+
ANTI_CACHE: "",
12+
MAXIMUM_FPS: 30,
13+
RESOURCES_LOADING_TIMEOUT: 30000 // in ms.
14+
}

pk-engine-js/src/js/event_queue.js

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
//------------------------------------------------------------------------------
2+
// event_queue.js: Queue of events which should be run
3+
// This file is a part of pk-engine-js library
4+
// Copyright (c) Alexander Gladysh <[email protected]>
5+
// Copyright (c) Dmitry Potapov <[email protected]>
6+
// See file `COPYRIGHT` for the license
7+
//------------------------------------------------------------------------------
8+
9+
PKEngine.EventQueue = new function()
10+
{
11+
var queue_ = []
12+
13+
this.push = function(event)
14+
{
15+
queue_.push(event)
16+
}
17+
18+
this.run = function()
19+
{
20+
for (var i = 0; i < queue_.length; i++)
21+
queue_[i].run()
22+
queue_.length = 0
23+
}
24+
}

0 commit comments

Comments
 (0)