| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152 |
- """Run with the game's Python, from the repository root."""
- import ast
- import hashlib
- import importlib.util
- import json
- import os
- from pathlib import Path
- os.environ.setdefault('SDL_VIDEODRIVER', 'dummy')
- os.environ.setdefault('SDL_AUDIODRIVER', 'dummy')
- ROOT = Path(__file__).resolve().parents[2]
- os.chdir(str(ROOT))
- import sys
- sys.path.insert(0, str(ROOT))
- import pygame
- from PIL import Image
- HERE = Path(__file__).resolve().parent
- checks = []
- def verify_assets():
- manifest = json.loads((HERE / 'asset_manifest.json').read_text(encoding='utf-8'))
- expected_size = tuple(manifest['canvas'])
- baseline = manifest['foot_baseline']
- hero = json.loads((ROOT / 'game/hero/DeepseekBlueWhale.json').read_text(encoding='utf-8'))
- data = json.loads((ROOT / ('game/frame/character/' + hero['character'] + '.json')).read_text(encoding='utf-8'))
- paths = []
- for index, direction in enumerate(('R', 'U', 'L', 'D')):
- for state, count in [('STAND_' + direction, 1), (direction, 6)]:
- entry = data[state]
- assert entry['Len'] == count
- cloth = entry['Cloth']
- assert len(cloth['IMG']) == len(cloth['CX']) == len(cloth['CY']) == count
- hashes = []
- for filename in cloth['IMG']:
- path = ROOT / 'res/img/cloth' / filename
- assert path.exists(), path
- image = Image.open(path)
- assert image.size == expected_size and image.mode == 'RGBA'
- assert image.getchannel('A').getextrema() == (0, 255)
- assert image.getbbox()[3] <= baseline
- if manifest.get('version') == 2:
- assert image.getbbox()[3] - image.getbbox()[1] >= 87
- assert entry['Cx'] == -64 and entry['Cy'] == -93
- hashes.append(hashlib.sha256(image.tobytes()).hexdigest())
- paths.append(path)
- assert len(set(hashes)) == count, ('Repeated walking image', state)
- assert len(set(paths)) == 28
- if manifest.get('version') == 2:
- from PIL import ImageOps
- for motion, count in [('stand', 1), ('walk', 6)]:
- for i in range(count):
- right = Image.open(ROOT / f'res/img/cloth/deepseek_bluewhale_{motion}_0_{i}.png')
- left = Image.open(ROOT / f'res/img/cloth/deepseek_bluewhale_{motion}_2_{i}.png')
- assert left.tobytes() == ImageOps.mirror(right).tobytes()
- checks.append('V2 art >=87 px high, no clipping, exact side-view mirrors and updated anchor offsets')
- assert (ROOT / 'res/img/ui/game' / (hero['icon_img'] + '.png')).exists()
- menu = ast.parse((ROOT / 'test_menu.py').read_text(encoding='utf-8-sig'))
- name_func = next(node for node in menu.body if isinstance(node, ast.FunctionDef) and node.name == 'show_hero_name')
- namespace = {}
- exec(compile(ast.Module(body=[name_func], type_ignores=[]), 'menu-name-check', 'exec'), namespace)
- assert '蓝色大肥鱼' in namespace['show_hero_name']('DeepseekBlueWhale')
- checks.append('28 distinct transparent sprites, 4 standing + 24 walking, hero/menu/icon registrations')
- def verify_real_game():
- expected_size = tuple(json.loads((HERE / 'asset_manifest.json').read_text(encoding='utf-8'))['canvas'])
- from client_local.const import color as C
- from client_local.frame import character
- from client_local.file_loader import fileLoader
- # New unique asset names must work through the real archive-aware loader.
- pygame.init()
- pygame.display.set_mode((800, 600))
- data = fileLoader.load_json('game/frame/character/CharacterDeepseekBlueWhale.json')
- for color in (C.CHARACTER_RED, C.CHARACTER_SKYBLUE):
- loaded = character.get_character(data, color, {})
- assert len(loaded) == 9
- assert len(loaded['LOSE']['Cloth']) == 1
- for direction in ('R', 'U', 'L', 'D'):
- assert len(loaded[direction]['Cloth']) == 6
- assert len(loaded['STAND_' + direction]['Cloth']) == 1
- for frame in loaded[direction]['Cloth']:
- assert frame.image.get_size() == expected_size
- # No recolor mask: navy/cyan identity is unaffected by player color.
- original = pygame.image.load(str(ROOT / 'res/img/cloth/deepseek_bluewhale_walk_3_0.png')).convert_alpha()
- assert pygame.image.tobytes(original, 'RGBA') == pygame.image.tobytes(loaded['D']['Cloth'][0].image, 'RGBA')
- checks.append('Real frame loader, all 8 states, no missing-texture fallback, fixed palette across player colors')
- spec = importlib.util.spec_from_file_location('deepseek_trial', str(ROOT / '试玩蓝色大肥鱼.py'))
- module = importlib.util.module_from_spec(spec)
- spec.loader.exec_module(module)
- class SmokeControl(module.BlueWhaleControl):
- def update(self):
- assert self.me.hero_name == 'DeepseekBlueWhale'
- assert self.current_level is not None
- original = (ROOT / 'config.json').read_bytes()
- # Exercise the engine's actual frame switching and Player.draw.
- screen = pygame.Surface((800, 600))
- for direction in ('R', 'U', 'L', 'D'):
- self.me.orientation = direction
- for walking in (False, True):
- self.me.walking = walking
- self.me.character_frame_trigger = True
- for index in range(6):
- self.me.update_frame(pygame.time.get_ticks() + 1000 + index * 120)
- self.me.draw(screen)
- self.me.walking = False
- self.me.orientation = 'D'
- self.me.character_frame_trigger = True
- self.current_level.update(self.screen)
- self.me.rooted = 0
- positions = []
- for direction in ('R', 'U', 'L', 'D'):
- self.me.set_motion(direction)
- for index in range(8):
- pygame.time.delay(20)
- self.current_level.update(self.screen)
- positions.append((self.me.x_pos, self.me.y_pos))
- assert len(set(positions)) > 1, 'Player did not move in the live Level update'
- self.me.set_motion()
- self.current_level.update(self.screen)
- checks.append('Live Level.update movement with the new character')
- bombs_before = len(self.current_level.bomb_instances)
- remaining_before = self.me.remain_bombs
- self.me.set_bomb()
- assert len(self.current_level.bomb_instances) == bombs_before + 1
- assert self.me.remain_bombs == remaining_before - 1
- from client_local.sprite.player import PlayerState
- self.me.state = PlayerState.LOSE
- self.me.update_frame_dead(pygame.time.get_ticks() + 2000)
- self.me.draw(screen)
- self.me.state = PlayerState.NORMAL
- self.me.character_frame_trigger = True
- self.me.update_frame(pygame.time.get_ticks() + 2100)
- checks.append('Live bomb placement and a valid LOSE-state sprite fallback')
- pygame.image.save(pygame.display.get_surface(), str(HERE / 'in_game.png'))
- assert (ROOT / 'config.json').read_bytes() == original
- checks.append('Real Hero/Level initialization, standing/walking frame updates and draw in all four directions')
- SmokeControl()
- pygame.quit()
- if __name__ == '__main__':
- before = hashlib.sha256((ROOT / 'config.json').read_bytes()).hexdigest()
- verify_assets()
- verify_real_game()
- assert hashlib.sha256((ROOT / 'config.json').read_bytes()).hexdigest() == before
- (HERE / 'runtime_verification.json').write_text(json.dumps({'ok': True, 'checks': checks,
- 'config_sha256_unchanged': before}, indent=2, ensure_ascii=False), encoding='utf-8')
- print(json.dumps({'ok': True, 'checks': checks}, ensure_ascii=False))
|