Update Scene to use HaxePunk function order

require "LovePunk.Tweener"

export ^

class Scene extends Tweener
	new: =>
		super!
		@camera = nil
		@visible = true
		-- private
		@__typeFirst = nil
		@__count = nil
		@__farthest = nil
		@__first = nil
		@__layerFarthest = nil
		@__layerNearest = nil
		@__layers = nil
		@__mouseX = nil
		@__mouseY = nil
		@__nearest = nil
		@__sprite = nil
		@__uniqueTypes = nil
		@__updatedFirst = nil

	begin: =>
	-- Changed from end because of issues with the name "end" in Lua
	endScene: =>
	focusGained: =>
	focusLost: =>

	update: =>
	render: =>

	mouseX: => @__mouseX
	mouseY: => @__mouseY
	sprite: => @__sprite

	add: (e) =>
	remove: (e) =>
	removeAll: =>
	addList: (list) =>
	removeList: =>
	addGraphic: (graphic, layer, x, y) =>
	addMask: (mask, type, x, y) =>
	create: (classType, addToScene) =>
	recycle: (e) =>
	clearRecycled: (classType) =>
	clearRecycledAll: =>
	bringToFront: (e) =>
	sendToBack: (e) =>
	bringForward: (e) =>
	sendBackward: (e) =>
	isAtFront: (e) =>
	isAtBack: (e) =>
	collideRect: (type, rX, rY, rWidth, rHeight) =>
	collidePoint: (type, pX, pY) =>
	collideLine: (type, fromX, fromY, toX, toY, precision, p) =>
	collideRectInto: (type, rX, rY, rWidth, rHeight, into) =>
	collideCircleInto: (type, circleX, circleY, radius, into) =>
	collidePointInt: (type, pX, pY, into) =>
	nearestToRect: (type, x, y, width, height) =>
	nearestToEntity: (type, e, useHitboxes) =>
	nearestToClass: (type, e, classType, useHitboxes) =>
	nearestToPoint: (type, x, y, useHitboxes) =>
	count: => @__count --TODO
	typeCount: (type) =>
	classCount: (c) =>
	layerCount: (layer) =>
	first: => @__updatedFirst --TODO
	layers: => @__layers --TODO
	typeFirst: (type) =>
	classFirst: (c) =>
	layerFirst: (layer) =>
	layerLast: (layer) =>
	getSpriteByLayer: (layer) =>
	getFarthest: => @__farthest --TODO
	getNearest: => @__nearest --TODO
	getLayerFarthest: => @__layerFarthest --TODO
	getLayerNearest: => @__layerNearest --TODO
	getUniqueTypes: => @__uniqueTypes --TODO
	getType: (type, into) =>
	getClass: (c, into) =>
	getLayer: (layer, into) =>
	getAll: (into) =>
	getInstance: (name) =>
	updateLists: (shouldAdd) =>

require "LovePunk.Tweener"

export ^

class Scene extends Tweener
	new: =>
		super!
		@camera = nil
		@visible = true
		-- private
		@__typeFirst = nil
		@__count = nil
		@__farthest = nil
		@__first = nil
		@__layerFarthest = nil
		@__layerNearest = nil
		@__layers = nil
		@__mouseX = nil
		@__mouseY = nil
		@__nearest = nil
		@__sprite = nil
		@__uniqueTypes = nil

	add: (e) =>
	addGraphic: (graphic, layer, x, y) =>
	addList: (list) =>
	addMask: (mask, type, x, y) =>
	begin: =>
	bringForward: (e) =>
	bringToFront: (e) =>
	classCount: (c) =>
	classFirst: (c) =>
	clearRecycled: (classType) =>
	clearRecycledAll: =>
	collideCircle: (type, circleX, circleY, radius, into) =>
	collideLine: (type, fromX, fromY, toX, toY, precision, p) =>
	collidePoint: (type, pX, pY) =>
	collidePoint: (type, pX, pY, into) =>
	collideRect: (type, rX, rY, rWidth, rHeight) =>
	collideRect: (type, rX, rY, rWidth, rHeight, into) =>
	create: (classType, addToScene) =>
	-- Changed from end because of issues with the name "end" in Lua
	endScene: =>
	focusGained: =>
	focusLost: =>
	getAll: (into) =>
	getClass: (c, into) =>
	getInstance: (name) =>
	getLayer: (layer, into) =>
	getSpriteByLayer: (layer) =>
	getType: (type, into) =>
	isAtBack: (e) =>
	isAtFront: (e) =>
	layerCount: (layer) =>
	layerFirst: (layer) =>
	layerLast: (layer) =>
	nearestToClass: (type, e, classType, useHitboxes) =>
	nearestToEntity: (type, e, useHitboxes) =>
	nearestToPoint: (type, x, y, useHitboxes) =>
	nearestToRect: (type, x, y, width, height) =>
	recycle: (e) =>
	remove: (e) =>
	removeAll: =>
	removeList: =>
	render: =>
	sendBackward: (e) =>
	sendToBack: (e) =>
	typeCount: (type) =>
	typeFirst: (type) =>
	update: =>
	updateLists: (shouldAdd) =>


