Jump to content

Module:NLL game log

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Mr. Stradivarius (talk | contribs) at 07:01, 17 September 2015 (make a start at converting Template:NLLGameLog). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
(diff) ← Previous revision | Latest revision (diff) | Newer revision → (diff)

-- This module implements [[Template:NLLGameLog]].

local p = {}

--[==[
	{{#if: {{{game3_opp|}}}{{{game3_opp_link|}}} |
		<tr align="center" {{#ifexpr: {{{game3_team_score|0}}}+{{{game3_opp_score|0}}} > 0 | {{#ifexpr: {{{game3_team_score|0}}} > {{{game3_opp_score|0}}}| bgcolor="CCFFCC" | bgcolor="FFBBBB" }} }}>
			<td>{{{game3_num|3}}}</td>
			<td>{{date | {{{game3_date}}} | mdy }}</td>
			<td>{{#ifeq: {{{game3_road_game}}} | 1 | @ }} {{#if: {{{game3_opp|}}} | {{#if: {{{game3_opp_link|}}} | [[{{{game3_opp_link}}}|{{{game3_opp}}}]] | {{{game3_opp}}} }} | {{#if: {{{game3_opp_link|}}} | [[{{{game3_opp_link}}}]] }} }}</td>
			<td>{{#ifeq: {{{game3_road_game}}} | 1 | {{#if: {{{game3_loc|}}} | {{#if: {{{game3_loc_link|}}} | [[{{{game3_loc_link}}}|{{{game3_loc}}}]] | {{{game3_loc}}} }} | {{#if: {{{game3_loc_link|}}} | [[{{{game3_loc_link}}}]] }} }} | {{#if: {{{arena|}}} | {{#if: {{{arena_link|}}} | [[{{{arena_link}}}|{{{arena}}}]] | {{{arena}}} }} | {{#if: {{{arena_link|}}} | [[{{{arena_link}}}]] }} }} }}</td>
			{{#ifexpr: {{{game3_team_score|0}}}+{{{game3_opp_score|0}}} <= 0 | <td></td><td></td><td></td><td></td> |
				<td>{{#ifexpr: {{{game3_team_score}}} > {{{game3_opp_score}}}| W | L }} {{{game3_team_score}}}&ndash;{{{game3_opp_score}}}</td>
				<td>{{#ifexpr: {{{game3_ot|0}}} > 0 | {{#ifexpr: {{{game3_ot|0}}} > 1 | {{{game3_ot|0}}} }}OT }}</td>
				<td>{{formatnum: {{{game3_attendance|0}}} }}</td>
				<td>{{#expr: {{#ifexpr: {{{game1_team_score|0}}} > {{{game1_opp_score|0}}} | 1 | 0 }}+{{#ifexpr: {{{game2_team_score|0}}} > {{{game2_opp_score|0}}} | 1 | 0 }}+{{#ifexpr: {{{game3_team_score|0}}} > {{{game3_opp_score|0}}} | 1 | 0 }} }}&ndash;{{#expr: {{#ifexpr: {{{game1_team_score|0}}} < {{{game1_opp_score|0}}} | 1 | 0 }}+{{#ifexpr: {{{game2_team_score|0}}} < {{{game2_opp_score|0}}} | 1 | 0 }}+{{#ifexpr: {{{game3_team_score|0}}} < {{{game3_opp_score|0}}} | 1 | 0 }} }}</td>
			}}
		</tr>
	}}
--]==]

--------------------------------------------------------------------------------
-- Game class
--------------------------------------------------------------------------------

local Game = {}
Game.__index = Game

Game.keys = {
	'opp',
	'opp_link',
	'team_score',
	'opp_score',
	'num',
	'date',
	'road_game',
	'loc',
	'loc_link',
	'ot',
	'attendance',
}

function Game.new(args, id)
	local self = setmetatable({}, Game)

	-- Set properties
	self.id = id
	do
		local prefix = 'game' .. id .. '_'
		for i, key in ipairs(Game.keys) do
			self[key] = args[prefix .. key]
		end
	end

	-- Abort if we don't have required fields
	if not self.opp and not self.opp_link then
		return nil
	end

	return self
end

function Game.get_number()
	return self.num or self.id
end

function Game.get_team_score()
	return self.team_score or 0
end

function Game.get_opposition_score()
	return self.opp_score or 0
end

function Game.get_goal_difference()
	return self:get_team_score() - self:get_opposition_score()
end

function Game.get_result_status()
	local gd = self:get_goal_difference()
	if gd == 0 then
		return 'D'
	elseif gd > 0 then
		return 'W'
	else
		return 'L'
	end
end

function Game.get_date()
	-- TODO: Convert [[Template:Date]] to Lua and call the module from here.
	local date = self.date or string.format('{{{game%d_date}}}', self.id)
	local frame = mw.getCurrentFrame()
	return frame:expandTemplate{title = 'Date', args = {date, 'mdy'}}
end

--------------------------------------------------------------------------------
-- GameLog class
--------------------------------------------------------------------------------

local GameLog = {}
GameLog.__index = GameLog

function GameLog.new(args)
	local self = setmetatable({}, GameLog)
	return self
end

--------------------------------------------------------------------------------
-- Exports
--------------------------------------------------------------------------------

local p = {}

function p._main(args)
end

function p.main(frame)
end

return p