Skip to content

Commit

Permalink
Core: Floor and ceil in datastorage (ArchipelagoMW#2448)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ishigh1 authored Nov 24, 2023
1 parent d892622 commit 530e792
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
13 changes: 9 additions & 4 deletions MultiServer.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import inspect
import itertools
import logging
import math
import operator
import pickle
import random
Expand Down Expand Up @@ -67,21 +68,25 @@ def update_dict(dictionary, entries):

# functions callable on storable data on the server by clients
modify_functions = {
# generic:
"replace": lambda old, new: new,
"default": lambda old, new: old,
# numeric:
"add": operator.add, # add together two objects, using python's "+" operator (works on strings and lists as append)
"mul": operator.mul,
"pow": operator.pow,
"mod": operator.mod,
"floor": lambda value, _: math.floor(value),
"ceil": lambda value, _: math.ceil(value),
"max": max,
"min": min,
"replace": lambda old, new: new,
"default": lambda old, new: old,
"pow": operator.pow,
# bitwise:
"xor": operator.xor,
"or": operator.or_,
"and": operator.and_,
"left_shift": operator.lshift,
"right_shift": operator.rshift,
# lists/dicts
# lists/dicts:
"remove": remove_from_list,
"pop": pop_from_container,
"update": update_dict,
Expand Down
2 changes: 2 additions & 0 deletions docs/network protocol.md
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,8 @@ The following operations can be applied to a datastorage key
| mul | Multiplies the current value of the key by `value`. |
| pow | Multiplies the current value of the key to the power of `value`. |
| mod | Sets the current value of the key to the remainder after division by `value`. |
| floor | Floors the current value (`value` is ignored). |
| ceil | Ceils the current value (`value` is ignored). |
| max | Sets the current value of the key to `value` if `value` is bigger. |
| min | Sets the current value of the key to `value` if `value` is lower. |
| and | Applies a bitwise AND to the current value of the key with `value`. |
Expand Down

0 comments on commit 530e792

Please sign in to comment.