Пример #1
0
def makecfg(fname):
    mu = Mu()
    if not mu.read(fname):
        print("could not read: " + fname)
        raise
    cfg = ConfigNode()
    add_textures(mu, cfg)
    add_materials(mu, cfg)
    add_object(mu, mu.obj, cfg)
    print(cfg.ToString())
Пример #2
0
def wheel_cfg(name, wheel):
    node = ConfigNode()
    node.AddValue("name", name)
    node.AddValue("mass", wheel.mass)
    node.AddValue("radius", wheel.radius)
    node.AddValue("suspensionDistance", wheel.suspensionDistance)
    node.AddValue("center", ValueString(wheel.center))
    spring_cfg(node.AddNode("suspensionSpring"), wheel.suspensionSpring)
    friction_cfg(node.AddNode("forwardFriction"), wheel.forwardFriction)
    friction_cfg(node.AddNode("sidewaysFriction"), wheel.sidewaysFriction)
    return node
Пример #3
0
 def list_craft_assets(self, filepath):
     ''' Reads the craft file and return all cfg folders '''
     craft_assets = set()
     with open(filepath, 'r') as craft_file:
         craft_data = craft_file.read()
         craftnodes = ConfigNode.load(craft_data)
         # FIXME: is part always the first value?
         assets_set = self.get_craft_unique_assets(craftnodes)
         for asset in assets_set:
             if asset not in self.parts:
                 print("Warning: part '{}' not found".format(asset))
             else:
                 if self.uses_qt:
                     from PyQt4 import QtCore
                     self.emitter.emit(QtCore.SIGNAL('building(QString, int, int)'), "Building", list(assets_set).index(asset), len(assets_set))
                 print('Getting files for {}'.format(asset))
                 craft_assets.update(self.get_asset_files(self.parts[asset]))
     return craft_assets
Пример #4
0
def main():
    wheel_mu = sys.argv[1]
    mu = Mu()
    if not mu.read(wheel_mu):
        print("could not read: " + fname)
        raise
    find_wheels(mu.obj)
    if len(sys.argv) > 2:
        node = ConfigNode.loadfile(sys.argv[2])
        wheel = node.GetNode('Wheel')
        if not wheel:
            print("could not find Wheel")
            sys.exit(1)
        adjust_wheel(wheel)
        mu.write("wheelout.mu")
    else:
        for w in wheel_colliders.keys():
            node = wheel_cfg(w, wheel_colliders[w])
            print("Wheel " + node.ToString())
Пример #5
0
def main():
    wheel_mu = sys.argv[1]
    mu = Mu()
    if not mu.read(wheel_mu):
        print("could not read: " + fname)
        raise
    find_wheels(mu.obj)
    if len(sys.argv) > 2:
        text = open(sys.argv[2], "rt").read()
        node = ConfigNode.load(text)
        wheel = node.GetNode('Wheel')
        if not wheel:
            print("could not find Wheel")
            sys.exit(1)
        adjust_wheel(wheel)
        mu.write("wheelout.mu")
    else:
        for w in wheel_colliders.keys():
            node = wheel_cfg(w, wheel_colliders[w])
            print("Wheel "+ node.ToString())
Пример #6
0
 def list_craft_assets(self, filepath):
     ''' Reads the craft file and return all cfg folders '''
     craft_assets = set()
     with open(filepath, 'r') as craft_file:
         craft_data = craft_file.read()
         craftnodes = ConfigNode.load(craft_data)
         # FIXME: is part always the first value?
         assets_set = self.get_craft_unique_assets(craftnodes)
         for asset in assets_set:
             if asset not in self.parts:
                 print("Warning: part '{}' not found".format(asset))
             else:
                 if self.uses_qt:
                     from PyQt4 import QtCore
                     self.emitter.emit(
                         QtCore.SIGNAL('building(QString, int, int)'),
                         "Building",
                         list(assets_set).index(asset), len(assets_set))
                 print('Getting files for {}'.format(asset))
                 craft_assets.update(self.get_asset_files(
                     self.parts[asset]))
     return craft_assets
Пример #7
0
from cfgnode import ConfigNode


def get_cfg_values(one_node, val_type):
    assert isinstance(one_node, ConfigNode)
    return [i[1] for i in one_node.values if i[0] == val_type]


part_node_dict = dict()
child_parent_map = dict()
parent_children_map = dict()
all_partnames = list()
parentage_crosses_stage = list()

loaded_config_nodes = ConfigNode.load(
    open(args.ship_file, encoding="utf-8").read())
print("Load successful")
theparts = [p[1] for p in loaded_config_nodes.nodes if p[0] == "PART"]

