Jump to content
Sign in to follow this  
You need to play a total of 5 battles to post in this section.
MatroseFuchs

ModAPI (discussion)

9 comments in this topic

Recommended Posts

Administrator
12 posts
20 battles

All greetings!

We updated the ModAPI documentation on our forum, added descriptions, new methods and sections, as well as updated instructions for creating mods.

https://forum.worldofwarships.ru/topic/69084-modapi-документация/

https://forum.worldofwarships.ru/topic/64856-modsapi-how-to/

Similar topics in the American forum will be added later. We are currently translating the documentation.

Share this post


Link to post
Share on other sites
[LBAS]
Member
4,676 posts
26,700 battles

I need WG to support my custom ports loader (xml)

its 2 years old and I want it becomes official support with "xml",

just like before, easy and friendly to use it

Spoiler
Quote

API_VERSION = 'API_v1.0'

MOD_VERSION = 'v1.3'

def log(message): print('[CustomPortsLoader] %s' % (message))
def error(message): print('[CustomPortsLoader][E] %s' % (message))
def debug(message): print('[CustomPortsLoader][D] %s' % (message))

# CustomPortsLoader version 1.3

log('Loading ports...')
debug('gamever %s' % (utils.getGameVersion()))
debug('apiver %s' % (API_VERSION))
debug('modver %s' % (MOD_VERSION))

import xml

ET = xml.etree.ElementTree

# <port name="PortName" display="Port Display Name" barge="true" bargePosX="100" bargePosY="100" bargePosZ="100" bargeYaw="55.0" bargeWaypointX="0" bargeWaypointY="0" bargeWaypointZ="0"/>

DISPLAY_NAME_DEFAULT = 'Custom Port'
BARGEPOS_DEFAULT = False

def map(fn, it):
  for i in range(0, len(it)):
    it = fn(it)
  return it

LOADED_PORTS = []

def unload():
  log('Unloading ports...')
  for port in LOADED_PORTS:
    log('Unloading %s...' % (port))
    try:
      customPorts.removeCustomPort(port)
      LOADED_PORTS.remove(port)
    except: error('Could not unload port %s!' % (port))

def load():
  log('Loading ports...')
  for root, dirs, files in utils.walk('.'):
    for file in files:
      filename = '%s/%s' % (root, file)
      ext = file.split('.')[-1].lower()
      if ext != 'xml': continue
      try:
        log('Reading XML %s for port info...' % (file))
        with open(filename, 'r') as xml_f:
          xml = ET.fromstring(xml_f.read()).getchildren()[0]
          if xml.tag != 'ports':
            error('Malformed xml, no <ports> tag')
            continue
          for port in xml.getchildren():
            if port.tag == 'port':
              if 'name' not in port.attrib:
                error('Malformed xml, no name attribute for <port> tag')
                break
              name = port.attrib['name']
              display = DISPLAY_NAME_DEFAULT
              if 'display' in port.attrib: display = port.attrib['display']
              
              bargePos = BARGEPOS_DEFAULT
              for child in port.getchildren():
                if child.tag == 'barge':
                  bargePos = [[0, 0, 0], 0, [0, 0, 0]]

                  if 'x' in child.attrib: bargePos[0][0] = float(child.attrib['x'])
                  if 'y' in child.attrib: bargePos[0][1] = float(child.attrib['y'])
                  if 'z' in child.attrib: bargePos[0][2] = float(child.attrib['z'])

                  if 'yaw' in child.attrib: bargePos[1] = float(child.attrib['yaw'])
                  
                  if 'waypointX' in child.attrib: bargePos[2][0] = float(child.attrib['waypointX'])
                  if 'waypointY' in child.attrib: bargePos[2][1] = float(child.attrib['waypointY'])
                  if 'waypointZ' in child.attrib: bargePos[2][1] = float(child.attrib['waypointZ'])

                  bargePos = ((bargePos[0][0], bargePos[0][1], bargePos[0][2]), bargePos[1], (bargePos[2][0], bargePos[2][1], bargePos[2][2]))

              customPorts.addCustomPort(name, portDisplayName = display, bargePos = bargePos)
              LOADED_PORTS.append(name)
              log('Added port %s with name %s (bargePos: %s)' % (name, display, bargePos))
      except: error('Unexpected exception with file...')  
      #finally: pass

load()

import Keys

def keyEvent(event):
  if event.isAltDown() and event.isKeyDown() and event.key == Keys.KEY_F10:
    log('Reloading ports...')
    unload()
    load()
    return True
  return False

events.onKeyEvent(keyEvent)

 

 

and this is how it look like

1 folder 1 mod multi-ports

Untitled.jpg

Edited by MatterCore

Share this post


Link to post
Share on other sites
Administrator
12 posts
20 battles
On 10/27/2018 at 6:06 PM, MatterCore said:

I want it becomes official support with "xml"

Greetings
I apologize for the long answer. Do you want your mod to be included in the official modpack?

Share this post


Link to post
Share on other sites
[LBAS]
Member
4,676 posts
26,700 battles
6 minutes ago, MatroseFuchs said:

Greetings
I apologize for the long answer. Do you want your mod to be included in the official modpack?

yes I want WG support "Custom_ports.xml " again just like before

Share this post


Link to post
Share on other sites
Administrator
12 posts
20 battles
On 11/23/2018 at 6:15 PM, MatterCore said:

I want WG support "Custom_ports.xml "

First you need to publish your mod in this section of the forum, see examples of mods publications.
Secondly, with each update of the game you need to check your mod for good condition and update if necessary.
If you support your mod for the next at least three game updates, only after that we will consider including your mod in the official modpack.

Share this post


Link to post
Share on other sites
[LBAS]
Member
4,676 posts
26,700 battles
2 hours ago, MatroseFuchs said:

First you need to publish your mod in this section of the forum, see examples of mods publications.
Secondly, with each update of the game you need to check your mod for good condition and update if necessary.
If you support your mod for the next at least three game updates, only after that we will consider including your mod in the official modpack.

OK Sayonara

Share this post


Link to post
Share on other sites
Sign in to follow this  

×