Recognize CraftingGuide 1.0 query parameters
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
"version": 1,
|
||||
"mod_name": "Minecraft",
|
||||
"mod_version": "1.6.4",
|
||||
"description": "Crafting recipes from vanilla Minecraft (in progress)",
|
||||
"description": "Crafting recipes from vanilla Minecraft",
|
||||
"recipes": [
|
||||
{
|
||||
"output": [[4, "Arrow"]],
|
||||
|
||||
@@ -5,16 +5,22 @@
|
||||
# All rights reserved.
|
||||
###
|
||||
|
||||
exports.DefaultBookUrls = DefaultBookUrls = [
|
||||
'/data/vanilla.json'
|
||||
'/data/applied_energetics.json'
|
||||
'/data/buildcraft.json'
|
||||
'/data/gravisuite.json'
|
||||
'/data/industrial_craft.json'
|
||||
'/data/more_blocks.json'
|
||||
'/data/thermal_expansion.json'
|
||||
]
|
||||
|
||||
exports.Duration = Duration = {}
|
||||
Duration.snap = 100
|
||||
Duration.fast = Duration.snap * 2
|
||||
Duration.normal = Duration.fast * 2
|
||||
Duration.slow = Duration.normal * 2
|
||||
|
||||
exports.Opacity = Opacity = {}
|
||||
Opacity.hidden = 1e-6
|
||||
Opacity.shown = 1
|
||||
|
||||
exports.Event = Event = {}
|
||||
Event.add = 'add' # collection, item...
|
||||
Event.change = 'change' # model
|
||||
@@ -25,12 +31,11 @@ Event.load.failed = 'load:failed' # controller, error message
|
||||
Event.load.finished = 'load:finished' # controller
|
||||
Event.remove = 'remove' # collection, item...
|
||||
|
||||
exports.DefaultBookUrls = DefaultBookUrls = [
|
||||
'/data/vanilla.json'
|
||||
'/data/applied_energetics.json'
|
||||
'/data/buildcraft.json'
|
||||
'/data/gravisuite.json'
|
||||
'/data/industrial_craft.json'
|
||||
'/data/more_blocks.json'
|
||||
'/data/thermal_expansion.json'
|
||||
]
|
||||
exports.Opacity = Opacity = {}
|
||||
Opacity.hidden = 1e-6
|
||||
Opacity.shown = 1
|
||||
|
||||
exports.UrlParam = UrlParam = {}
|
||||
UrlParam.quantity = 'count'
|
||||
UrlParam.recipe = 'recipeName'
|
||||
UrlParam.includingTools = 'tools'
|
||||
|
||||
@@ -8,6 +8,8 @@
|
||||
BaseController = require './base_controller'
|
||||
{Event} = require '../constants'
|
||||
InventoryParser = require '../models/inventory_parser'
|
||||
url = require 'url'
|
||||
{UrlParam} = require '../constants'
|
||||
|
||||
########################################################################################################################
|
||||
|
||||
@@ -27,23 +29,24 @@ module.exports = class CraftingTableController extends BaseController
|
||||
onCatalogChanged: ->
|
||||
return unless @rendered
|
||||
@_updateNameAutocomplete()
|
||||
@_parseUrlParameters()
|
||||
|
||||
onHaveFieldChanged: ->
|
||||
return unless @rendered
|
||||
|
||||
@model.have.clear()
|
||||
@_parser.parse @$haveField.val(), @model.have
|
||||
@model.craft()
|
||||
@_craft()
|
||||
|
||||
onIncludingToolsFieldChanged: ->
|
||||
return unless @rendered
|
||||
@model.includingTools = @$('input[name="including_tools"]:checked').length > 0
|
||||
@model.craft()
|
||||
@_craft()
|
||||
|
||||
onNameFieldChanged: ->
|
||||
return unless @rendered
|
||||
@model.name = @$nameField.val()
|
||||
@model.craft()
|
||||
@_craft()
|
||||
|
||||
onNameFieldFocused: ->
|
||||
return unless @rendered
|
||||
@@ -52,7 +55,7 @@ module.exports = class CraftingTableController extends BaseController
|
||||
onQuantityFieldChanged: ->
|
||||
return unless @rendered
|
||||
@model.quantity = parseInt @$quantityField.find(":selected").val()
|
||||
@model.craft()
|
||||
@_craft()
|
||||
|
||||
# BaseController Overrides #####################################################################
|
||||
|
||||
@@ -69,13 +72,7 @@ module.exports = class CraftingTableController extends BaseController
|
||||
super
|
||||
|
||||
@_updateNameAutocomplete()
|
||||
|
||||
@onHaveFieldChanged()
|
||||
@onIncludingToolsFieldChanged()
|
||||
@onQuantityFieldChanged()
|
||||
|
||||
# do last so others are no-op until all is set
|
||||
@onNameFieldChanged()
|
||||
@_parseUrlParameters()
|
||||
|
||||
refresh: ->
|
||||
@$needList.empty()
|
||||
@@ -103,6 +100,37 @@ module.exports = class CraftingTableController extends BaseController
|
||||
|
||||
# Private Methods ##############################################################################
|
||||
|
||||
_craft: ->
|
||||
@model.craft()
|
||||
|
||||
_parseUrlParameters: ->
|
||||
params = url.parse(window.location.href, true).query
|
||||
|
||||
if params[UrlParam.includingTools]?
|
||||
param = params[UrlParam.includingTools]
|
||||
if param in ['true', 'yes']
|
||||
@$includingToolsField.attr 'checked', 'checked'
|
||||
else if param in ['false', 'no']
|
||||
@$includingToolsField.removeAttr 'checked'
|
||||
else
|
||||
console.log "invalid including tools value in URL param: #{params[UrlParam.includingTools]}"
|
||||
@onIncludingToolsFieldChanged()
|
||||
|
||||
if params[UrlParam.quantity]?
|
||||
@$quantityField.val parseInt params[UrlParam.quantity]
|
||||
if @$quantityField.find(':selected').length is 0
|
||||
console.log "invalid quantity in URL param: #{params[UrlParam.quantity]}"
|
||||
@onQuantityFieldChanged()
|
||||
|
||||
# Do this check last to avoid recalculting the recipe multiple times
|
||||
if params[UrlParam.recipe]?
|
||||
recipeName = params[UrlParam.recipe]
|
||||
if @model.catalog.findRecipes(recipeName).length > 0
|
||||
@$nameField.val recipeName
|
||||
else
|
||||
console.log "invalid recipe name in URL param: #{params[UrlParam.recipe]}"
|
||||
@onNameFieldChanged()
|
||||
|
||||
_updateNameAutocomplete: ->
|
||||
onChanged = => @onNameFieldChanged()
|
||||
|
||||
|
||||
@@ -5,9 +5,9 @@
|
||||
# All rights reserved.
|
||||
###
|
||||
|
||||
BaseModel = require './base_model'
|
||||
{Event} = require '../constants'
|
||||
RecipeBookParser = require './recipe_book_parser'
|
||||
BaseModel = require './base_model'
|
||||
{Event} = require '../constants'
|
||||
RecipeBookParser = require './recipe_book_parser'
|
||||
|
||||
########################################################################################################################
|
||||
|
||||
|
||||
Reference in New Issue
Block a user