for partNode in theparts:
    partpart = [i[1] for i in partNode.values if i[0] == "part"][0]
    partNode_childlinks = [i[1] for i in partNode.values if i[0] == "link"]
    for one_child in partNode_childlinks:
        child_parent_map[one_child] = partpart
    parent_children_map[partpart] = partNode_childlinks
    all_partnames.append(partpart)
    part_node_dict[partpart] = partNode

for child, parent in child_parent_map.items():
    child_stage = get_cfg_values(part_node_dict[child], "istg")[0]
    parent_stage = get_cfg_values(part_node_dict[parent], "istg")[0]
Пример #8
0
        other_part = part_map[port.GetValue('dockUId')]
        other_port = find_module(other_part, "ModuleDockingNode")
        if other_port.GetValue('dockUId') != p.GetValue('uid'):
            continue
        if parts.index(other_part) != int(p.GetValue('parent')):
            continue
        events = port.GetNode('EVENTS')
        undock = events.GetNode('Undock')
        print(p.GetValue('uid'), port.GetValue('state'),
              port.GetValue('dockUId'))
        count += 1
    return count


for arg in sys.argv[1:]:
    text = open(arg, "rt").read()
    node = ConfigNode.load(text)
    game = node.GetNode('GAME')
    if not game:
        print("could not find GAME")
        sys.exit(1)
    flightstate = game.GetNode("FLIGHTSTATE")
    if not flightstate:
        print("could not find FLIGHTSTATE")
        sys.exit(1)
    vessels = flightstate.GetNodes("VESSEL")
    for v in vessels:
        if check_ports(v):
            print(v.GetValue("name"), v.GetValue("type"))
    sys.exit(0)
Пример #9
0
#  Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
# ##### END GPL LICENSE BLOCK #####

# <pep8 compliant>

from cfgnode import ConfigNode
import sys

src = sys.argv[1]
dst = sys.argv[2]
out = sys.argv[3]

src_text = open(src, "rt").read()
dst_text = open(dst, "rt").read()
src_node = ConfigNode.load(src_text)
src_game = src_node.GetNode('GAME')
dst_node = ConfigNode.load(dst_text)
dst_game = dst_node.GetNode('GAME')
if not src_game:
    print("could not find source GAME")
    sys.exit(1)
if not dst_game:
    print("could not find destination GAME")
    sys.exit(1)

src_flightstate = src_game.GetNode("FLIGHTSTATE")
if not src_flightstate:
    print("could not find source FLIGHTSTATE")
    sys.exit(1)
dst_flightstate = dst_game.GetNode("FLIGHTSTATE")
Пример #10
0
        if 'Docked' in port.GetValue('state'):
            continue
        other_part = part_map[port.GetValue('dockUId')]
        other_port = find_module(other_part, "ModuleDockingNode")
        if other_port.GetValue('dockUId') != p.GetValue('uid'):
            continue
        if parts.index(other_part) != int(p.GetValue('parent')):
            continue
        events = port.GetNode('EVENTS')
        undock = events.GetNode('Undock')
        print(p.GetValue('uid'), port.GetValue('state'), port.GetValue('dockUId'))
        count+=1
    return count

for arg in sys.argv[1:]:
    text = open(arg, "rt").read()
    node = ConfigNode.load(text)
    game = node.GetNode('GAME')
    if not game:
        print("could not find GAME")
        sys.exit(1)
    flightstate = game.GetNode("FLIGHTSTATE")
    if not flightstate:
        print("could not find FLIGHTSTATE")
        sys.exit(1)
    vessels = flightstate.GetNodes("VESSEL")
    for v in vessels:
        if check_ports(v):
            print(v.GetValue("name"), v.GetValue("type"))
    sys.exit(0)
Пример #11
0
from cfgnode import ConfigNode
import sys
import yaml

file = open(sys.argv[1], 'r')
data = file.read()
file.close()

cfg = ConfigNode()
yml = list(yaml.load_all(data))

cl_node = cfg.AddNewNode('KERBALCHANGELOG')
cl_node.AddValue('showChangelog', True)
cl_node.AddValue('modName', 'Kerbalism')
for a in yml:
    for _, b in a.items():
        for k, v in b.items():  # i hate python
            c = cl_node.AddNewNode('VERSION')
            c.AddValue('version', k)
            for change in v['changes']:
                c.AddValue('change', change)
print('KERBALCHANGELOG\n' + cl_node.ToString())

file = open(sys.argv[2], 'w')
file.write('KERBALCHANGELOG\n' + cl_node.ToString())
file.close()