Reload too

Reload too

--
-- Copyright (C) 2017 DBot
--
-- Licensed under the Apache License, Version 2.0 (the "License");
-- you may not use this file except in compliance with the License.
-- You may obtain a copy of the License at
--
--     http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.
--

WATCH_WEAPONS = {}

timer.Create 'PPM2.ModelChecks', 1, 0, ->
    for ply in *player.GetAll()
        ply.__cachedIsPony = ply\IsPony()
        if ply.__ppm2_weapon_hit and not ply.__cachedIsPony
            wep\SetNoDraw(false) for wep in *ply\GetWeapons()
            ply.__ppm2_weapon_hit = false

    for i, wep in pairs WATCH_WEAPONS
        if not IsValid(wep)
            WATCH_WEAPONS[wep] = nil
            continue
        if not IsValid(wep\GetOwner())
            WATCH_WEAPONS[wep] = nil
            wep\SetNoDraw(false)

PPM2.PostDrawOpaqueRenderables = (a, b) ->
    return if a or b
    lply = LocalPlayer()

    for ply in *player.GetAll()
        if ply.__cachedIsPony
            wep = ply\GetActiveWeapon()
            if IsValid(wep)
                ply.__ppm2_weapon_hit = true
                wep\SetNoDraw(ply ~= lply or lply\ShouldDrawLocalPlayer())
                WATCH_WEAPONS[wep\EntIndex()] = wep

            if ply\GetPonyData() and not ply\Alive()
                data = ply\GetPonyData()
                rag = ply\GetRagdollEntity()
                if IsValid(rag)
                    rag\SetNoDraw(true)
                    renderController = data\GetRenderController()
                    if renderController
                        renderController\PreDraw()
                        rag\DrawModel()
                        renderController\PostDraw()

PPM2.PrePlayerDraw = =>
    return unless @GetPonyData()
    return unless @__cachedIsPony
    data = @GetPonyData()
    renderController = data\GetRenderController()
    renderController\PreDraw() if renderController
PPM2.PostPlayerDraw = =>
    return unless @GetPonyData()
    return unless @__cachedIsPony
    data = @GetPonyData()
    renderController = data\GetRenderController()
    renderController\PostDraw() if renderController

hook.Add 'PrePlayerDraw', 'PPM2.PlayerDraw', PPM2.PrePlayerDraw, -2
hook.Add 'PostPlayerDraw', 'PPM2.PostPlayerDraw', PPM2.PostPlayerDraw, -2
hook.Add 'PostDrawOpaqueRenderables', 'PPM2.PostDrawOpaqueRenderables', PPM2.PostDrawOpaqueRenderables, 2
hook.Add 'RenderScreenspaceEffects', 'PPM2.RenderScreenspaceEffects', ->
    self = LocalPlayer()

    if @__cachedIsPony and @GetPonyData() and @Alive()
        @GetPonyData()\GetRenderController()\DrawLegs()

SHOULD_DRAW_VIEWMODEL = CreateConVar('cl_ppm2_draw_hands', '1', {FCVAR_ARCHIVE}, 'Should draw hooves as viewmodel')

hook.Add 'PreDrawPlayerHands', 'PPM2.ViewModel', (arms = NULL, viewmodel = NULL, ply = LocalPlayer(), weapon = NULL) ->
    return true unless SHOULD_DRAW_VIEWMODEL\GetBool()
    return unless IsValid(arms)
    return unless ply.__cachedIsPony
    return unless ply\Alive()
    data = ply\GetPonyData()
    return unless data
    data\GetRenderController()\PreDrawArms(arms)
    arms.__ppm2_draw = true

hook.Add 'PostDrawPlayerHands', 'PPM2.ViewModel', (arms = NULL, viewmodel = NULL, ply = LocalPlayer(), weapon = NULL) ->
    return unless IsValid(arms)
    return unless arms.__ppm2_draw
    data = ply\GetPonyData()
    return unless data
    data\GetRenderController()\PostDrawArms(arms)
    arms.__ppm2_draw = false

UpdateWeight = ->
    ent = net.ReadEntity()
    return if not IsValid(ent)
    return if not ent\GetPonyData()
    ent\GetPonyData()\GetWeightController()\UpdateWeight()

lastDataSend = 0
net.Receive 'PPM2.RequestPonyData', ->
    lastDataSend = 0
    RunConsoleCommand('ppm2_reload')

net.Receive 'PPM2.UpdateWeight', UpdateWeight

concommand.Add 'ppm2_require', ->
    net.Start('PPM2.Require')
    net.SendToServer()
    print '[PPM2] Requesting pony data...'

concommand.Add 'ppm2_reload', ->
    return if lastDataSend > RealTime()
    lastDataSend = RealTime() + 10
    instance = PPM2.GetMainData()
    newData = instance\CreateNetworkObject()
    newData\Create()
    instance\SetNetworkData(newData)
    print '[PPM2] Sending pony data to server...'

hook.Add 'KeyPress', 'PPM2.RequireData', ->
    hook.Remove 'KeyPress', 'PPM2.RequireData'
    RunConsoleCommand('ppm2_reload')
    RunConsoleCommand('ppm2_require')

