def __init__(self, engine: PhonemeEngine, parent_game, position=(0, 0, 0), texture='rect835.png', text: Optional[str] = '', **kwargs): super().__init__(parent=scene, position=position, model='cube', origin_y=.5, texture=texture, color=color.color(0, 0, random.uniform(.9, 1.0)), text=text, text_color=color.red, double_sided=True, **kwargs) self.phoneme_store = engine self.parent_game = parent_game
def make_html(style, file_name): if style == 'light': base_color = color.color(60, 0, .99) background_color = lerp(base_color, base_color.invert(), 0) else: base_color = color.color(60, 1, .01) background_color = lerp(base_color, base_color.invert(), .125) text_color = lerp(background_color, background_color.invert(), .9) example_color = lerp(background_color, text_color, .1) scrollbar_color = html_color(lerp(background_color, text_color, .1)) link_color = html_color(color.gray) init_color = html_color(base_color.invert()) style = f''' <style> html {{ scrollbar-face-color: {html_color(text_color)}; scrollbar-base-color: {html_color(text_color)}; scrollbar-3dlight-color: {html_color(text_color)}4; scrollbar-highlight-color: {html_color(text_color)}; scrollbar-track-color: {html_color(background_color)}; scrollbar-arrow-color: {html_color(background_color)}; scrollbar-shadow-color: {html_color(text_color)}; scrollbar-dark-shadow-color: {html_color(text_color)}; }} ::-webkit-scrollbar {{ width: 8px; height: 3px;}} ::-webkit-scrollbar {{ width: 8px; height: 3px;}} ::-webkit-scrollbar-button {{ background-color: {scrollbar_color}; }} ::-webkit-scrollbar-track {{ background-color: {html_color(background_color)};}} ::-webkit-scrollbar-track-piece {{ background-color: {html_color(background_color)};}} ::-webkit-scrollbar-thumb {{ height: 50px; background-color: {scrollbar_color}; border-radius: 3px;}} ::-webkit-scrollbar-corner {{ background-color: {html_color(background_color)};}} ::-webkit-resizer {{ background-color: {html_color(background_color)};}} body {{ margin: auto; background-color: {html_color(background_color)}; color: {html_color(text_color)}; font-family: monospace; position: absolute; top:0; left: 24em; font-size: 1.375em; font-weight: lighter; max-width: 100%; overflow-x: hidden; white-space: pre-wrap; }} a {{ color: {link_color}; }} g {{ color: gray; }} .example {{ padding-left: 1em; background-color: {html_color(example_color)}; }} .params {{ color:{init_color}; font-weight:bold; }} </style> ''' # return style html = '<title> ursina cheat sheet</title>' sidebar = ''' <div class="sidebar" style=" left: 0px; position: fixed; top: 0px; padding-top:40px; padding-left:20px; bottom: 0; overflow-y: scroll; width: 15em; z-index: 1; "> <a href="cheat_sheet.html">light</a> <a href="cheat_sheet_dark.html">dark</a> ''' for i, class_dictionary in enumerate( (most_used_info, module_info, class_info, prefab_info, script_info, asset_info)): for name, attrs_and_functions in class_dictionary.items(): print('generating docs for', name) location, params, attrs, funcs, example = attrs_and_functions params = params.replace('__init__', name.split('(')[0]) params = params.replace('(self, ', '(') params = params.replace('(self)', '()') name = name.replace('ShowBase', '') name = name.replace('NodePath', '') for parent_class in ('Entity', 'Button', 'Draggable', 'Text', 'Collider', 'Mesh', 'Prismatoid'): name = name.replace( f'({parent_class})', f'(<a style="color: gray;" href="#{parent_class}">{parent_class}</a>)' ) base_name = name if '(' in base_name: base_name = base_name.split('(')[0] base_name = base_name.split(')')[0] name = name.replace('(', '<g>(') name = name.replace(')', ')</g>') v = lerp(text_color.v, background_color.v, .2) # v = .5 col = color.color(50 - (i * 30), .9, v) col = html_color(col) sidebar += f'''<a style="color:{col};" href="#{base_name}">{base_name}</a>\n''' html += '\n' html += f'''<div id="{base_name}"><div id="{base_name}" style="color:{col}; font-size:1.75em; font-weight:normal;">{name}</div>''' html += '<div style="position:relative; padding:0em 0em 2em 1em; margin:0;">' # location location = str(location) if 'ursina' in location: location = location.split('ursina')[-1].replace('\\', '.')[:-3] html += f'''<g>ursina{location}</g><br><br>''' if params: params = f'<params class="params">{params}</params>\n' html += params + '\n' for e in attrs: if ' = ' in e: e = f'''{e.split(' = ')[0]}<g> = {e.split(' = ')[1]}</g> ''' html += f'''{e}\n''' html += '\n' for e in funcs: e = f'{e[0]}(<g>{e[1]}</g>) <g>{e[2]}</g>' html += e + '\n' if example: html += '\n<div class="example">' + example + '\n</div>' html += '\n</div></div>' html = html.replace('<g></g>', '') sidebar += '\n' sidebar += '</div>' html += '</div>' html = sidebar + style + '<div id="content">' + html + '</div>' + '</body>' with open(file_name, 'w', encoding='utf-8') as f: f.write(html)
for class_name, class_definition in classes.items(): if 'def __init__' in class_definition: params = '__init__(' + class_definition.split( 'def __init__(')[1].split('\n')[0][:-1] attrs = get_class_attributes(class_definition) methods = get_functions(class_definition, is_class=True) example = get_example(code) asset_info[class_name] = (params, attrs, methods, example) def html_color(color): return f'hsl({color.h}, {int(color.s*100)}%, {int(color.v*100)}%)' base_color = color.color(60, 1, .01) base_color = color.color(60, 0, .99) # background_color = color.color(0,0,.9) background_color = lerp(base_color, base_color.invert(), .125) background_color = lerp(base_color, base_color.invert(), 0) text_color = lerp(background_color, background_color.invert(), .9) example_color = lerp(background_color, text_color, .1) scrollbar_color = html_color(lerp(background_color, text_color, .1)) link_color = html_color(color.gray) init_color = html_color(base_color.invert()) style = f''' <style> html {{ scrollbar-face-color: {html_color(text_color)}; scrollbar-base-color: {html_color(text_color)};
def alpha(self, value): if value > 1: value = value / 255 self.color = color.color(self.color.h, self.color.s, self.color.v, value)
def create_text_section(self, text, tag='', x=0, y=0): # print(text, tag) self.text_node = TextNode('t') self.text_node_path = self.attachNewNode(self.text_node) try: self.text_node.setFont(self._font) except: pass # default font if tag != '<>': tag = tag[1:-1] if tag.startswith('hsb('): # set color based on numbers tag = tag[4:-1] hsb_values = tuple(float(e.strip()) for e in tag.split(',')) self.current_color = color.color(*hsb_values) elif tag.startswith('rgb('): # set color based on numbers tag = tag[4:-1] rgb_values = (float(e.strip()) for e in tag.split(',')) self.current_color = color.rgba(*rgb_values) if tag.startswith('scale:'): scale = tag.split(':')[1] self.scale_override = float(scale) elif tag.startswith('image:'): texture_name = tag.split(':')[1] image = Entity( parent=self.text_node_path, name='inline_image', model='quad', texture=texture_name, color=self.current_color, scale=1, # position=(x*self.size*self.scale_override, y*self.size*self.line_height), origin=(.0, -.25), add_to_scene_entities=False, ) if not image.texture: destroy(image) else: self.images.append(image) # self.text_node.remove_node() # self.text_node = image else: if tag in self.text_colors: self.current_color = self.text_colors[tag] self.text_node_path.setScale(self.scale_override * self.size) self.text_node.setText(text) self.text_node.setTextColor(self.current_color) self.text_node.setPreserveTrailingWhitespace(True) # self.text_node_path.setPos( # x * self.size * self.scale_override, # 0, # (y * self.size * self.line_height) - .75 * self.size) self.text_node_path.setPos(x * self.size * self.scale_override, (y * self.size * self.line_height) - .75 * self.size, 0) self.text_nodes.append(self.text_node_path) return self.text_node
def make_html(style, file_name): if style == 'light': base_color = color.color(60, 0, .99) background_color = lerp(base_color, base_color.invert(), 0) else: base_color = color.color(60, 1, .01) background_color = lerp(base_color, base_color.invert(), .125) text_color = lerp(background_color, background_color.invert(), .9) example_color = lerp(background_color, text_color, .1) scrollbar_color = html_color(lerp(background_color, text_color, .1)) link_color = html_color(color.gray) init_color = html_color(base_color.invert()) style = f''' <style> html {{ scrollbar-face-color: {html_color(text_color)}; scrollbar-base-color: {html_color(text_color)}; scrollbar-3dlight-color: {html_color(text_color)}4; scrollbar-highlight-color: {html_color(text_color)}; scrollbar-track-color: {html_color(background_color)}; scrollbar-arrow-color: {html_color(background_color)}; scrollbar-shadow-color: {html_color(text_color)}; scrollbar-darkshadow-color: {html_color(text_color)}; }} ::-webkit-scrollbar {{ width: 8px; height: 3px;}} ::-webkit-scrollbar {{ width: 8px; height: 3px;}} ::-webkit-scrollbar-button {{ background-color: {scrollbar_color}; }} ::-webkit-scrollbar-track {{ background-color: {html_color(background_color)};}} ::-webkit-scrollbar-track-piece {{ background-color: {html_color(background_color)};}} ::-webkit-scrollbar-thumb {{ height: 50px; background-color: {scrollbar_color}; border-radius: 3px;}} ::-webkit-scrollbar-corner {{ background-color: {html_color(background_color)};}} ::-webkit-resizer {{ background-color: {html_color(background_color)};}} body {{ margin: auto; background-color: {html_color(background_color)}; color: {html_color(text_color)}; font-family: monospace; position: absolute; top:0; left: 24em; font-size: 1.375em; font-weight: lighter; max-width: 100%; overflow-x: hidden; white-space: pre-wrap; }} a {{ color: {link_color}; }} purple {{color: hsl(289.0, 50%, 50%);}} gray {{color: gray;}} olive {{color: olive;}} yellow {{color: darkgoldenrod;}} green {{color: seagreen;}} blue {{color: hsl(210, 50%, 50%);}} .example {{ padding-left: 1em; background-color: {html_color(example_color)}; }} .params {{ color:{init_color}; font-weight:bold; }} </style> ''' # return style html = '<title> ursina cheat sheet</title>' html += ''' <b>Ursina cheat sheet</b> This document lists most modules and classes in ursina. Each section is structured as follows: ClassName(BaseClass) module location parameters How instantiate the class, ie. Button(text='', **kwargs). '**kwargs' in this case, means you can give it optional keyword arguments. For example, Button('Start', scale=.25, color=color.blue, position=(-.1,.25)) also incldues information on how big the button should be, its color and its position. attributes Names of values we can get/set, sometimes followed by its starting value and a short explanation. For example, 'scale', 'color' and 'position' are attributes we gave the Button above. These are members of Entity, which Button class inherits from, so the Button class can also access these. methods/functions these ends with (), which means they are functions that can be called. Also lists their parameters and default arguments. For example, Entity has a method called 'look_at()'. You need to give it a 'target' (an Entity or position) to look at and optionally say which axis will be facing the target. example You can search the document with Ctrl+F for instant search results. ''' sidebar = ''' <div class="sidebar" style=" left: 0px; position: fixed; top: 0px; padding-top:40px; padding-left:20px; bottom: 0; overflow-y: scroll; width: 15em; z-index: 1; "> <a href="cheat_sheet.html">light</a> <a href="cheat_sheet_dark.html">dark</a> ''' for i, class_dictionary in enumerate( (most_used_info, module_info, class_info, prefab_info, script_info, asset_info)): for name, attrs_and_functions in class_dictionary.items(): print('generating docs for', name) location, params, attrs, funcs, example = attrs_and_functions params = params.replace('__init__', name.split('(')[0]) params = params.replace('(self, ', '(') params = params.replace('(self)', '()') name = name.replace('ShowBase', '') name = name.replace('NodePath', '') for parent_class in ('Entity', 'Button', 'Draggable', 'Text', 'Collider', 'Mesh', 'Prismatoid'): name = name.replace( f'({parent_class})', f'(<a style="color: gray;" href="#{parent_class}">{parent_class}</a>)' ) base_name = name if '(' in base_name: base_name = base_name.split('(')[0] base_name = base_name.split(')')[0] name = name.replace('(', '<gray>(') name = name.replace(')', ')</gray>') v = lerp(text_color.v, background_color.v, .2) # v = .5 col = color.color(50 - (i * 30), .9, v) col = html_color(col) sidebar += f'''<a style="color:{col};" href="#{base_name}">{base_name}</a>\n''' html += '\n' html += f'''<div id="{base_name}"><div id="{base_name}" style="color:{col}; font-size:1.75em; font-weight:normal;">{name}</div>''' html += '<div style="position:relative; padding:0em 0em 2em 1em; margin:0;">' # location location = str(location) if 'ursina' in location: location = location.split('ursina')[-1] github_link = 'https://github.com/pokepetter/ursina/tree/master/ursina' + location.replace( '\\', '/') location = location.replace('\\', '.')[:-3] html += f'''<a href="{github_link}"><gray>ursina{location}</gray></a><br><br>''' if params: params = f'<params class="params">{params}</params>\n' html += params + '\n' for e in attrs: if ' = ' in e: e = f'''{e.split(' = ')[0]}<gray> = {e.split(' = ')[1]}</gray> ''' html += f'''{e}\n''' html += '\n' for e in funcs: e = f'{e[0]}(<gray>{e[1]}</gray>) <gray>{e[2]}</gray>' html += e + '\n' if example: html += '\n<div class="example">' + example + '\n</div>' html += '\n</div></div>' html = html.replace('<gray></gray>', '') sidebar += '\n' sidebar += '</div>' html += '</div>' html = sidebar + style + '<div id="content">' + html + '</div>' + '</body>' with open(file_name, 'w', encoding='utf-8') as f: f.write(html)