Skip to content

Commit

Permalink
Merge pull request #31 from gaudiatech/no-pimodules
Browse files Browse the repository at this point in the history
import the NEW metadat format to master branch
  • Loading branch information
wkta authored Sep 22, 2024
2 parents 9ea4bac + bc6bda2 commit 76a5fa0
Show file tree
Hide file tree
Showing 19 changed files with 319 additions and 185 deletions.
72 changes: 35 additions & 37 deletions src/pyvcmdline/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ def bump_subcommand(bundle_name):
"""
print('bump bundle to current version that is', __version__)
my_metadat = read_metadata(bundle_name)
my_metadat['vmlib_ver'] = __version__.replace('.', '_')
my_metadat['dependencies']['pyved_engine'] = [__version__.replace('.', '_'), 'pyv'] # alias = pyv
rewrite_metadata(bundle_name, my_metadat)


Expand Down Expand Up @@ -444,11 +444,18 @@ def init_command(game_identifier) -> None:
# here, we modify the metadata based on what game genres the user wish to set
procedure_select_game_genre(metadata)

# ensure to have registered the latest pyved_engine version +use the default alias:
metadata['dependencies']['pyved_engine'] = [
__version__.replace('.', '_'), 'pyv'
] # defaut alias for the engine is "pyv"

# Get the absolute path of the current script
script_directory = os.path.dirname(os.path.abspath(__file__))
template_blueprint_folder = os.path.join(script_directory, f'template_{template_id}')
target_folder = os.path.join(os.getcwd(), x)
recursive_copy(template_blueprint_folder, target_folder)
# once we've copied all source files, it is the norm to list all files and update the metadat.json
save_list_of_py_files(os.path.join(x, 'cartridge'), metadata)

copy_launcher_script(x)
create_folder_and_serialize_dict(target_folder, data_dict=metadata)
Expand All @@ -462,18 +469,6 @@ def init_command(game_identifier) -> None:
print('Go ahead and have fun ;)')


# import os
# import urllib2
#
#
# class EnhancedFile(file):
# def __init__(self, *args, **keyws):
# file.__init__(self, *args, **keyws)
#
# def __len__(self):
# return int(os.fstat(self.fileno())[6])


def trigger_publish(slug):
"""
once the game is available server-side, as a stored cartridge,
Expand All @@ -488,28 +483,28 @@ def trigger_publish(slug):
"""
raise NotImplementedError # deprecated function

dummy_json_str = """
{
"game_title": "This is the game title",
"slug": "flappy",
"description": "This is a test game",
"instructions": "Click any object to move",
"width": 960,
"height": 720,
"thumb_1": "https://img.gamemonetize.com/ulol31p2l8xogmlxh1yqfa64dxzkyrix/512x384.jpg",
"thumb_2": "https://img.gamemonetize.com/ulol31p2l8xogmlxh1yqfa64dxzkyrix/512x384.jpg",
"category": "Puzzle,Arcade,Action",
"source": "API",
}
"""
jsondata = json.loads(dummy_json_str)
jsondata['slug'] = x = slug
reply = requests.post(
url='https://kata.games/api/uploads.php',
data=json.dumps(jsondata)
)
print(f'trigger_publish CALLED (arg:x=={x})--- result is...')
print(reply.text)
# dummy_json_str = """\
# {
# "game_title": "This is the game title",
# "slug": "flappy",
# "description": "This is a test game",
# "instructions": "Click any object to move",
# "width": 960,
# "height": 720,
# "thumb_1": "https://img.gamemonetize.com/ulol31p2l8xogmlxh1yqfa64dxzkyrix/512x384.jpg",
# "thumb_2": "https://img.gamemonetize.com/ulol31p2l8xogmlxh1yqfa64dxzkyrix/512x384.jpg",
# "category": "Puzzle,Arcade,Action",
# "source": "API",
# }
# """
# jsondata = json.loads(dummy_json_str)
# jsondata['slug'] = x = slug
# reply = requests.post(
# url='https://kata.games/api/uploads.php',
# data=json.dumps(jsondata)
# )
# print(f'trigger_publish CALLED (arg:x=={x})--- result is...')
# print(reply.text)


# TODO will be useful for implementing a future "repair" bundle subcommand
Expand Down Expand Up @@ -626,14 +621,16 @@ def upload_my_zip_file(zip_file_path: str, gslug, debugmode: bool) -> None:
'uploadedFile': (
zip_file_path,
open(zip_file_path, 'rb'),
'application/zip',
{'Expires': '0'}
'application/zip'
#{'Expires': '0'}
)
}
api_endpoint = pyvcli_config.get_upload_url(debugmode)
print('before requests.post')
reply = requests.post(
url=api_endpoint,
files=files,
timeout=8, # 8 sec is the max
data={'pyv-cli-flag': True, 'chosen-slug': gslug, 'uploadBtn': 'Upload'}
)
try:
Expand Down Expand Up @@ -692,6 +689,7 @@ def share_subcommand(bundle_name, dev_flag_on):
slug = metadat['slug']
if dev_flag_on: # in devmode, all tests on metadata are skipped
zipfile_path = pack_game_cartridge(slug)
print(f'file:{zipfile_path} packed, uploading it now...')
upload_my_zip_file(zipfile_path, slug, True)
return

Expand Down
52 changes: 28 additions & 24 deletions src/pyvcmdline/cmdline_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,29 +8,30 @@


