Skip to content

Commit

Permalink
Merge pull request #129 from Capstone-Projects-2024-Spring/BP-XXX-Dem…
Browse files Browse the repository at this point in the history
…o-Changes

Bp xxx demo changes
  • Loading branch information
gummyfrog committed Apr 29, 2024
2 parents 2e6e959 + 4e52cb5 commit 9125b7d
Show file tree
Hide file tree
Showing 35 changed files with 8,085 additions and 354 deletions.
34 changes: 29 additions & 5 deletions blockly/compiler_src.js
Expand Up @@ -14,6 +14,10 @@ const onlyBitmaps = (process.argv.indexOf('--bitmaps') > -1);
const onlyIcon = (process.argv.indexOf('--icon') > -1);
var bitmaps = {};


let imagedestination = null;
let testing = false;

class dummyField extends Blockly.Field {}
dummyField.fromJson = () => {};
Blockly.fieldRegistry.register('field_bitmap', dummyField);
Expand Down Expand Up @@ -105,10 +109,17 @@ var saveBitmap = (bitmap, size, name, icon=false) => {
}
}



var writeLocation = `${__dirname}/compiled_games/images/${name.toLowerCase().replace(/[^a-zA-Z ]/g, "").replace(" ", "-") || "UNKNOWN"}.png`
if(icon) {
writeLocation = `${__dirname}/../flask/saved/icons/${name}.png`
}

if(imagedestination != null) {
writeLocation = `${imagedestination}/${name.toLowerCase().replace(/[^a-zA-Z ]/g, "").replace(" ", "-")}.png`;
}

var out = fs.createWriteStream(writeLocation);
savePixels(d, "png").pipe(out)
}
Expand Down Expand Up @@ -193,7 +204,9 @@ var getBitmapSize = (bitmap_type, definitions) => {
return [size.width, size.height]
}

var compile = (filepath, filedestination) => {
var compile = (filepath, filedestination, _imagedestination = null, _testing = false) => {
imagedestination = _imagedestination;
testing = _testing;
try {
var fpath = filepath || process.argv[2]
const file = jsonfile.readFileSync(fpath);
Expand Down Expand Up @@ -226,7 +239,11 @@ var compile = (filepath, filedestination) => {
} else {
var hasExit = findPathToExit(file);
if(!hasExit) {
process.exit(-1);
if(!testing) {
process.exit(-1);
} else {
throw new Error("failed to find exit")
}
}

// Save all those BitMaps.
Expand Down Expand Up @@ -299,13 +316,20 @@ var compile = (filepath, filedestination) => {
});
} catch (e) {
console.log(e);
process.exit(-1)
if(!testing) {
process.exit(-1);
} else {
// throw new Error("failed to find exit")
}
}

}
} catch (e) {
console.error(e);
process.exit(-1)
if(!testing) {
process.exit(-1);
} else {
// throw new Error("failed to find exit")
}
}
}

Expand Down
79 changes: 75 additions & 4 deletions flask/serve.py
Expand Up @@ -66,9 +66,12 @@ def send_report(path):

@app.route('/save/', methods = ['POST'])
def save():
print(request)
print(request.method)
if request.method == 'POST':
print(request.json)
gamedata = request.json

print(gamedata)
# actually unnecessary to find gamename thru metadata, but keeping for legacy
gamename = ""
metadataFound = False
Expand Down Expand Up @@ -111,27 +114,95 @@ def save():
if closeFound == False:
return {"error": "Exit Game Block Missing", "fix": "Make sure your project has a reachable exit block. You can find it under the Game Logic category."}, 400


with open(os.path.join(GAMES_FOLDER, gamename+".json"), 'w', encoding='utf-8') as f:
json.dump(gamedata, f, ensure_ascii=False, indent=4)

save_icon_result = save_game_icon(gamename)
if save_icon_result.returncode != 0:
return {'error': 'Could not save game icon.'}, 400

print(save_icon_result.returncode)

compile_result = compile_game(gamename)
if compile_result.returncode != 0:
return {'error': 'Game does not compile.', "fix": "Make sure you have a reachable exit block.", "err": compile_result.stderr}, 400


print(compile_result.returncode)

game_test_result = test_run_game(gamename)
print(game_test_result)
print(game_test_result['game_ran'])
if game_test_result['game_ran'] == True:
return {'success': 'Game runs!'}, 200
else:
return {'error': 'Game does not run.', "fix": "Check your project for blocks without followup actions- for example, 'if' or 'Key Down' blocks without more blocks inside them."}, 400



@app.route('/saveWithoutRun/', methods = ['POST'])
def saveWithoutRun():
if request.method == 'POST':
print(request.json)
gamedata = request.json
print(gamedata)
# actually unnecessary to find gamename thru metadata, but keeping for legacy
gamename = ""
metadataFound = False
loopFound = False
closeFound = False
iconFound = False
validMetadata = False

# Iterate through workspace to find metadata

blocks = unrollWorkspaceBlocks(gamedata)

for x in blocks:
if(x["type"]=="exit"):
print(x)
closeFound = True
if(x["type"]=="game_loop"):
loopFound = True

for x in gamedata["blocks"]["blocks"]:
if(x["type"]=="metadata"):
iconFound = "game_icon" in x["inputs"]
validMetadata = "game name" in x["inputs"] and "author name" in x["inputs"] and "description" in x["inputs"]

if(validMetadata == False):
break

gamename = x["inputs"]["game name"]["block"]["fields"]["TEXT"]
metadataFound = True


if validMetadata == False:
return {"error": "Invalid Metadata.", "fix": "Make sure y ou have a name, author, and description in your metadata block."}, 400
if metadataFound == False:
return {"error": "Metadata Block Missing", "fix": "Make sure your project has a metadata block. You can find it under the Game Logic category."}, 400
if iconFound == False:
return {"error": "Game Icon Missing", "fix": "Make sure your project has a game icon attached to its metadata block. You can find bitmaps under the Actors category."}, 400
if loopFound == False:
return {"error": "Game Loop Block Missing", "fix": "Make sure your project has a game loop block. You can find it under the Game Logic category."}, 400
if closeFound == False:
return {"error": "Exit Game Block Missing", "fix": "Make sure your project has a reachable exit block. You can find it under the Game Logic category."}, 400


with open(os.path.join(GAMES_FOLDER, gamename+".json"), 'w', encoding='utf-8') as f:
json.dump(gamedata, f, ensure_ascii=False, indent=4)

save_icon_result = save_game_icon(gamename)
if save_icon_result.returncode != 0:
return {'error': 'Could not save game icon.'}, 400

compile_result = compile_game(gamename)
if compile_result.returncode != 0:
return {'error': 'Game does not compile.', "fix": "Make sure you have a reachable exit block.", "err": compile_result.stderr}, 400

return {'success': 'Game Saved!'}, 200



@app.route('/games/', methods = ['GET'])
def allgames():
included_extensions = ['js']
Expand Down
7 changes: 4 additions & 3 deletions home/webapp/src/components/styles/HomePage.styled.jsx
Expand Up @@ -11,9 +11,6 @@ export const HomePageContainer = styled.div`
overflow: hidden;
gap: 20px;
& * {
font-size: 26px !important;
}
`;

export const GalleryContainer = styled.div`
Expand Down Expand Up @@ -79,6 +76,10 @@ export const GameInfoContainer = styled.div`
export const GameMetaData = styled.div`
// outline: 3px solid red;
width: 50%;
& * {
font-size: 26px !important;
}
gap: 10px;
`;

Expand Down

0 comments on commit 9125b7d

Please sign in to comment.