summaryrefslogtreecommitdiffstats
path: root/demos/declarative/samegame
diff options
context:
space:
mode:
authorAlan Alpert <alan.alpert@nokia.com>2009-09-22 06:47:18 (GMT)
committerAlan Alpert <alan.alpert@nokia.com>2009-09-22 06:47:18 (GMT)
commit3846e7c9c602b3dcc06516aaee582aedf9c0f436 (patch)
tree4ad6f489e9e764a749038d8b9e33f551322a1f30 /demos/declarative/samegame
parent1ee038d05089aea25d3602f3e65592d7dd07b76f (diff)
downloadQt-3846e7c9c602b3dcc06516aaee582aedf9c0f436.zip
Qt-3846e7c9c602b3dcc06516aaee582aedf9c0f436.tar.gz
Qt-3846e7c9c602b3dcc06516aaee582aedf9c0f436.tar.bz2
Clean up Same Game JS
Delayed loading is never used and is poorly implemented, so remove it.
Diffstat (limited to 'demos/declarative/samegame')
-rwxr-xr-xdemos/declarative/samegame/content/samegame.js49
1 files changed, 12 insertions, 37 deletions
diff --git a/demos/declarative/samegame/content/samegame.js b/demos/declarative/samegame/content/samegame.js
index 0a3a4db..e42b7cc 100755
--- a/demos/declarative/samegame/content/samegame.js
+++ b/demos/declarative/samegame/content/samegame.js
@@ -44,7 +44,7 @@ function initBoard()
for(xIdx=0; xIdx<maxX; xIdx++){
for(yIdx=0; yIdx<maxY; yIdx++){
board[index(xIdx,yIdx)] = null;
- startCreatingBlock(xIdx,yIdx);
+ createBlock(xIdx,yIdx);
}
}
timer = new Date();
@@ -170,22 +170,15 @@ function floodMoveCheck(xIdx, yIdx, type)
floodMoveCheck(xIdx, yIdx - 1, board[index(xIdx,yIdx)].type);
}
-//If the component isn't ready, then the signal doesn't include the game x,y
-//So we store any x,y sent that we couldn't create at the time, and use those
-//if we are triggered by the signal.
-var waitStack = new Array(maxIndex);
-var waitTop = -1;
+function createBlock(xIdx,yIdx){
+ if(component==null)
+ component = createComponent(tileSrc);
-function finishCreatingBlock(xIdx,yIdx){
+ // Note that we don't wait for the component to become ready. This will
+ // only work if the block QML is a local file. Otherwise the component will
+ // not be ready immediately. There is a statusChanged signal on the
+ // component you could use if you want to wait to load remote files.
if(component.isReady){
- if(xIdx == undefined){
- //Called without arguments, create a previously stored (xIdx,yIdx)
- if(waitTop == -1)
- return;//Don't have a previously stored (xIdx,yIdx)
- xIdx = waitStack[waitTop] % maxX;
- yIdx = Math.floor(waitStack[waitTop] / maxX);
- waitTop -= 1;
- }
dynamicObject = component.createObject();
if(dynamicObject == null){
print("error creating block");
@@ -201,30 +194,12 @@ function finishCreatingBlock(xIdx,yIdx){
dynamicObject.height = tileSize;
dynamicObject.spawned = true;
board[index(xIdx,yIdx)] = dynamicObject;
- return true;
- }else if(component.isError){
- print("error creating block");
+ }else{//isError or isLoading
+ print("error loading block component");
print(component.errorsString());
- }else{
- //It isn't ready, but we'll be called again when it is.
- //So store the requested (xIdx,yIdx) for later use
- waitTop += 1;
- waitStack[waitTop] = index(xIdx,yIdx);
- }
- return false;
-}
-
-function startCreatingBlock(xIdx,yIdx){
- if(component!=null){
- finishCreatingBlock(xIdx,yIdx);
- return;
+ return false;
}
-
- component = createComponent(tileSrc);
- if(finishCreatingBlock(xIdx,yIdx))
- return;
- component.statusChanged.connect(finishCreatingBlock());
- return;
+ return true;
}
function sendHighScore(name) {