CoffeeScript VNM Patches

Discussion in 'Visual Novel Maker Plugins and Extensions' started by Archeia, Mar 5, 2019.

Thread Status:
Not open for further replies.
  1. Archeia

    Archeia Level 99 Demi-fiend Staff Member Developer

    Messages:
    14,336
    Likes Received:
    13,683
    Location:
    Game Dev Salt Mines
    First Language:
    Filipino
    Primarily Uses:
    VNM
    This topic serves as semi-official patches until the next VNM update rolls around or if by any reason you don't want to update.

    Allow Shadow Property on JSON Patch
    VNM Version 1.0.1093
    Code:
    # ===================================================================
    #
    #   Enable Shadow Property on JSON
    #   Allows you to use shadow properties with JSON.
    #
    # ===================================================================
    
    class StyleExt extends ui.Style
    ###
    * Initializes font-data from a style-descriptor.
    *
    * @method setupFont
    * @param {Object} descriptor - The style-descriptor.
    * @protected
    ###
    setupFont: (descriptor) ->
        if descriptor.font
            if !@font
                @font = new Font(descriptor.font.name, descriptor.font.size ? 0)
            else
                @font.name = descriptor.font.name
                @font.size = descriptor.font.size ? 0
          
            @font.bold = descriptor.font.bold ? @font.bold
            @font.italic = descriptor.font.italic ? @font.italic
            @font.smallCaps = descriptor.font.smallCaps ? @font.smallCaps
            @font.underline = descriptor.font.underline ? @font.underline
            @font.strikeThrough = descriptor.font.strikeThrough ? @font.strikeThrough
      
            if descriptor.font.color?
                @font.color.setFromArray(descriptor.font.color)
      
            if descriptor.font.border?
                @font.border = descriptor.font.border ? no
                @font.borderSize = descriptor.font.borderSize ? 4
                @font.borderColor.set(0, 0, 0, 255)
            if descriptor.font.shadow?
                @font.shadow = descriptor.font.shadow ? no
                @font.shadowOffsetX = descriptor.font.shadowOffsetX ? 2
                @font.shadowOffsetY = descriptor.font.shadowOffsetY ? 2
                @font.shadowColor.setFromArray(descriptor.font.shadowColor)
          
            if descriptor.font.outline?
                @font.border = descriptor.font.outline ? no
                @font.borderSize = descriptor.font.outline.size ? 4
          
                if descriptor.font.outline.color?
                    @font.borderColor.setFromArray(descriptor.font.outline.color)
                else
                    @font.borderColor.set(0, 0, 0, 255)
    ui.Style = StyleExt

    ...
     
    #1
  2. Archeia

    Archeia Level 99 Demi-fiend Staff Member Developer

    Messages:
    14,336
    Likes Received:
    13,683
    Location:
    Game Dev Salt Mines
    First Language:
    Filipino
    Primarily Uses:
    VNM
    Fix Imagemap Z-Index
    VNM Version 1.0.1093
    You need this to also use the fix below.
    Code:
    # ===================================================================
    #
    #   Fix ImageMap Clicking Issue
    #   This fixes the instance where you can click on imagemaps behind
    #   instances like the message log.
    #
    # ===================================================================
    class Patch_ImageMap extends gs.Component_ImageMap
        ###*
        * Updates the image-map's ground and all hotspots.
        *
        * @method update
        ###
        update: ->
            super()
            @object.rIndex = @ground.rIndex
            @updateGround()
    
            for hotspot in @hotspots
                @updateHotspot(hotspot)
    
            return null
    
    gs.Component_ImageMap = Patch_ImageMap

    Fix ImageMap Clicking Issue

    VNM Version 1.0.1093
    Code:
    # ===================================================================
    #
    #   Helps Fix Clicking Delays
    #
    # ===================================================================
    class Patch_CompEventEmitter extends gs.Component_EventEmitter
        ###*
        * Emits the specified event. All observers/listeners registered for the
        * specified event are informed.
        *
        * @method emit
        * @param {string} eventName - The name of the event to fire.
        * @param {Object} [sender=null] - The sender of the event.
        * @param {Object} [data={}] - An optional object passed to each handler-function.
        ###
        emit: (eventName, sender, data) ->
            handlerLists = @handlers[eventName]
            data = data ? {} #@defaultData
    
            if handlerLists and @needsSort[eventName]
                @needsSort[eventName] = no
                for handlerList in handlerLists
                    handlerList.sort (a, b) ->
                        if a.owner and b.owner
                            if a.owner.rIndex > b.owner.rIndex
                              return -1
                            else if a.owner.rIndex < b.owner.rIndex
                              return 1
                            else
                              return 0
                        else
                            return -1
    
            if handlerLists?
                breakOwner = null
                for handlerList in handlerLists by -1
                    if !handlerList then continue
                    i = 0
                    count = handlerList.length
                    @isEmitting++
                    while i < count
                        handler = handlerList[i]
    
                        data.handler = handler
                        data.sender = sender
                        data.data = handler.data
    
                        if (!breakOwner and (!handler.owner or !handler.owner.visible? or handler.owner.visible)) or breakOwner == handler.owner
                            handler.handler(data)
    
                        if handler.once
                            @markedForRemove.push(handler)
    
                        if data.breakChain
                            breakOwner = handler.owner
                            break
    
                        i++
                    @isEmitting--
                    if data.breakChain
                        data.breakChain = no
                if !@isEmitting and @markedForRemove.length > 0
                    for handler in @markedForRemove
                        @handlers[handler.eventName][handler.priority].remove(handler)
                    @markedForRemove = []
    
    
            return null
    
    gs.Component_EventEmitter = Patch_CompEventEmitter 
    

    More Actions for Imagemap (using JSON)
    VNM Version 1.0.1093
    Code:
    # ===================================================================
    #
    #   More Actions for Imagemap
    #
    #   This script fixes the issue with ImageMap JSON only allowing
    #   a single action property and also allows it to support conditions.
    #
    # ===================================================================
    class Patch_ImageMapAction extends ui.Component_ActionHandler
        ###*
        * Adds event-handler for mouse/touch events to update the component only if
        * a user-action happened.
        *
        * @method setupEventHandlers
        ###
        setupEventHandlers: ->
            gs.GlobalEventManager.offByOwner("keyUp", @object)
            gs.GlobalEventManager.offByOwner("mouseUp", @object)
            gs.GlobalEventManager.offByOwner("mouseMoved", @object)
         
         
            if @object.focusable
                gs.GlobalEventManager.on "keyUp", ((e) =>
                    if Input.release(Input.KEY_RETURN) and @object.ui.focused
                        @object.needsUpdate = yes
                        @executeActions()
                ), null, @object
         
            gs.GlobalEventManager.on "mouseUp", ((e) =>
                contains = Rect.contains(@object.dstRect.x, @object.dstRect.y,
                             @object.dstRect.width, @object.dstRect.height,
                             Input.Mouse.x - @object.origin.x, Input.Mouse.y - @object.origin.y)
             
                if contains
                    exec = no
                    actions = actions || @object.actions
                    if actions?
                        for action in actions
                            exec = @checkAction(action) and !@checkActionWait(action)
                            break if exec
                         
                    if exec
                        e.breakChain = yes
                        @executeActions()
                    @object.needsUpdate = yes
                 
            ), null, @object
         
             
            if @object.actions?.first((a) -> a and (a.event == "onMouseEnter" or a.event == "onMouseLeave" or a.event == "onMouseHover"))
                gs.GlobalEventManager.on "mouseMoved", ((e) =>
                    contains = Rect.contains(@object.dstRect.x, @object.dstRect.y,
                             @object.dstRect.width, @object.dstRect.height,
                             Input.Mouse.x - @object.origin.x, Input.Mouse.y - @object.origin.y)
             
                    if @containsPointer != contains
                        @containsPointer = contains
                        @object.needsUpdate = yes
                ),
                null, @object
             
            # @object.events.on "action", (e) =>
            #     actions = if e.actions then e.actions else [e.action]
            #     for action in actions
            #         @executeAction(action)
            @object.events.on "action", (e) =>
                actions = if e.actions then e.actions else [e.action]
                @executeActions(actions)
    
    
    ui.Component_ActionHandler = Patch_ImageMapAction
    
     
    Last edited: Mar 8, 2019
    #2
Thread Status:
Not open for further replies.

Share This Page