--
-- Copyright (C) 2017 DBot
--
-- Licensed under the Apache License, Version 2.0 (the "License");
-- you may not use this file except in compliance with the License.
-- You may obtain a copy of the License at
--
--     http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.
--

WATCH_WEAPONS = {}

timer.Create 'PPM2.ModelChecks', 1, 0, ->
    for ply in *player.GetAll()
        ply.__cachedIsPony = ply\IsPony()
        if ply.__ppm2_weapon_hit and not ply.__cachedIsPony
            wep\SetNoDraw(false) for wep in *ply\GetWeapons()
            ply.__ppm2_weapon_hit = false

    for i, wep in pairs WATCH_WEAPONS
        if not IsValid(wep)
            WATCH_WEAPONS[wep] = nil
            continue
        if not IsValid(wep\GetOwner())
            WATCH_WEAPONS[wep] = nil
            wep\SetNoDraw(false)

PPM2.PostDrawOpaqueRenderables = (a, b) ->
    return if a or b
    lply = LocalPlayer()

    for ply in *player.GetAll()
        if ply.__cachedIsPony
            wep = ply\GetActiveWeapon()
            if IsValid(wep)
                ply.__ppm2_weapon_hit = true
                wep\SetNoDraw(ply ~= lply or lply\ShouldDrawLocalPlayer())
                WATCH_WEAPONS[wep\EntIndex()] = wep

            if ply\GetPonyData() and not ply\Alive()
                data = ply\GetPonyData()
                rag = ply\GetRagdollEntity()
                if IsValid(rag)
                    rag\SetNoDraw(true)
                    renderController = data\GetRenderController()
                    if renderController
                        renderController\PreDraw()
                        rag\DrawModel()
                        renderController\PostDraw()

PPM2.PrePlayerDraw = =>
    return unless @GetPonyData()
    return unless @__cachedIsPony
    data = @GetPonyData()
    renderController = data\GetRenderController()
    renderController\PreDraw() if renderController
PPM2.PostPlayerDraw = =>
    return unless @GetPonyData()
    return unless @__cachedIsPony
    data = @GetPonyData()
    renderController = data\GetRenderController()
    renderController\PostDraw() if renderController

hook.Add 'PrePlayerDraw', 'PPM2.PlayerDraw', PPM2.PrePlayerDraw, -2
hook.Add 'PostPlayerDraw', 'PPM2.PostPlayerDraw', PPM2.PostPlayerDraw, -2
hook.Add 'PostDrawOpaqueRenderables', 'PPM2.PostDrawOpaqueRenderables', PPM2.PostDrawOpaqueRenderables, 2
hook.Add 'RenderScreenspaceEffects', 'PPM2.RenderScreenspaceEffects', ->
    self = LocalPlayer()

    if @__cachedIsPony and @GetPonyData() and @Alive()
        @GetPonyData()\GetRenderController()\DrawLegs()

SHOULD_DRAW_VIEWMODEL = CreateConVar('cl_ppm2_draw_hands', '1', {FCVAR_ARCHIVE}, 'Should draw hooves as viewmodel')

hook.Add 'PreDrawPlayerHands', 'PPM2.ViewModel', (arms = NULL, viewmodel = NULL, ply = LocalPlayer(), weapon = NULL) ->
    return true unless SHOULD_DRAW_VIEWMODEL\GetBool()
    return unless IsValid(arms)
    return unless ply.__cachedIsPony
    return unless ply\Alive()
    data = ply\GetPonyData()
    return unless data
    data\GetRenderController()\PreDrawArms(arms)
    arms.__ppm2_draw = true

hook.Add 'PostDrawPlayerHands', 'PPM2.ViewModel', (arms = NULL, viewmodel = NULL, ply = LocalPlayer(), weapon = NULL) ->
    return unless IsValid(arms)
    return unless arms.__ppm2_draw
    data = ply\GetPonyData()
    return unless data
    data\GetRenderController()\PostDrawArms(arms)
    arms.__ppm2_draw = false

UpdateWeight = ->
    ent = net.ReadEntity()
    return if not IsValid(ent)
    return if not ent\GetPonyData()
    ent\GetPonyData()\GetWeightController()\UpdateWeight()

lastDataSend = 0
net.Receive 'PPM2.RequestPonyData', ->
    lastDataSend = 0
    RunConsoleCommand('ppm2_reload')

net.Receive 'PPM2.UpdateWeight', UpdateWeight

concommand.Add 'ppm2_require', ->
    net.Start('PPM2.Require')
    net.SendToServer()
    print '[PPM2] Requesting pony data...'

concommand.Add 'ppm2_reload', ->
    return if lastDataSend > RealTime()
    lastDataSend = RealTime() + 10
    instance = PPM2.GetMainData()
    newData = instance\CreateNetworkObject()
    newData\Create()
    instance\SetNetworkData(newData)
    print '[PPM2] Sending pony data to server...'

hook.Add 'KeyPress', 'PPM2.RequireData', ->
    hook.Remove 'KeyPress', 'PPM2.RequireData'
    RunConsoleCommand('ppm2_require')