def write_init(self, writer): data = self.get_data() data.skipBytes(8) writer.putln('max_x_vel = %s;' % read_value(data)) writer.putln('max_y_vel = %s;' % read_value(data)) writer.putln('x_accel = %s;' % read_value(data)) writer.putln('x_decel = %s;' % read_value(data)) writer.putln('gravity = %s;' % read_value(data)) writer.putln('jump_strength = %s;' % read_value(data)) writer.putln('jump_hold_height = %s;' % read_value(data)) writer.putln('step_up = %s;' % read_value(data)) writer.putln('slope_correction = %s;' % read_value(data)) writer.putln(to_c('through_collision_top = %s;', data.readByte() == 1)) writer.putln(to_c('jump_through = %s;', data.readByte() == 1))
def write_init(self, writer): data = self.get_data() flags = data.readShort(True) filename = data.readString() writer.putln('auto_save = true;') writer.putln('is_global = false;') writer.putln('data = new SectionMap();') if filename: if flags & APP_DATA: filename = to_c('platform_get_appdata_dir() + %r', '/' + filename) else: filename = to_c('%r', filename) writer.putlnc('load_file(%s);', filename)
def write_init(self, writer): data = self.get_data() x_size = max(1, data.readInt()) y_size = max(1, data.readInt()) z_size = max(1, data.readInt()) flags = BitDict('Numeric', 'Text', 'Base1', 'Global') flags.setFlags(data.readInt()) is_numeric = flags['Numeric'] offset = int(flags['Base1']) init = to_c('initialize(%s, %s, %s, %s, %s);', is_numeric, offset, x_size, y_size, z_size) if flags['Global']: glob = self.get_global('ArrayObject::SavedArray') writer.putlnc('global_data = &%s;', glob) writer.putlnc('if (!%s.init) {', glob) writer.indent() writer.putlnc('%s.init = true;', glob) writer.putln(init) writer.dedent() writer.putln('} else {') writer.indent() writer.putlnc('data = %s.value;', glob) writer.end_brace() else: writer.putln(init)
def write_init(self, writer): data = self.get_data() x_size = max(1, data.readInt()) y_size = max(1, data.readInt()) z_size = max(1, data.readInt()) flags = BitDict('Numeric', 'Text', 'Base1', 'Global') flags.setFlags(data.readInt()) is_numeric = flags['Numeric'] offset = int(flags['Base1']) init = to_c('initialize(%s, %s, %s, %s, %s);', is_numeric, offset, x_size, y_size, z_size) if flags['Global']: writer.putln('static ArrayData static_global_data;') writer.putln('global_data = &static_global_data;') writer.putln('static bool init = false;') writer.putln('if (!init) {') writer.indent() writer.putln('init = true;') writer.putln(init) writer.dedent() writer.putln('} else {') writer.indent() writer.putln('data = static_global_data;') writer.end_brace() else: writer.putln(init)
def write_init(self, writer): data = self.get_data() flags = BitDict('FreeFlag', 'VerticalScrollbar', 'Sort', 'Border', 'HideOnStart', 'SystemColor', '3DLook', 'ScrollToNewline') width = data.readShort() height = data.readShort() is_unicode = self.data.settings.get('unicode', False) font = self.data.new(LogFont, data, old=not is_unicode) font_color = data.readColor() self.data.readString(data, 40) data.skipBytes(16 * 4) back_color = data.readColor() flags.setFlags(data.readInt()) line_count = data.readShort(True) index_offset = -1 if data.readInt() == 1 else 0 data.skipBytes(4 * 3) lines = [] for _ in xrange(line_count): line = self.data.readString(data) writer.putln(to_c('add_line(%r);', line)) if flags['HideOnStart']: writer.putln('set_visible(false);') if flags['Sort']: writer.putln('list_flags |= SORT_LIST;') writer.putlnc('index_offset = current_line = %s;', index_offset)
def write_init(self, writer): data = self.get_data() flags = BitDict( 'FreeFlag', 'VerticalScrollbar', 'Sort', 'Border', 'HideOnStart', 'SystemColor', '3DLook', 'ScrollToNewline' ) width = data.readShort() height = data.readShort() # XXX support unicode font = LogFont(data, old = True) font_color = data.readColor() data.readString(40) data.skipBytes(16 * 4) back_color = data.readColor() flags.setFlags(data.readInt()) line_count = data.readShort(True) index_offset = -1 if data.readInt() == 1 else 0 data.skipBytes(4 * 3) lines = [] for _ in xrange(line_count): line = data.readString() writer.putln(to_c('add_line(%r);', line)) if flags['HideOnStart']: writer.putln('set_visible(false);')
def write_init(self, writer): text = self.common.text lines = [paragraph.value for paragraph in text.items] for paragraph in text.items: writer.putln(to_c('add_line(%r);', paragraph.value)) # objects_file.putln('font = font%s' % text.items[0].font) writer.putln('width = %s;' % text.width) writer.putln('height = %s;' % text.height) writer.putln('blend_color = %s;' % make_color(text.items[0].color)) font = text.items[0].font writer.putln('bold = font%s.bold;' % font) writer.putln('italic = font%s.italic;' % font) writer.putln('font = get_font(font%s.size);' % font) paragraph = text.items[0] if paragraph.flags['HorizontalCenter']: horizontal = 'ALIGN_HCENTER' elif paragraph.flags['RightAligned']: horizontal = 'ALIGN_RIGHT' else: horizontal = 'ALIGN_LEFT' if paragraph.flags['VerticalCenter']: vertical = 'ALIGN_VCENTER' elif paragraph.flags['BottomAligned']: vertical = 'ALIGN_BOTTOM' else: vertical = 'ALIGN_TOP' writer.putln('alignment = %s | %s;' % (horizontal, vertical))
def write_init(self, writer): common = self.common animations = common.animations.loadedAnimations max_anim = max(animations) + 1 writer.putlnc('this->animations = &%s;', self.animations_name) writer.putlnc('if (!%s) {', self.initialized_name) writer.indent() writer.putlnc('%s = true;', self.initialized_name) scale_method = self.converter.config.get_scale_method(self) for name, images in self.images: for image_index, image in enumerate(images): writer.putlnc('%s[%s] = %s;', name, image_index, image) if scale_method is None: continue writer.putlnc('%s[%s]->set_filter(%s);', name, image_index, scale_method) writer.end_brace() flags = common.newFlags writer.putln(to_c('collision_box = %s;', flags['CollisionBox'])) writer.putlnc('auto_rotate = %s;', bool(flags['AutomaticRotation'])) writer.putlnc('transparent = %s;', self.get_transparent()) writer.putln('animation = %s;' % get_animation_name(min(animations))) if APPEARING in animations: writer.putln('forced_animation = current_animation = APPEARING;') else: writer.putln('current_animation = animation;') if len(animations) == 1 and DISAPPEARING in animations: writer.putln('flags |= FADEOUT;') self.destruct = True writer.putln('initialize_active();')
def write_scene(self, data): index = self.data.scenes.index(data) scene = self.open_code('scene%s.h' % (index+1)) scene.put_includes('common.h', 'objects.h') class_name = 'Scene%s' % (index+1) scene.put_class(class_name, 'Scene') scene.put_access('public') scene.put_line(to_c('%s(GameManager * manager) : ' 'Scene(%r, %s, %s, %s, %s, manager)', class_name, data.name, data.width, data.height, make_color(data.background), index)) scene.start_brace() scene.end_brace() scene.put_func('void on_start') for instance in data.instances: scene.put_line('add_object(new %s(%s, %s));' % (self.object_type_names[instance.object_type], instance.x, instance.y)) scene.end_brace() scene.end_brace(True) scene.close()
def write_init(self, writer): common = self.common animations = common.animations.loadedAnimations max_anim = max(animations)+1 writer.putlnc('this->animations = &%s;', self.animations_name) writer.putlnc('if (!%s) {', self.initialized_name) writer.indent() writer.putlnc('%s = true;', self.initialized_name) scale_method = self.converter.config.get_scale_method(self) for name, images in self.images: for image_index, image in enumerate(images): writer.putlnc('%s[%s] = %s;', name, image_index, image) if scale_method is None: continue writer.putlnc('%s[%s]->set_filter(%s);', name, image_index, scale_method) writer.end_brace() flags = common.newFlags writer.putln(to_c('collision_box = %s;', flags['CollisionBox'])) writer.putlnc('auto_rotate = %s;', bool(flags['AutomaticRotation'])) writer.putlnc('transparent = %s;', self.get_transparent()) writer.putln('animation = %s;' % get_animation_name(min(animations))) if APPEARING in animations: writer.putln('forced_animation = current_animation = APPEARING;') else: writer.putln('current_animation = animation;') if len(animations) == 1 and DISAPPEARING in animations: writer.putln('flags |= FADEOUT;') self.destruct = True writer.putln('initialize_active();')
def write(self, writer): obj = (self.data.objectInfo, self.data.objectType) name = self.converter.get_object_writer(obj).data.name if name == SPRITES_STRING: writer.put('set_image_path(%s);' % self.convert_index(0)) elif name == FONT_STRING: writer.put('set_font_path(%s);' % self.convert_index(0)) elif name == RESIZE_STRING: writer.putc('set_window_resize(%s);', self.get_bool(0)) elif name == SHADERS_STRING: writer.put('set_shader_path(%s);' % self.convert_index(0)) elif name == SOUNDS_STRING: writer.put('set_sounds_path(%s);' % self.convert_index(0)) elif name == STEAM_STRING: v = self.get_bool(0) # writer.put(to_c('SteamObject::set_enabled(%s);', v)) elif name == REMOTE_STRING: v = self.convert_index(0) writer.put('platform_set_remote_setting(%s);' % v) elif name == BORDER_STRING: v = self.get_bool(0) writer.put(to_c('platform_set_border(%s);', v)) elif name == UTF8_STRING: v = self.get_bool(0) if v: defines.append('#define CHOWDREN_TEXT_USE_UTF8')
def putdefine(self, name, value=''): if value is None: return if value == '': self.putlnc('#define %s', name) return if isinstance(value, str): value = to_c('%r', value, cpp=False) self.putln('#define %s %s' % (name, value))
def write_init(self, writer): text = self.common.rtf writer.putln(to_c('add_line("");',)) writer.putln('width = %s;' % text.width) writer.putln('height = %s;' % text.height) writer.putln('blend_color = Color(0, 0, 0);') writer.putln('bold = false;') writer.putln('italic = false;') writer.putln('alignment = ALIGN_HCENTER | ALIGN_VCENTER;')
def write_init(self, writer): text = self.common.rtf writer.putln(to_c('add_line("");', )) writer.putln('width = %s;' % text.width) writer.putln('height = %s;' % text.height) writer.putln('blend_color = Color(0, 0, 0);') writer.putln('bold = false;') writer.putln('italic = false;') writer.putln('alignment = ALIGN_HCENTER | ALIGN_VCENTER;')
def write_init(self, writer): text = self.common.rtf writer.putln(to_c('add_line("");')) writer.putln("width = %s;" % text.width) writer.putln("height = %s;" % text.height) writer.putln("blend_color = Color(0, 0, 0);") writer.putln("bold = false;") writer.putln("italic = false;") writer.putln("alignment = ALIGN_HCENTER | ALIGN_VCENTER;")
def write_init(self, writer): data = self.get_data() x_size = max(1, data.readInt()) y_size = max(1, data.readInt()) z_size = max(1, data.readInt()) flags = BitDict('Numeric', 'Text', 'Base1', 'Global') flags.setFlags(data.readInt()) is_numeric = flags['Numeric'] offset = int(flags['Base1']) writer.putln(to_c('initialize(%s, %s, %s, %s, %s);', is_numeric, offset, x_size, y_size, z_size))
def write_object_type(self, type_id, object_type, objects): # XXX put object name here instead of class name name = object_type.get_class_name() subclass = object_type.get_class_name() class_name = to_cap_words(name, 'Obj') + str(type_id) self.object_type_names[type_id] = class_name objects.put_class(class_name, subclass) objects.put_access('public') objects.put_line('static const int type_id = %s;' % type_id) parameters = [to_c('%r', name), 'x', 'y', 'type_id'] extra_parameters = [convert_class_parameter(item) for item in object_type.get_parameters()] parameters = ', '.join(extra_parameters + parameters) init_list = [to_c('%s(%s)', subclass, parameters)] for name, value in object_type.get_init_list(): init_list.append(to_c('%s(%r)', name, value)) init_list = ', '.join(init_list) objects.put_line(to_c('%s(int x, int y) : %s', class_name, init_list)) objects.start_brace() object_type.write_init(objects) objects.end_brace() objects.end_brace(True)
def write(self, writer): filename = self.convert_index(0) reader = self.parameters[1].loader.get_reader() load = reader.readByte() path = reader.readByte() clear = reader.readByte() flags = reader.readByte() if load != LOAD_FILE: raise NotImplementedError() if path != KEEP_PATH: raise NotImplementedError() if clear != KEEP_PATH: raise NotImplementedError() if flags != READ_ONLY: raise NotImplementedError() writer.put(to_c('load_file(%s, true, true, true);', filename))
def write_init(self, writer): common = self.common animations = common.animations.loadedAnimations max_anim = max(animations)+1 writer.putlnc('this->animations = &%s;', self.animations_name) writer.putlnc('if (!%s) {', self.initialized_name) writer.indent() writer.putlnc('%s = true;', self.initialized_name) for name, images in self.images: for image_index, image in enumerate(images): writer.putlnc('%s[%s] = %s;', name, image_index, image) writer.end_brace() flags = common.newFlags writer.putln(to_c('collision_box = %s;', flags['CollisionBox'])) writer.putlnc('auto_rotate = %s;', bool(flags['AutomaticRotation'])) writer.putlnc('transparent = %s;', self.get_transparent()) writer.putln('animation = %s;' % get_animation_name(min(animations))) if APPEARING in animations: writer.putln('forced_animation = APPEARING;') writer.putln('initialize_active();')
def write_init(self, writer): text = self.common.text lines = [paragraph.value for paragraph in text.items] writer.putln('width = %s;' % text.width) writer.putln('height = %s;' % text.height) writer.putln('blend_color = %s;' % make_color(text.items[0].color)) font = text.items[0].font font_info = self.converter.fonts[font] writer.putlnc('bold = %s;', font_info.isBold()) writer.putlnc('italic = %s;', bool(font_info.italic)) writer.putlnc('font_name = %r;', font_info.faceName) flags = [] if font_info.isBold(): flags.append('FTTextureFont::BOLD') flags = ' | '.join(flags) if not flags: flags = '0' writer.putlnc('font = get_font(%s, %s);', font_info.getSize(), flags) paragraph = text.items[0] if paragraph.flags['HorizontalCenter']: horizontal = 'ALIGN_HCENTER' elif paragraph.flags['RightAligned']: horizontal = 'ALIGN_RIGHT' else: horizontal = 'ALIGN_LEFT' if paragraph.flags['VerticalCenter']: vertical = 'ALIGN_VCENTER' elif paragraph.flags['BottomAligned']: vertical = 'ALIGN_BOTTOM' else: vertical = 'ALIGN_TOP' writer.putln('alignment = %s | %s;' % (horizontal, vertical)) for paragraph in text.items: writer.putln(to_c('add_line(%r);', paragraph.value))
def write_init(self, writer): text = self.common.text writer.putln('width = %s;' % text.width) writer.putln('height = %s;' % text.height) writer.putln('blend_color = %s;' % make_color(text.items[0].color)) font = text.items[0].font font_info = self.converter.fonts[font] writer.putlnc('bold = %s;', font_info.isBold()) writer.putlnc('italic = %s;', bool(font_info.italic)) writer.putlnc('font_name = %r;', font_info.faceName) flags = [] if font_info.isBold(): flags.append('FTTextureFont::BOLD') flags = ' | '.join(flags) if not flags: flags = '0' writer.putlnc('font = get_font(%s, %s);', font_info.getSize(), flags) paragraph = text.items[0] if paragraph.flags['HorizontalCenter']: horizontal = 'ALIGN_HCENTER' elif paragraph.flags['RightAligned']: horizontal = 'ALIGN_RIGHT' else: horizontal = 'ALIGN_LEFT' if paragraph.flags['VerticalCenter']: vertical = 'ALIGN_VCENTER' elif paragraph.flags['BottomAligned']: vertical = 'ALIGN_BOTTOM' else: vertical = 'ALIGN_TOP' writer.putln('alignment = %s | %s;' % (horizontal, vertical)) for paragraph in text.items: text = self.converter.config.get_string(paragraph.value) writer.putln(to_c('add_line(%r);', text))
def write_init(self, writer): text = self.common.text lines = [paragraph.value for paragraph in text.items] writer.putln("width = %s;" % text.width) writer.putln("height = %s;" % text.height) writer.putln("blend_color = %s;" % make_color(text.items[0].color)) font = text.items[0].font font_info = self.converter.fonts[font] writer.putlnc("bold = %s;", font_info.isBold()) writer.putlnc("italic = %s;", bool(font_info.italic)) writer.putlnc("font_name = %r;", font_info.faceName) flags = [] if font_info.isBold(): flags.append("FTTextureFont::BOLD") flags = " | ".join(flags) if not flags: flags = "0" writer.putlnc("font = get_font(%s, %s);", font_info.getSize(), flags) paragraph = text.items[0] if paragraph.flags["HorizontalCenter"]: horizontal = "ALIGN_HCENTER" elif paragraph.flags["RightAligned"]: horizontal = "ALIGN_RIGHT" else: horizontal = "ALIGN_LEFT" if paragraph.flags["VerticalCenter"]: vertical = "ALIGN_VCENTER" elif paragraph.flags["BottomAligned"]: vertical = "ALIGN_BOTTOM" else: vertical = "ALIGN_TOP" writer.putln("alignment = %s | %s;" % (horizontal, vertical)) for paragraph in text.items: writer.putln(to_c("add_line(%r);", paragraph.value))
def write_init(self, writer): data = self.get_data() flags = BitDict( 'FreeFlag', 'VerticalScrollbar', 'Sort', 'Border', 'HideOnStart', 'SystemColor', '3DLook', 'ScrollToNewline' ) width = data.readShort() height = data.readShort() is_unicode = self.data.settings.get('unicode', False) font = self.data.new(LogFont, data, old=not is_unicode) font_color = data.readColor() self.data.readString(data, 40) data.skipBytes(16 * 4) back_color = data.readColor() flags.setFlags(data.readInt()) line_count = data.readShort(True) index_offset = -1 if data.readInt() == 1 else 0 data.skipBytes(4 * 3) for _ in xrange(line_count): line = self.data.readString(data) writer.putln(to_c('add_line(%r);', line)) if flags['HideOnStart']: writer.putln('set_visible(false);') if flags['Sort']: writer.putln('list_flags |= SORT_LIST;') if line_count: writer.putln('sort();') writer.putlnc('index_offset = current_line = %s;', index_offset)
def write_init(self, writer): data = self.get_data() flags = BitDict('FreeFlag', 'VerticalScrollbar', 'Sort', 'Border', 'HideOnStart', 'SystemColor', '3DLook', 'ScrollToNewline') width = data.readShort() height = data.readShort() # XXX support unicode font = LogFont(data, old=True) font_color = data.readColor() data.readString(40) data.skipBytes(16 * 4) back_color = data.readColor() flags.setFlags(data.readInt()) line_count = data.readShort(True) index_offset = -1 if data.readInt() == 1 else 0 data.skipBytes(4 * 3) lines = [] for _ in xrange(line_count): line = data.readString() writer.putln(to_c('add_line(%r);', line)) if flags['HideOnStart']: writer.putln('set_visible(false);')
def putc(self, value, *arg, **kw): value = to_c(value, *arg, **kw) self.put(value, **kw)
def __init__(self, project, outdir): self.project = project self.data = data = project.data self.outdir = outdir copy_tree(os.path.join(os.getcwd(), RUNTIME_DIR), outdir) # config.h config = self.open_code('config.h') includes = ['common.h'] scene_classes = [] for i in xrange(len(data.scenes)): includes.append('scene%s.h' % (i+1)) scene_classes.append('Scene%s' % (i+1)) config.put_includes(*includes) config.put_define('WINDOW_WIDTH', 800) config.put_define('WINDOW_HEIGHT', 600) config.put_define('NAME', repr_c(data.name)) config.put_line('static Scene ** scenes = NULL;') config.put_func('Scene ** get_scenes', 'GameManager * manager') config.put_line('if (scenes) return scenes;') config.put_line('scenes = new Scene*[%s];' % len(scene_classes)) for i, scene in enumerate(scene_classes): config.put_line('scenes[%s] = new %s(manager);' % (i, scene)) config.put_line('return scenes;') config.end_brace() config.close() # images.h images = self.open_code('images.h') images.put_includes('common.h') images.start_guard('IMAGES_H') for image_id, image in project.images.iteritems(): image.save(self.get_filename('images', '%s.png' % image_id)) image_name = get_image(image) images.put_line(to_c( 'static Image %s(%r, %s, %s);', image_name, str(image_id), image.hotspot_x, image.hotspot_y)) images.close_guard('IMAGES_H') images.close() # objects.h self.object_type_names = {} objects = self.open_code('objects.h') objects.put_includes('common.h', 'images.h') for type_id, object_type in project.object_types.iteritems(): self.write_object_type(type_id, object_type, objects) objects.close() # object type implementations type_files = set() for type_id, object_type in project.object_types.iteritems(): type_files.add(object_type.get_runtime()) type_includes = set() for name, path in type_files: ext = os.path.splitext(path)[1] name = '%s%s' % (name, ext) new_path = self.get_filename('objects', name) shutil.copyfile(path, new_path) type_includes.add('objects/%s' % name) types = self.open_code('objecttypes.h') types.put_includes(*type_includes) types.close() # scenes for scene in data.scenes: self.write_scene(scene)
def putlnc(self, line, *arg, **kw): line = to_c(line, *arg, **kw) self.putln(line, **kw)