Squaby Demo
import QtQuick 2.0
import Felgo 4.0
LevelEditor {
property bool __loadLevelForFirstTime: true
Component.onCompleted: {
console.debug("SquabyLevelEditor: entityManager:", entityManagerItem)
}
applicationJSONLevelsDirectory: Qt.resolvedUrl("levels/jsonLevels/")
qmlLevelList: [
]
levelBaseNameToUrlMap: {
"DynamicLevel01": {url: Qt.resolvedUrl("levels/empty/LevelEmpty.qml")},
}
levelLoaderItem: level ? level.levelLoader : {}
toStoreEntityTypes: ["obstacle"]
toRemoveEntityTypes: ["obstacle"]
onLoadLevelFinished: {
console.debug("SquabyLevelEditor: finished loading single level with name", currentLevelName, "and id", currentLevelId)
handleLoadLevelOrNewLevelFinished()
}
onNewLevelFinished: {
console.debug("SquabyLevelEditor: finished creating a new level with name", currentLevelName, "and id", currentLevelId, ", createEmptyLevel was true:", createEmptyLevel)
if(createEmptyLevel) {
handleLoadLevelOrNewLevelFinished()
} else {
}
}
function handleLoadLevelOrNewLevelFinished() {
if(__loadLevelForFirstTime) {
__loadLevelForFirstTime = false;
console.debug("TwoPhaseLevelLoader: startGame() is called for the first time in this game, so precreate pooled entities, level:", level)
var now = Date.now();
level.preCreateEntitiesForPool()
var dt = Date.now()-now;
console.debug("SquabyLevelEditor: dt for preCreateEntitiesForPool:", dt)
}
window.state = "game"
}
onRemoveLevelFinished: {
}
onExportLevelAsFileFinished: {
NativeUtils.displayMessageBox("Successfully exported level file with name " + currentLevelName)
}
onSaveLevelFinished: {
}
onLevelError: {
NativeUtils.displayMessageBox("Error at saving a level, content: " + JSON.stringify(errorData))
}
onLevelPublished: {
scene.state = ""
window.state = "levels"
gameNetwork.increasePublishedLevels()
}
onUserBestLevelStatsChanged: {
console.debug("__new bestLevelStats:", JSON.stringify(userBestLevelStats))
if(userBestLevelStats["best_quality"]) {
gameNetwork.setBestLevelRatingOfOwnLevels(userBestLevelStats["best_quality"]["average_quality"])
}
if(userBestLevelStats["most_downloaded"]) {
gameNetwork.setLevelDownloadsOfOwnLevels(userBestLevelStats["most_downloaded"]["times_downloaded"])
}
}
onLevelRated: {
for(var i=0;i<userGeneratedLevels.length; i++) {
var level = userGeneratedLevels[i]
if(level.levelId === levelId) {
if(level["rating"] && level.rating.quality) {
console.debug("the player has already rated this level, thus do not increase the achievement counter")
return
}
}
}
gameNetwork.increaseRatedLevels()
}
onLevelDownloadedSuccessfully: {
gameNetwork.increaseDownloadedLevels()
}