EXP_METADAT_KEYS = (
'asset_base_folder',
'asset_list',
'sound_base_folder',
'sound_list',

'vmlib_ver',
'author',
'build_date',
'dependencies',
'description',
'title',
'instructions',
'slug',
'thumbnail512x384',
'thumbnail512x512',
'ktg_services',
'source_files',

'uses_challenge',
'has_game_server',
'ncr_faucet',
'game_genre'
)
'dependencies',
'asset_base_folder',
'asset_list',
'sound_base_folder',
'sound_list',

'vmlib_ver',
'author',
'build_date',
'dependencies',
'description',
'title',
'instructions',
'slug',
'thumbnail512x384',
'thumbnail512x512',
'ktg_services',
'source_files',

'uses_challenge',
'has_game_server',
'ncr_faucet',
'game_genre'
)

template_pyconnector_config_file ="""
{
Expand Down Expand Up @@ -58,6 +59,9 @@ def verify_metadata(mdat_obj) -> str:
for k in EXP_METADAT_KEYS:
if k not in mdat_obj:
return 'Missing key= {}'.format(k)
# need to test that pyved_engine is in dependencies...
if "pyved_engine" not in mdat_obj['dependencies']:
return 'Invalid list detected: "pyved_engine" not listed in the list of dependencies'

# we also need to test whether Y or N, categories specified are still recognized within the CMS!
if (not isinstance(mdat_obj['game_genre'], list)) or (len(mdat_obj['game_genre']) == 0):
Expand All @@ -66,7 +70,7 @@ def verify_metadata(mdat_obj) -> str:
for elt in mdat_obj['game_genre']:
if elt not in ok_game_genres:
return f'Game genre "{elt}" rejected by the Kata.Games system, please contact an Admin, or replace value'
print('--Metadata is valid--')
print('Metadata->OK')


def read_metadata(bundle_name):
Expand Down
74 changes: 39 additions & 35 deletions src/pyvcmdline/json_prec.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,15 @@
"""


JSON_PREC_NOASSETS = """\
JSON_PREC_GAMEZERO = """\
{
"vmlib_ver":"void",
"dependencies":{
"pyved_engine": "???"
},
"description":"this is a placeholder so you can describe your game",
"author":"placeholder_author",
"asset_list":[
],
"asset_base_folder":".",
"asset_list": ["lion.png"],
"asset_base_folder": "my_folder",
"sound_base_folder":".",
"sound_list": [
],
Expand All @@ -33,9 +31,8 @@

JSON_PREC_PLATFORMER = """\
{
"vmlib_ver": "23_9a1",
"dependencies": {
"pyved_engine": "???"
"vmlib_ver":"void",
"dependencies":{
},
"description": "this is an example of platformer",
"author": "KataGames_Team",
Expand All @@ -59,11 +56,10 @@
}
"""

JSON_PREC_CHESS ="""
JSON_PREC_CHESS ="""\
{
"vmlib_ver": "23_9a1",
"dependencies": {
"pyved_engine": "???"
"vmlib_ver":"void",
"dependencies":{
},
"description": "this is a placeholder so you can describe your game",
"author": "moonbak et al.",
Expand Down Expand Up @@ -104,38 +100,46 @@

JSON_PREC_ROGUE = """
{
"vmlib_ver": "24_3a1",
"dependencies": {
"pyved_engine": "???"
"vmlib_ver":"void",
"dependencies":{
},
"description": "a basic demo for a roguelike game",
"author": "moonbak",
"asset_base_folder":".",
"sound_base_folder":".",
"asset_list": [
"description": "a basic demo for a roguelike game",
"author": "thomas",
"asset_base_folder": ".",
"sound_base_folder": ".",
"asset_list": [
"smallninja_sprites.json",
"tileset.png",
"monster.png",
"avatar1.png"
],
"sound_list": [],
"slug": "roguelikeDemo",
"title": "Roguelike Template",
"build_date": "Tue Apr 2 15:40:11 2024",
"thumbnail512x384": "thumb_2.png",
"thumbnail512x512": "thumb_1.png",
"ktg_services": false,
"instructions": "no instructions provided",
"uses_challenge": false,
"has_game_server": false,
"ncr_faucet": false,
"game_genre": ["Roguelike"]
],
"sound_list": [],
"slug": "JeuEvolue",
"title": "Roguelike Template",
"build_date": "Tue Sep 17 09:06:21 2024",
"thumbnail512x384": "thumb_2.png",
"thumbnail512x512": "thumb_1.png",
"ktg_services": false,
"instructions": "no instructions provided",
"uses_challenge": false,
"has_game_server": false,
"ncr_faucet": false,
"game_genre": [
"Roguelike"
],
"game_title": "JeuEvolue",
"source_files": [
"gamedef.py",
"glvars.py",
"mvc_parts.py",
"__init__.py"
]
}
"""

TEMPL_ID_TO_JSON_STR = {
0: JSON_PREC_NOASSETS,
1: JSON_PREC_NOASSETS,
0: JSON_PREC_GAMEZERO,
1: JSON_PREC_GAMEZERO,
2: JSON_PREC_PLATFORMER,
3: JSON_PREC_CHESS,
4: JSON_PREC_ROGUE
Expand Down
Loading

0 comments on commit 76a5fa0

Please sign in to comment.